Objective-C Singleton Macro

My friend Paddy showed me an awesome macro for generating single classes, shown here. You’d use it like:

SYNTHESIZE_SINGLE_FOR_CLASS(class_name);

//instance methods go here!

@end

This is pretty sweet - if you’re using the Singleton pattern a lot, and let’s face it, it’s always something we mean to do, this is a lifesaver since Singleton code is all copy-and-paste.


Posted on April 1, 2011