Last active
August 29, 2015 13:55
-
-
Save matthewreagan/8760631 to your computer and use it in GitHub Desktop.
-isKindOfClass Macro Shortcut
This file contains 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
#define EXPECT(anObj, aClass)\ | |
aClass * anObj##_valid = nil;\ | |
BOOL anObj##_isClass = [anObj isKindOfClass:[aClass class]];\ | |
if (! anObj##_isClass) { NSLog(@"Warning: Invalid class, '%s' is %@, expecting %@", #anObj, [anObj class], [aClass class]); }\ | |
if ( anObj##_isClass )\ | |
{ anObj##_valid = (aClass *) anObj; }\ | |
if ( anObj##_isClass ) | |
// ...replaces this: | |
id webServiceResponse; | |
if ([webServiceResponse isKindOfClass:[NSDictionary class]]) | |
{ | |
NSDictionary *typeCast = (NSDictionary *)webServiceResponse; | |
[typeCast dictionarySpecificMethod]; | |
} | |
else | |
{ | |
NSLog(@"Warning: expecting dictionary"); | |
} | |
// ...with this: | |
EXPECT(webServiceResponse, NSDictionary) | |
{ | |
[webServiceResponse_valid dictionarySpecificMethod]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment