valueForKey 只返回内存地址而不是实际值

发布于 2024-08-08 02:05:58 字数 572 浏览 8 评论 0原文

    NSDictionary *topic = [spaces objectAtIndex:i];
    NSInteger topicid = [topic valueForKey:@"TOPICID"];

当我运行它并打印出主题时,我得到以下信息:

Printing description of topic:
<CFDictionary 0xdb2a70 [0x30307a00]>{type = mutable, count = 2, capacity = 12, pairs = (
    10 : <CFString 0xdb5300 [0x30307a00]>{contents = "TOPICID"} = 29
    12 : <CFString 0xdb53a0 [0x30307a00]>{contents = "TOPICNAME"} = <CFString 0xdb5360 [0x30307a00]>{contents = "zzzzzzzz"}
)}

但是,当我查看 topicid 时,该值始终是内存地址。我做错了什么?

    NSDictionary *topic = [spaces objectAtIndex:i];
    NSInteger topicid = [topic valueForKey:@"TOPICID"];

when I run this and print out topic I get the following:

Printing description of topic:
<CFDictionary 0xdb2a70 [0x30307a00]>{type = mutable, count = 2, capacity = 12, pairs = (
    10 : <CFString 0xdb5300 [0x30307a00]>{contents = "TOPICID"} = 29
    12 : <CFString 0xdb53a0 [0x30307a00]>{contents = "TOPICNAME"} = <CFString 0xdb5360 [0x30307a00]>{contents = "zzzzzzzz"}
)}

However, when I look at topicid, the value is always a memory address. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

单挑你×的.吻 2024-08-15 02:05:58

也许该值实际上是一个 NSNumber。你可以使用以下方法得到这个:

NSInteger topicid = [[topic objectForKey:@"TOPICID"] intValue];

Maybe the value is actually an NSNumber. You would get this using:

NSInteger topicid = [[topic objectForKey:@"TOPICID"] intValue];
一瞬间的火花 2024-08-15 02:05:58

字典只能包含对象,不能包含基元。那里存储的任何内容(正如 Xetius 所建议的)可能都以某种形式包装。看起来 TOPICID 是一个 NSString。

Dictionaries can only contain objects, not primitives. Whatever is stored in there (as Xetius suggested) is probably wrapped in some form. It would appear that TOPICID is an NSString.

于我来说 2024-08-15 02:05:58

在数组输出中,您可以看到 topicID 是一个字符串值(NSString)。因此,您可能希望按照 Xetius 的描述来设置它 - 但不是因为它是一个 NSNumber,因为 NSString 有一个“intValue”方法。

In the array output, you can see topicID is a string value (NSString). So, you would want to set it as Xetius describes - but not because it is an NSNumber, because NSString has an "intValue" method.

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