在 NSMutableDictionary 中获取和设置 NSArray

发布于 2024-12-28 13:36:38 字数 454 浏览 6 评论 0原文

我有一个全局文件,用于在释放创建值的另一个类之前存储值。我的方法看起来像这样用于存储:

`- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱,才寂寞 2025-01-04 13:36:38

我从来没有分配过它。哎呀!

plantKinds = [[NSMutableDictionary alloc] init];

今天是周一,该起床了。

I never allocated it. Oops!

plantKinds = [[NSMutableDictionary alloc] init];

It's monday, time to wake up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文