English 中文(简体)
如何在字典中添加具有价值的新钥匙
原标题:How to insert a new key with value in dictionary

我想在现有字典中添加一个具有相应价值的钥匙。

我能够为词汇中的现有钥匙设定价值,但我无法增加新的关键价值。

希望得到任何帮助。

最佳回答

使用NSMutableDtionary

NSMutableDictionary *yourMutableDictionary = [NSMutableDictionary alloc] init];
[yourMutableDictionary setObject:@"Value" forKey:@"your key"];

www.un.org/Depts/DGACM/index_spanish.htm

下面是上述法典的迅速复制件。

var yourMutableDictionary = NSMutableDictionary()
yourMutableDictionary.setObject("Value", forKey: "Key")

但是,我建议你迅速采取审慎态度。

var yourMutableDictionary = [String: AnyObject]() //Open close bracket represents initialization

//The reason for AnyObject is a dictionary s value can be String or
//Array or Dictionary so it is generically written as AnyObject

yourMutableDictionary["Key"] = "Value"
问题回答
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];

通过采用这一方法,我们可以给国家统计研究院增加新的价值。

[dict setObject:@"Value" forKey:@"Key"];

了解 wheat中的关键

[[dict allKeys] containsObject:@"key"];

从现在起,我从小子里以字典的形式获得内容,从那边,我把内容添加到其他一些字典中。

  //here contract is my json dictionary 
  NSArray *projectDBList =[contract allKeys];//listing all the keys in dict 

  NSMutableDictionary *projectsList=[[NSMutableDictionary alloc]init];

  [projectDBList enumerateObjectsUsingBlock:^(NSString * obj, NSUInteger idx, BOOL *stop) {

  [projectsList setObject:[contract objectForKey:obj] forKey:obj];

  }];




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签