Created
October 25, 2012 15:06
-
-
Save datwelk/3953174 to your computer and use it in GitHub Desktop.
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
// Definitions | |
NSDictionary *son = @{ @"firstname" : @"James", @"lastname" : @"Appleseed" }; | |
NSDictionary *daughter = @{ @"firstname" : @"Susan", @"lastname" : @"Appleseed"}; | |
NSArray *children = @[son, daughter]; | |
NSDictionary *father = @{ @"firstname" : @"John", @"lastname" : @"Appleseed" }; | |
NSDictionary *family = @{@"children" : children, @"father" : father}; | |
NSDictionary *pedigree = @{@"family" : family }; | |
// First test | |
id _family = [pedigree objectForKey:@"family"]; | |
if ([_family isKindOfClass:[NSDictionary class]]) | |
{ | |
NSDictionary *_family = (NSDictionary *)_family; | |
id _children = [_family objectForKey:@"children"]; | |
if ([_children isKindOfClass:[NSArray class]]) { | |
NSLog(@"Children is an NSArray"); | |
} else { | |
NSLog(@"Children is not an NSArray"); | |
} | |
} else { | |
NSLog(@"Family is not an NSDictionary"); | |
} | |
// Output first test: "Children is not an NSArray" | |
// Second test | |
id _family = [pedigree objectForKey:@"family"]; | |
if ([_family isKindOfClass:[NSDictionary class]]) | |
{ | |
id _children = [_family objectForKey:@"children"]; | |
if ([_children isKindOfClass:[NSArray class]]) { | |
NSLog(@"Children is an NSArray"); | |
} else { | |
NSLog(@"Children is not an NSArray"); | |
} | |
} else { | |
NSLog(@"Family is not an NSDictionary"); | |
} | |
// Output second test: "Children is an NSArray" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment