从位于AppDelegate的MutableDictionnary读取值

时间:2017-02-15 09:40:06

标签: ios objective-c xcode appdelegate nsmutabledictionary

我实际上正在使用Objective-C应用, 我在NSMutableDictionary上创建了3个AppDelegate,我知道如何使用以下内容在NSMutableDictionary中设置值:

[(AppDelegate *)[NSApp delegate]setCentralServTrapDict:CentralServDict];

但我不知道如何读取这些值,我已经尝试过了:

[(AppDelegate *)[NSApp delegate]valueForKey:@"kCentralServSystemCpuUsage"];

而这......:

[(AppDelegate *)[NSApp delegate]CentralServ valueForKey()];

如何从其他类中访问NSMutableDictionary的值?

1 个答案:

答案 0 :(得分:0)

如果我正确理解了这个问题,那么访问dictionary值的语法似乎不正确。例如:

NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionary];
[mutableDictionary setObject:@1 forKey:@"firstValue"];
NSNumber *firstValueVar = mutableDictionary[@"firstValue"];