gpt4 book ai didi

objective-c - 如何在调试器控制台中获取 NSDictionary 对象的值/键?

转载 作者:技术小花猫 更新时间:2023-10-29 10:30:23 26 4
gpt4 key购买 nike

我设置了一个断点...

如果我这样做:

(lldb) print [self dictionary]
(NSDictionary *) $5 = 0x0945c760 1 key/value pair

但如果我这样做:

(lldb) print [[self dictionary] allKeys]
error: no known method '-allKeys'; cast the message send to the method's return type
error: 1 errors parsing expression

即使我尝试访问我知道在那里的 key ..

(lldb) print [[self dictionary] objectForKey:@"foobar"]
error: no known method '-objectForKey:'; cast the message send to the method's return type
error: 1 errors parsing expression

我做错了什么?

最佳答案

error: no known method '-objectForKey:'; cast the message send to the method's return type

因此,它告诉您它不能仅仅从消息发送的名称中推断出返回类型信息——这完全没问题。它甚至会告诉您如何准确地解决该问题 - 您必须转换发送到方法的返回类型的消息。

启动 Apple 的文档,我们发现 - [NSDictionary objectForKey:] 返回 id - 通用的 Objective-C 对象类型。转换为 id(或者更好,如果你知道你的字典包含什么类型的对象,转换为那个确切的对象类型)就可以了:

(lldb) print (MyObject *)[(NSDictionary *)[self dictionary] objectForKey:@"foobar"]

关于objective-c - 如何在调试器控制台中获取 NSDictionary 对象的值/键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11994409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com