Show Menu

Do you have a job opening?

Submit your 30 day Job Listing for FREE

@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:

Super class:


@property (nonatomic, retain) NSButton *someButton;
...
@synthesize someButton;

Subclass:


@property (nonatomic, retain) IBOutlet NSButton *someButton;
...
@dynamic someButton;

I just came across this section of another blog:

Some accessors are created dynamically at runtime, such as certain ones used in CoreData’s NSManagedObject class. If you want to declare and use properties for these cases, but want to avoid warnings about methods missing at compile time, you can use the @dynamic directive instead of @synthesize.

Using the @dynamic directive essentially tells the compiler “don’t worry about it, a method is on the way.”

Taken from: http://theocacao.com/document.page/516

having issues?

We have a Questions and Answer section where you can ask your iOS Development questions to thousands of iOS Developers.

Ask Question

FREE Download!

Get your FREE Swift 2 Cheat Sheet and quick reference guide PDF download when you sign up to SwiftMonthly


Sharing is caring

If you enjoyed this tutorial, please help us and others by sharing using one of the social media buttons below.


Written by:

I work in the shadows. You can thank me by being a good soul.

Comments

comments