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

前端 未结 4 1944
面向向阳花
面向向阳花 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 15:00

    Because you are overriding the init message. If you don't override it then [[NewsItem alloc] init] would just call the superclass' init message. In C#, you might use base to do the same.

提交回复
热议问题