如何将下面给出的内容存储到NSDictionary
{
"测试":"例子"
}
您可以使用
为key添加值NSDictionary *dictionary=[NSDictionary dictionaryWithObjectsAndKeys:@"Test",@"Example", nil];
您可以使用'initWithObjects:(objects) forKeys:'为key添加值
NSDictionary* dictionary = [[NSDictionary alloc] initWithObjects:@[@"Example",@"Example2"] forKeys:@[@"Test",@"Test2"]];
NSLog(@"%@",dictionary);
//{
// Test = Example;
// Test2 = Example2;
//}
或者你可以使用NSMutableDictionary:
NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init];
[mutableDictionary setObject:@"Example" forKey:@"Test"];
[mutableDictionary setObject:@"Example2" forKey:@"Test2"];
NSLog(@"%@",mutableDictionary);
//{
// Test = Example;
// Test2 = Example2;
//}
这些的输出相同。你还应该看看