
Untitled
By: a guest on
May 17th, 2012 | syntax:
None | size: 0.58 KB | hits: 15 | expires: Never
Stringify macro values in Objective C?
#define ASSIGN_PROPERTY(PROP_NAME, PROP_NAME_PARAM) {
if (PROP_NAME_PARAM == nil) {
NSAssert(PROP_NAME != nil, @"#PROP_NAME is already nil");
PROP_NAME = nil;
} else {
NSAssert1(PROP_NAME == nil, @"#PROP_NAME is already set, address=%p", PROP_NAME);
PROP_NAME = PROP_NAME_PARAM;
}
}
- (void) setFoo:(NSObject *)fooParam {
ASSIGN_PROPERTY(foo, fooParam)
}
foo is already set, address=0x5e55400
#PROP_NAME is already set, address=0x5e55400
NSAssert(PROP_NAME != nil, @"%s is already nil", #PROP_NAME);