根据我阅读的文档,@dynamic 在运行时创建访问器方法,而@synthesize 将在构建时创建访问器。
那么让我猜猜:@dynamic 节省了一些内存并且代码在内存页面中保持更小?还是什么?它们之间还有哪些其他区别?
是否可以这样说:“使用@dynamic 而不是@synthesize 总是一个好主意”?我的意思是...如果这真的可以节省内存,为什么不呢?
但我猜@dynamic 相对于@synthesize 有一些缺点,否则每个人都会使用@dynamic。那么有什么缺点呢?
最佳答案
没有。动态属性不会自动生成。 @dynamic
属性标记向编译器指示您将以某种方式提供访问器和 setter :
来自 Objective-C Programming Language Guide :
@dynamic
You use the
@dynamic
keyword to tell the compiler that you will fulfill the API contract implied by a property either by providing method implementations directly or at runtime using other mechanisms such as dynamic loading of code or dynamic method resolution.
关于iphone - @dynamic 和@synthesize 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2066193/