iOS基础学习

Objective-C基础学习之new方法实现原理

2017-09-23  本文已影响26人  WenJim

1.new方法实现原理

This method is a combination of alloc and init. Like alloc, it initializes the isa instance variable of the new object so it points to the class data structure. It then invokes the init method to complete the initialization process.
The isa instance variable of the new instance is initialized to a data structure that describes the class; memory for all other instance variables is set to 0.
An object isn’t ready to be used until it has been initialized. The init method defined in the NSObject class does no initialization; it simply returns self.
Person *p1 = [Person new];
Person *p = [[Person alloc] init];
上一篇 下一篇

猜你喜欢

热点阅读