简体   繁体   中英

Difference between [ self init ] and self = [ super init ]

I wonder what different between [ self init ] and self = [ super init ] in init family method if I don't override "init" method.

And why people usually use self = [ super init ] in init family method?

[ self init ] means you are initializing the self class.

and

self = [ super init ] means initializing super class and the returned address/memory location is set to self class.

people use self = [ super init ] to all parent classes up to NSObject , so this is very important to do

usually people use if (self = [ super init ]) {... return self;} just in case if self == nil , but i've never had such thing

[self init] is not right, because you just ignore initialization of parent classes, which might be a cause of bugs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM