Is it not safe to call Accessor methods in init and dealloc methods in Objective C?
Is it not safe to call Accesso开发者_如何转开发r methods in init and dealloc methods in Objective C?
It depends on the setters. Some may be safe to call, some not. The problem is you can’t be sure which are, since subclasses can override them. If a subclass overrides a setter you use in -init
you’re calling it before the subclass is fully initialized which is a potentially unsafe operation.
You may also want to look at this question.
There shouldn't be a problem though not sure why you would want to call accessors in init or dealloc. Also you don't really need to call accessors since you are in an instance method and can reference the variables directly.
精彩评论