Skip to content

Monthly Archives: June 2009

Objective-C 2.0 properties and to-many relationships

I’ve occasionally been asked about the appropriate form for properties representing to-many relationships in Objective-C 2.0. Let’s start with the example of a recipe and its ingredients, represented by instances of the Recipe and Ingredient classes. @interface Recipe : NSObject { @private NSMutableSet *_ingredients; } @property (copy) NSSet *ingredients; @end This is a pretty straightforward […]

Singletons in Cocoa/Objective-C

I’ll preface this post with the standard advice: *Don’t create singletons if you don’t absolutely have to.* In general, if you’re creating a global “manager” object of some sort, you’re doing something wrong. That said, there’s still occasionally a reason to have such a global singleton, such as a “default something.” The sample code in […]