Skip to content

Instantly share code, notes, and snippets.

@VojtaStavik
Last active August 29, 2015 14:17
Show Gist options
  • Save VojtaStavik/c414d1495f786bd3b9c6 to your computer and use it in GitHub Desktop.
Save VojtaStavik/c414d1495f786bd3b9c6 to your computer and use it in GitHub Desktop.
// Objective-C:
user.userId = @"unknown";
if ([object isKinfOfClass:[NSDictionary class]]) {
if ([[((NSDictionary *)object) objectForKey:@"user_id"] isKindOfClass:[NSString class]]) {
user.userId = (NSString *)[((NSDictionary *)object) objectForKey:@"user_id"];
}
}
// Swift:
user.userId = (object as? NSDictionary)?["user_id"] as? String ?? "unknown"
// that's all :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment