在Objective-C中,如何测试对象类型? [英] In Objective-C, how do I test the object type?

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

问题描述

我需要测试对象的类型是 NSString 还是 UIImageView 。我怎么能做到这一点?是否有某种类型的isoftype方法?

I need to test whether the object is of type NSString or UIImageView. How can I accomplish this? Is there some type of "isoftype" method?

推荐答案

如果你的对象是 myObject ,你想测试它是否是 NSString ,代码如下:

If your object is myObject, and you want to test to see if it is an NSString, the code would be:

[myObject isKindOfClass:[NSString class]]

同样,如果你想测试 myObject UIImageView

Likewise, if you wanted to test myObject for a UIImageView:

[myObject isKindOfClass:[UIImageView class]]

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

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