Objective-C:检索 Class 实例的超类的首选方法 [英] Objective-C: preferred way to retrieve the superclass of a Class instance

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

问题描述

我想知道以下两种方法中哪一种是检索 Class 变量的超类的正确或首选方法:

I am wondering which of the two following methods is the correct or preferred one to retrieve the superclass of a Class variable:

  1. Class getSuperclass(Class cls) { return [cls superclass];}

Class getSuperclass(Class cls) { return class_getSuperclass(cls);}

推荐答案

好吧,docs 说:

Well, the docs on class_getSuperclass() say this:

你通常应该使用 NSObject 的超类方法而不是这个功能

You should usually use NSObject‘s superclass method instead of this function

所以,我会选择 1 号门.

So, I'd go with door #1.

这篇关于Objective-C:检索 Class 实例的超类的首选方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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