如何确定iOS(id)对象的结构?
当我从 iOS 应用程序调用某个函数时,它会返回 id
数据类型。我无法查看这个函数,所以我不知道它在做什么或返回类型到底是什么。
如果我使用 NSLog("@"...)
将其打印到控制台,我会得到类似于以下内容的字符串: 2012-01-18 19:03:08.915 HelloWorld[165:707]按键状态
。
有什么方法可以让我确定这个基本 Id 对象的结构吗?我将如何获取该响应的特定部分,例如“按键状态”。字符串解析似乎是一个可怕的想法,但也许这是唯一的方法。也许数据真的只是一个 NSString
?
谢谢!
When I call a certain function from my iOS app, it returns an id
data type. I can't see into this function so I don't know what it's doing or what the return type really is.
If I print it to console using NSLog("@"...)
I get a string similar to this:2012-01-18 19:03:08.915 HelloWorld[165:707] Key Press State
.
Is there any way for me to determine the structure of this basic Id object? How would I go about getting a specific part of that response out, such as "Key press state"
. String parsing seems like a horrible idea, but maybe that's the only way. Perhaps the data really is just an NSString
?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
如果您查看
,您将看到用于查询对象的类、方法选择器、ivars 等的方法。但是,您通常不想这样做,因为它破坏了封装并可能导致您依赖将来可能会更改的实现细节,因此请小心。您可以在此处阅读更多信息。If you look in
<objc/runtime.h>
you'll see methods for querying an object about its class, method selectors, ivars, etc. However, you don't usually want to do that, as it breaks encapsulation and can lead to you relying on implementation details that might change in the future, so be careful with it. You can read more here.