Add values in NSMutableDictionary in iOS with Objective-C

前端 未结 3 1837
死守一世寂寞
死守一世寂寞 2021-02-07 05:44

I\'m starting objective-c development and I would like to ask the best way to implement a list of keys and values.

In Delphi there is the class TDict

3条回答
  •  逝去的感伤
    2021-02-07 06:19

    The other answers are correct, but there is more modern syntax for this now. Rather than:

    [myDictionary setObject:nextValue  forKey:myWord];
    

    You can simply say:

    myDictionary[myWord] = nextValue;
    

    Similarly, to get a value, you can use myDictionary[key] to get the value (or nil).

提交回复
热议问题