What is common case for @dynamic usage?

岁酱吖の 提交于 2019-11-29 11:20:23

@dynamic indicates to the compiler that you plan to provide your own implementation for the accessor(s), even if the compiler can't currently see them. If you omit @dynamic and don't use @synthesize, one of two things will happen:

  1. If you've only provided half an accessor (for instance, a getter without a setter on a readwrite property), or you're using GCC, the compiler will warn you.
  2. If you're using Clang to compile your code, proper accessors will be automatically generated for you. (Synthesize-by-default is not officially supported.)

@dynamic is therefore useful to prevent the compiler from doing either of the above. This might also come in handy if you implement a property in a very dynamic way, like with runtime functions, but that's rarely necessary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!