如何在Objective-C中获取方法的返回类型? [英] Way to get return type of a method in Objective-C?
问题描述
我正在iOS上编写一个通用的属性/密钥编辑器视图类,它使用 [objectForKey isKindOfClass:[NSDate class]] $ c $检查编辑键的类型。例如,c>。当我意识到如果
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屋!