iPhone如何检查对象的类型? [英] iPhone how to check the type of an Object?

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

问题描述

我想检查一个Object的类型。我该怎么做?

I want to check the type of an Object. How can I do that?

情节是我得到一个对象。如果该对象是A类型,则执行一些操作。如果它是B类,那么做一些操作。目前,对象的类型是C,它是A和B的父级。

The scenario is I'm getting an object. If that object is of type A then do some operations. If it is of type B then do some operations. Currently the type of the object is C that is parent of A and B.

我有两个类 AViewController BViewController 。我进入的对象 UIViewController 。现在如何检查对象是 AViewController 还是 BViewController

I have two classes AViewController andBViewController. The object I'm getting in UIViewController. Now how to check whether the object is AViewController or BViewController?

推荐答案

if([some_object isKindOfClass:[A_Class_Name class]])
{
    // do somthing
}

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

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