我試圖合併2 NSDictionary
對象到1 NSMutableDictionary
。通過閱讀2個不同的plist
文件創建了NSDictionary
。 ,如何結合兩個NSDictionaries?
@property (nonatomic, strong) NSMutableDictionary *configuration;
...
-(NSMutableDictionary*) configuration{
if (!_configuration) {
NSDictionary *core_config = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"installation" ofType:@"plist"]];
NSDictionary *app_config = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle bundleWithPath:@"/path/to"] pathForResource:@"something/data" ofType:@"plist"]];
[_configuration addEntriesFromDictionary: core_config];
[_configuration addEntriesFromDictionary: app_config];
NSLog(@"merged: %lu, core: %lu, app: %lu", (unsigned long)[_configuration count], (unsigned long)[core_config count], (unsigned long)[app_config count]);
// merged: 0, core: 4, app: 5
}
return _configuration;
}
的_configuration
是空的,儘管調用addEntriesFromDictionary
兩次。
什麼是你的問題?你有什麼問題? – rmaddy