NSDictionary Objective-C

后端 未结 3 565
死守一世寂寞
死守一世寂寞 2021-01-14 13:17

I\'m trying to store data in the following fashion with a string as the key and I would like an array as the value.

key objects

\"letters\"

3条回答
  •  一个人的身影
    2021-01-14 14:03

    Assuming you have an NSArray called letters and one called numbers containing the correct values:

    NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
        letters, @"letters",
        numbers, @"numbers",
        nil
    ];
    

    Make sure to retain if you want to keep dict around, or alternatively use alloc and initWithObjectsAndKeys.

    See NSDictionary API reference for more details.

提交回复
热议问题