Is it not safe to call Accessor methods in init an

2019-08-29 06:29发布

Is it not safe to call Accessor methods in init and dealloc methods in Objective C?

标签: objective-c
2条回答
不美不萌又怎样
2楼-- · 2019-08-29 06:41

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.

查看更多
Explosion°爆炸
3楼-- · 2019-08-29 07:00

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.

查看更多
登录 后发表回答