在 NSMutableDictionary 中获取和设置 NSArray
我有一个全局文件,用于在释放创建值的另一个类之前存储值。我的方法看起来像这样用于存储:
`- (void)set_plantKind:(NSArray *)plantKindArr forMapName:(NSString *)mapName { [plantKinds setObject:plantKindArr forKey:mapName];
NSLog(@"key: %@, value: %@", mapName, [plantKinds objectForKey:mapName]);
} `
我可以很好地记录 plantKindArr 和 mapName,但它似乎没有将 plantKindArr 存储在字典中,或者也许我只是不知道如何正确检索它。我尝试记录日志,正如您在 NSLog 中看到的那样,但该值返回 null。有什么线索可以说明我在这里可能做错了什么吗?
I have a global file that stores values before another class is deallocated that created the values. My method looks like this for storing:
`- (void)set_plantKind:(NSArray *)plantKindArr forMapName:(NSString *)mapName {
[plantKinds setObject:plantKindArr forKey:mapName];
NSLog(@"key: %@, value: %@", mapName, [plantKinds objectForKey:mapName]);
}
`
I can log plantKindArr and mapName just fine, but it does not seem to storing plantKindArr in the dictionary, or maybe I just don't know how to retrieve it correctly. I tried logging as you can see in the NSLog, yet the value returns null. Any clues to what I could be doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从来没有分配过它。哎呀!
plantKinds = [[NSMutableDictionary alloc] init];
今天是周一,该起床了。
I never allocated it. Oops!
plantKinds = [[NSMutableDictionary alloc] init];
It's monday, time to wake up.