类类型Objective C [英] Class type Objective C

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

问题描述

NSObject 协议中,它定义了类似于以下的方法:

In the NSObject protocol, it defines a method that is similar to this:

-(Class) class

Class对象是什么类型的对象?或者甚至是一个对象?我可以用对象做什么?

What type of object is the Class object? Or is it even an object? What can I do with the object? Can I get the base class or adopted protocols?

推荐答案

是本身是由 Objective-C运行时定义的类,类似于Java中的 Class 类。例如,您可以使用 class_getClassName() 获取类的名称:

Class is itself a class defined by the Objective-C runtime, akin to the Class class in Java. For example, you can use the function class_getClassName() to get the name of a class:

NSObject *o = [[[NSObject alloc] init] autorelease];
NSLog(@"%s\n", class_getClassName([o class]));  // prints "NSObject"

您可以使用 Class objects;有关详细信息,请参阅Objective-C运行时参考。

You can do all kinds of introspection/reflection with Class objects; see the Objective-C runtime reference for details.

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

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