Get all keys of an NSDictionary as an NSArray

て烟熏妆下的殇ゞ 提交于 2019-11-30 10:36:44

问题


Is it possible to get all the keys from a specific NSDictionary as a seperate NSArray?


回答1:


Just use

NSArray*keys=[dict allKeys];

In general, if you wonder if a specific class has a specific method, look up Apple's own documentation. In this case, see NSDictionary class reference. Go through all the methods. You'll discover many useful methods that way.




回答2:


Yes it's possible. Use allKeys method:

NSDictionary *yourDictionary;
NSArray * yourKeys
yourKeys = [yourDictionary allKeys];



回答3:


And if you want to get all keys and values, here's what you do:

for (NSString *key in dictionary) {
    id value = dictionary[key];
    NSLog(@"Value: %@ for key: %@", value, key);
}


来源:https://stackoverflow.com/questions/7057063/get-all-keys-of-an-nsdictionary-as-an-nsarray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!