Edit AllPages

Go back to CocoaPrerequisites

Skip to CocoaStepTwo

** Getting Started with Cocoa ** - Apple provides a nice sequence of very introductory steps at If you are an experienced programmer, you might be tempted to skip this information or skim through it. That would be a mistake in most cases. The introductory material may bore experienced programmers, and the initial trivial tutorial may not seem relevant to an experienced programmer. Nevertheless, the Cocoa way of doing things is sometimes subtly different from the techniques common with other software technologies. In a few cases, the Cocoa approach is radically different. Since the authors of documentation and tutorials cannot assume what preconceptions or education the reader might have, the material has to be pedantic.

Some people new to Cocoa justifiably complain that much of Apple’s documentation seems to use undefined terms or defines terms using other undefined terms. Keep in mind that a common technical vocabulary is needed to effectively communicate. Apple’s choice of terminology comes from a different tradition within computer science than some other popular software technologies. Apple’s terminology is standard for people who come from the Smalltalk tradition which started the whole object oriented programming concept. The existence of different traditions that have not yet coalesced is a testament to the youth of object oriented programming. Seminal texts like “Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley Professional Computing Series) “ by Erich Gamma (Author), Richard Helm (Author), Ralph Johnson (Author), and John M. Vlissides (Author) have made tremendous progress unifying the field and providing a common vocabulary.

** You need a conceptual foundation before you can make progress ** - In most respects, Cocoa is not an a-la-carte framework. There are key design patterns, repeated idioms, optional conventions, and most importantly some essential conventions. No matter how much experience a programmer may have, if the programmer fails to adhere to essential conventions (like Cocoa memory management conventions), they will not succeed with Cocoa.

Because Cocoa is a cohesive system that is astoundingly consistent, a programmer who groks it can often correctly guess class and method names, anticipate potential error cases, avoid unnecessary code, and benefit from increased productivity. On the other hand, a programmer who is missing one or more key concepts is likely to find seeming barriers everywhere because Cocoa probably applies the concept ubiquitously.

So what are the key concepts?

Above all is the ** Model View Controller (MVC) Pattern ** used to organize all of Cocoa. ModelViewController

* C pointer assignment ** - Programmers coming from environments without access to explicit pointers are often lost immediately when attempting to use Cocoa because every Objective-C object is accessed via a pointer. If you don’t understand how and why to use pointers, you should learn the C programming language and ideally at least one assembly language so that you understand how computer Central Processing Units (CPUs) work and how C, C++, and Objective-C generate the machine language that is executed. This points back to the first prerequisite for Cocoa programming: CocoaPrerequisites. Ref: Any C Programming book. *** Two Stage instance creation ** - This is Cocoa’s convention for creation of new instances of Objective-C classes. *** Convenience Methods ** - These Class methods conveniently return already initialized instances of Objective-C classes. *** Reference Counted Memory Management ** - This was NOT invented just for Cocoa. Reference counting is one of the oldest and most widely used techniques for sharing and keeping track of scarce computer resources such as memory, file identifiers, inter process communication tools like FIFOs? (unnamed pipes), graphics card texture memory, strings (via the CString?)class) in Microsoft’s Foundation Framework, COM objects via IUnknown? in Microsoft’s COM/DCOM/Active-X, “smart” pointers in the Boost C++ library, and much much more. Whether or not you plan to use Cocoa, any serious programmer should understand this basic and widely used technique. Simple Examples: *** The SIMPLE Rules for Reference Counted Memory Management ** - *** Accessors ** - This is the right place to perform all memory management. Using Accessors also prepares your code for more advanced Cocoa usage. *** Encoding/Decoding Archiving/Unarchiving ** - These patterns/concepts are essential for understanding how Apple’s critical Interface Builder tool works. Interface Builder is used to develop the user interface for Cocoa applications.(The following link is obsolete.) *** Copying ** - *** Introspection ** - *** Mutability ** - *** Class Clusters ** - *** Singletons ** - *** Notifications ** - *** Delegates & Data Sources ** - *** Outlets ** - *** Targets, and Actions ** - *** Responder Chain ** - *** Proxies and Forwarding and Invocations ** - *** Prototypes (Cells & Controls) - ** Bundles ** - ** Controllers ** - This subject has gotten very large in recent versions of Cocoa. Limit yourself to the following for a while before attempting more advanced and esoteric Controllers. *** Decorators ** - This pattern is not emphasized in Cocoa but is used frequently within the framework. Scrollers, rulers, bezels etc. follow this pattern.

** Wow! That’s a lot of concepts ** - Yes that is a lot of concepts. That isn’t even all of them. Those are just the ground floor of concepts, and even bigger better ones are built on top. The ground floor concepts should be enough to get you started, and with an understanding of those concepts, you should be able to read both reference documentation and conceptual documentation about Cocoa and not constantly encounter “undefined” terms.

** Some astute programmers might recognize some of those “concepts” as object oriented design patterns ** - DesignPattern - Indeed, they are. Cocoa has some very elegant implementations for common design patterns, but very few patterns are unique to Cocoa. These patterns exist and are used in other popular software development technologies. Mastering these patterns/concepts will make you a better and more skilled programmer with those other software development technologies as well as Cocoa. However, the use and reuse of these patterns is really not optional with Cocoa the way it might be with other technologies.

next CocoaStepTwo - Finding Apple’s Cocoa documentation and samples