Skip to content

Instantly share code, notes, and snippets.

@datwelk
Created October 25, 2012 15:06
Show Gist options
  • Save datwelk/3953174 to your computer and use it in GitHub Desktop.
Save datwelk/3953174 to your computer and use it in GitHub Desktop.
// 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