天天看点

iOS @synthesize和@dynamic

@property对应两个选择

1、@synthesize will generate getter and setter methods for your property.

2、@dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass)

Uses for @dynamic are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an outlet for a property defined by a superclass that was not defined as an outlet:

大概意思就是:

@synthesize 能够为您的属性的getter和setter方法。有自定义会屏蔽自动生成的getter和setter

@dynamic 不会自动生成getter/setter方法,需要自己实现,不然会报错

运行时动态创建绑定:主要使用在CoreData的实现NSManagedObject子类时使用,由Core Data框架在程序运行的时动态生成子类属性