@implementation Son
- (instancetype)init{
if (self = [super init]) {
NSLog(@"%@",NSStringFromClass([self class]));
NSLog(@"%@",NSStringFromClass([self superclass]));
NSLog(@"%@",NSStringFromClass([super class]));
}
return self;
}
@end
这个问题主要是 self 和super
self refers to the object receiving a message in objective-C programming.
super is a flag that tells the compiler to search for the method implementation in a very different place. It begins in the superclass of the class that defines the method where super appears.
self 是从当前类开始找 super 是从 父类开始找。最后接受者 都是当前对象。所以返回的是一样的。
最后都返回 son father son
- @property 默认的数据类型
@property NSMutableArray *arr ;
@property int zz;
对应基本数据类型,默认关键字为
atomic, assign, readwrite
对应对象类型,默认关键字为
atomic, strong, readwrite
atomic 与 nonatomic 区别 读写安全。
atomic 确保 读写安全。会在set 之后读取数据。若多线程同时set 不确保最后读取数据的准确性。
网友评论