You could try something else. I would not have thought about this more than a couple of days ago, but I happened to read Cocoa With Love . In connection with the post, he discussed how he created a macro #definethat “generated” the entire singleton class in the place where you called the macro. You can upload your code for this (you can give ideas on your own implementation).
, - (Warning: Untested Code Ahead):
#define SYNTHESIZE_LAZY_INITIALIZER_FOR_OBJECT(objectName, objectType) \
\
- (objectType *)objectName \
{ \
if(!objectName) \
{ \
objectName = [[objectType alloc] init]; \
} \
return objectName; \
} \
\
- (void)set##objectName:(objectType *)value \
{ \
[value retain]; \
[objectName release]; \
objectName = value; \
}
? , , , , /. . , - !;)
. Warning: Untested Code Ahead:
@interface SomeClass : NSObject {
NSObject *someObj;
}
@end
@implementation SomeClass
SYNTHESIZE_LAZY_INITIALIZER_FOR_OBJECT(someObj, NSObject);
@end