在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
,但是这听起来像我需要的overkill。
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屋!