Created
August 12, 2012 18:11
-
-
Save codeswimmer/3333522 to your computer and use it in GitHub Desktop.
Check for multiple assignment to an ivar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *const ASMultipleAssignmentException = @"Multiple Assignment Exception"; | |
#ifndef CHECK_FOR_MULTI_ASSIGN | |
#define CHECK_FOR_MULTI_ASSIGN(ivar) \ | |
do { \ | |
if (ivar) { \ | |
NSString *AS_reason = @"Cannot assign to " #ivar " more than once"; \ | |
@throw [NSException exceptionWithName:ASMultipleAssignmentException \ | |
reason:AS_reason \ | |
userInfo:nil]; \ | |
} \ | |
} while(0) | |
#endif | |
- (void)setName:(NSString *)name | |
{ | |
CHECK_FOR_MULTI_ASSIGN(_name); | |
_name = name; | |
} | |
- (void)setScore:(NSNumber *)score | |
{ | |
CHECK_FOR_MULTI_ASSIGN(_score); | |
_score = score; | |
} | |
- (void)setWebsite:(NSURL *)website | |
{ | |
CHECK_FOR_MULTI_ASSIGN(_website); | |
_website = website; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment