如何在Objective-C中获取方法的返回类型? [英] Way to get return type of a method in Objective-C?

查看:92
本文介绍了如何在Objective-C中获取方法的返回类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iOS上编写一个通用的属性/密钥编辑器视图类,它使用 [objectForKey isKindOfClass:[NSDate class]] 。当我意识到如果 objectForKey nil 会失败时,我碰壁了。是否有一种方法可以获取通用Objective-C属性的类/返回类型,即使该属性为 nil 呢?我在Objective-C运行时知道 method_getReturnType ,但这听起来像是我需要的东西。

I'm writing a generic 'attribute/key editor' view class on iOS, and it checks the type of the editing key using [objectForKey isKindOfClass:[NSDate class]], for example. I just ran into a wall when I realized that will fail if objectForKey is nil. Is there a way to get the class/return type for a generic Objective-C property, even if said property is nil? I know about method_getReturnType in the Objective-C run-time, but that sounds like overkill for what I need.

推荐答案

您不能。尽管可以使用方法的返回类型信息,但是用于返回对象的方法的返回类型编码只是 @ ,表示对象引用。

You can’t. Although return type information for methods is available, the return type encoding for methods which return objects is simply @, meaning "object reference".

这篇关于如何在Objective-C中获取方法的返回类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆