开发者

Get all keys of an NSDictionary as an NSArray

开发者 https://www.devze.com 2023-03-28 13:30 出处:网络
Is it possi开发者_JAVA百科ble to get all the keys from a specific NSDictionary as a seperate NSArray?Just use

Is it possi开发者_JAVA百科ble to get all the keys from a specific NSDictionary as a seperate NSArray?


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.


Yes it's possible. Use allKeys method:

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


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消