Objective-C-我们应该对类类型使用强,弱还是赋值? [英] Objective-C - Should we use strong, weak or assign for Class-type?

查看:87
本文介绍了Objective-C-我们应该对类类型使用强,弱还是赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们应该对Obj-C对象的属性/ivars使用强/弱.但是我发现我可以对class-type属性/ivars使用strong.

I know that we should use strong/weak for Obj-C objects properties/ivars. But I found that I can use strong for Class-type properties/ivars.

@property (nonatomic, strong) Class testClass;

该代码不会导致生成错误.为什么?我们应该使用强还是分配?

The code will not cause a build error. Why? And should we use strong or assign?

推荐答案

根据班级的秘密生活

类对象不是实例,但绝对是成熟的对象

A class object is not an instance, but it is definitely a full-fledged object

您无需执行任何操作即可创建类对象.程序启动时,会自动为您创建程序定义的每个类的一个类对象.

You don’t have to do anything to create a class object. One class object for every class your program defines is created for you automatically as the program starts up.

当然,您可以将strong用于对象.

Of course, you can use strong for an object.

何时释放类对象?-简单的答案是程序完成时.

When is a class object released? - Simple answer is when program is finished.

没有理由关心对象的保留计数,该对象在程序运行时将永远不会释放.这意味着无论您使用强/弱/分配,都没有关系,直到程序完成,该对象仍不会被破坏.

There is no reason to care about Retain Count of an object which will be never released while program is running. It means that doesn't matter if you use strong/weak/assign, this object is still not be destroyed until program is finished.

因此,您可以使用任何所需的值,它们将产生相同的结果.

So you can use whatever you want, they will give same result.

这篇关于Objective-C-我们应该对类类型使用强,弱还是赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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