I am aware that using setters in dealloc can create problems, if any other object is observing for changes in a property. But why should not we use them in initializers?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only reason not to use accessors in
-initis because your object is not fully initialised and the accessor may depend on it. This is only likely to happen if you have a subclass that overrides the accessor methods.There is a symmetrical problem on deallocation in that an overridden accessor might depend on not being called on a partially deallocated object. There is also the issue that you might send out spurious KVO notifications.
This goes to the heart of proper encapsulation. Subclasses should not need to care about the implementation details of the super class.