objective-c – safe __attribute __((构造函数))函数类

objective-c – safe __attribute __((构造函数))函数类,第1张

概述在__attribute __((构造函数))函数中使用自己项目中定义的类是否安全?当调用__attribute __((构造函数)函数时,Objective-C运行时是否有机会对类执行所需 *** 作?或者我是否误解了运行时如何加载类,并且在此上下文中库类和您自己的类之间没有区别? 我建议你使用初始化或加载而不是属性,但这是我的偏好. 当运行时加载类时,将调用类的load方法. 类的initialize 在__attribute __((构造函数))函数中使用自己项目中定义的类是否安全?当调用__attribute __((构造函数)函数时,Objective-C运行时是否有机会对类执行所需 *** 作?或者我是否误解了运行时如何加载类,并且在此上下文中库类和您自己的类之间没有区别?解决方法 我建议你使用初始化或加载而不是属性,但这是我的偏好.

当运行时加载类时,将调用类的load方法.

类的initialize方法在类中的任何其他方法之前调用.

从加载文档:

On Mac OS X v10.5,the order of initialization is as follows:

All initializers in any framework you link to. All +load methods in your image. All C++ static initializers and C/C++ attribute(constructor) functions in your image. All initializers in frameworks that link to you.

In addition:

A class’s +load method is called after all of its superclasses’ +load methods. A category +load method is called after the class’s own +load method.

In a +load method,you can therefore safely message other unrelated classes from the same image,but any +load methods on those classes may not have run yet.

这清楚地表明在初始化运行时之后将运行任何属性或加载方法.因为load是类的一个方法,并且在任何属性方法之前运行,然后运行时必须设置类.

总结

以上是内存溢出为你收集整理的objective-c – safe __attribute __((构造函数))函数类全部内容,希望文章能够帮你解决objective-c – safe __attribute __((构造函数))函数类所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1005500.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存