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

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

问题描述

我在iOS上编写一个通用的属性/键编辑器视图类,并使用 [objectForKey isKindOfClass:[NSDate class]] 。我刚碰到一堵墙,当我意识到如果 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屋!

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