NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [dic setValue:@"1" forKey:@"a"]; [dic setValue:@"3" forKey:@"c"]; [dic setValue:@"2" forKey:@"b"]; NSLog(@"dic:%@",dic);
结果是 abc
若换成NSMutableArray,用addObject的方法,结果是插入的顺序。
所以字典与数组有这样的不同
NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [dic setValue:@"1" forKey:@"a"]; [dic setValue:@"3" forKey:@"c"]; [dic setValue:@"2" forKey:@"b"]; NSLog(@"dic:%@",dic);
结果是 abc
若换成NSMutableArray,用addObject的方法,结果是插入的顺序。
所以字典与数组有这样的不同