Correct [super dealloc]

后端 未结 2 1352
-上瘾入骨i
-上瘾入骨i 2021-02-07 15:21

Does the order of statements in the dealloc method matter? Does the [super dealloc] need to be at the top of the method? Does it matter?

Also in e.g.

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-07 16:02

    Does the order of statements in the dealloc method matter? Does the [super dealloc] need to be at the top of the method? Does it matter?

    It should go at the end. The idea is to say "I've torn down all the bits I've done, so now I'll let my parent class do the same" (recursively)

    Also in e.g. viewDidLoad. Should [super viewDidLoad] be at the top of the method?

    It should go at the top. The parent class should do what it needs to do to load its view before the subclass loads its parts, because it might rely on something the parent class needs to set up first.

提交回复
热议问题