What are the differences between implementing a @property
with @dynamic
or @synthesize
?
Objective-c – @synthesize vs @dynamic, what are the differences
cocoacocoa-touchobjective cpropertiessynthesize
Related Topic
- Ios – What’s the difference between the atomic and nonatomic attributes
- Ios – How to sort an NSMutableArray with custom objects in it
- Ios – How to check for an active Internet connection on iOS or macOS
- Ios – How to make a UITextField move up when the keyboard is present – on starting to edit
- Objective-c – What’s are the differences between @dynamic and @synthesize
- Ios – Xcode – How to fix ‘NSUnknownKeyException’, reason: … this class is not key value coding-compliant for the key X” error
- Objective-c – Differences between strong and weak in Objective-C
- Python – How does the @property decorator work in Python
Best Answer
@synthesize will generate getter and setter methods for your property. @dynamic just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass or will be provided at runtime).
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.@dynamic also can be used to delegate the responsibility of implementing the accessors. If you implement the accessors yourself within the class then you normally do not use @dynamic.
Super class:
Subclass: