Created
March 9, 2015 04:42
-
-
Save kmdarshan/fec1374b5c160abf51be to your computer and use it in GitHub Desktop.
Checking for null objects
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
| @implementation RRUser | |
| @synthesize email, name, facebookId, userId, sessionToken, imageUrl; | |
| -(void) parseResponse:(NSDictionary*) data { | |
| // this is a better way to test, if the class responds to a selector | |
| // then go ahead and read from it | |
| if([[data objectForKey:@"email"] respondsToSelector:@selector(length)]) { | |
| self.email = [data objectForKey:@"email"]; | |
| } | |
| if([[data objectForKey:@"name"] respondsToSelector:@selector(length)]) { | |
| self.name = [data objectForKey:@"name"]; | |
| } | |
| // incase you read from self.name, it would crash, since name would be null | |
| if([data objectForKey:@"name"] != Nil) { | |
| self.name = [data objectForKey:@"name"]; | |
| } | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment