1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| int main(int argc, const char * argv[]) { @autoreleasepool { NSDictionary *dict1 = [NSDictionary dictionaryWithObject:@"OneValue" forKey:@"One"]; NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:@"OneValue",@"One", @"TwoValue",@"Two", @"ThreeValue",@"Three", @"FourValue",@"Four", @"FiveValue",@"Five", nil]; NSLog(@"dict1 = %@", dict1); NSLog(@"dict2 = %@", dict2); NSDictionary *dict3 = [NSDictionary dictionaryWithDictionary:dict2]; NSLog(@"dict3 = %@",dict3); NSInteger count = [dict2 count]; NSLog(@"dict2 count = %ld",(long)count); NSString *string = [dict3 objectForKey:@"One"]; NSLog(@"One String = %@",string); NSArray *allKeys = [dict3 allKeys]; NSArray *allValues = [dict3 allValues]; NSLog(@"dict3 allkeys = %@",allKeys); NSLog(@"dict3 allvalues = %@",allValues); NSMutableDictionary *mutableDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"v1",@"k1", @"v2",@"k2", @"v3",@"k3", @"v4",@"k4", @"v5",@"k5", @"v6",@"k6",nil]; NSLog(@"mutableDict = %@",mutableDict); NSDictionary *dict4 = [NSDictionary dictionaryWithObjectsAndKeys:@"v7",@"k7", nil]; [mutableDict addEntriesFromDictionary:dict4]; NSLog(@"mutabledict = %@",mutableDict); [mutableDict setObject:@"v8" forKey:@"k8"]; NSLog(@"mutableDict = %@",mutableDict); NSMutableDictionary *mutableDict2 = [NSMutableDictionary dictionary]; [mutableDict2 setDictionary:mutableDict]; NSLog(@"mutabledict2 = %@",mutableDict2); [mutableDict2 removeObjectForKey:@"k3"]; NSLog(@"mutabledict2 = %@",mutableDict2); for (int index = 0; index < [mutableDict count]; index++) { NSString *string = [mutableDict objectForKey:[[mutableDict allKeys] objectAtIndex:index]]; NSLog(@"String = %@",string); } NSLog(@"_______________________________________________快速枚举"); for(id key in mutableDict){ NSString *string = [mutableDict objectForKey:key]; NSLog(@"string = %@",string); } NSLog(@"_______________________________________________枚举类型"); NSEnumerator *enumerator = [mutableDict keyEnumerator]; id key; while (key) { id obejct = [mutableDict objectForKey:key]; id key = [enumerator nextObject]; NSLog(@"string = %@",string); } NSLog(@"Hello, World!"); } return 0; }
|