An old post explains pretty well: Why shoudn't I use accessor methods in init methods
But my question is:
Q. If I am not overriding accessor methods in sub class in Objective C, is it safe to use in init?
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.
It is usually avoided to prevent KVO mechanisms from accessing a partially initialised or partially deallocated object. This is particularly true for Mac OS X development where bindings and KVO play a large part especially in an application’s user interface. I’m not an iPhone developer but if KVO is used on the iPhone platform as well, then it may be reason enough to avoid using accessor methods in your
initanddeallocmethods.KVO makes a dynamic subclass of your class so that it can easily monitor changes to properties.
It’s easy enough to avoid them in
initanddealloc. Some argue that it’s easier to use the accessor methods everywhere regardless of Apple’s recommendations, but the convention is to avoid using them forinitanddeallocand following the convention usually means less hurt later even if you don’t anticipate any problems now.