Why to use [super init] in Objective C constructors?

前端 未结 4 1941
面向向阳花
面向向阳花 2021-01-24 14:34

Say I have a class named Item. Which is a superclass of NewsItem and TwitterItem.

If I want to create some NewsItem\'s do I have to use (inside constructor)

<         


        
4条回答
  •  生来不讨喜
    2021-01-24 14:49

    since your custom object will at least inherit from the mothers of all Objects: NSObject, you have to call '[super init];' 'super' simply does call the init Method of its superclass

提交回复
热议问题