How to insert a new key with value in dictionary

前端 未结 4 1008
情话喂你
情话喂你 2020-12-18 18:17

I want to insert a key with a corresponding value in an existing dictionary...

I am able to set values for existing keys in the dictionary, but I am not able to add

4条回答
  •  难免孤独
    2020-12-18 18:45

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

    By using this method we can add the new value to NSMutableDictionary

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

    To know wheather the key exist in dictionary

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

提交回复
热议问题