天天看點

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架構在程式運作的時動态生成子類屬性