You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 9, 2023. It is now read-only.
Right now the guide simply says to use direct ivar access in dealloc. You should also directly access ivars in init* methods. More generally, you shouldn't really be invoking any method inside init* or dealloc methods. Other methods (including accessors that may be overridden) may expecting the object to be in a fully constructed state. When you're inside one of these methods, that is not the case.
The text was updated successfully, but these errors were encountered:
If you're trying to be as defensive as possible, then you have to operate under the assumption that someone may have subclassed the class and overridden your public methods. These overrides may be assuming that when the method is invoked, all of the properties and ivars and everything are in a consistent and fully-initialized state.
So, if your initializer or dealloc method causes one of these overridden methods to be executed, then the logic of the method may do something incorrect. The best case scenario is that it works as intended. The worst case scenario is that you do something like dereference a NULL pointer or index beyond the bounds of an array or cause some data to become corrupted, etc.
Whilst you're inside an initializer or dealloc method, your object is in an inconsistent state. Thus, if you're trying to be as defensive as possible, you should avoid invoking methods that might be making assumptions about the state of the object.
Right now the guide simply says to use direct ivar access in
dealloc
. You should also directly access ivars ininit*
methods. More generally, you shouldn't really be invoking any method insideinit*
ordealloc
methods. Other methods (including accessors that may be overridden) may expecting the object to be in a fully constructed state. When you're inside one of these methods, that is not the case.The text was updated successfully, but these errors were encountered: