sye*_*dfa 0 for-loop objective-c nsdictionary fast-enumeration
我有两个数组,一个保存键值(myKeys),另一个保存NSString对象(myStrings).我想使用两个数组来使用快速枚举来填充单个NSDictionary(myDictionary),但我不确定如何?
for (NSNumber *key in myKeys) {
[self.myDictionary setObject @"here is where the value should go from the 'other' array forKey: key];
}
Run Code Online (Sandbox Code Playgroud)
我如何在这里考虑NSArray对象?
查看文档,NSDictionary可以在不进行枚举的情况下执行此操作.
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:myObjects forKeys:myKeys];
Run Code Online (Sandbox Code Playgroud)
如果您尝试向现有的mutableDictionary添加值,它也可以这样做.
[mutableDictionary addEntriesFromDictionary:dictionary];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
316 次 |
| 最近记录: |