@dynamic for some, but not all properties

19 views
Skip to first unread message

Brendan Duddridge

unread,
Jun 5, 2015, 1:28:01 AM6/5/15
to mobile-c...@googlegroups.com
Hi,

So I am working on a subclass of CBLModel and I would like to have some properties persisted and other properties not persisted. I have declared @dynamic in the Implementation for those properties that I wan to be persisted. But I get warnings that I have to add setters and getters for the properties I don't want persisted. Is that the case? Do I really have to declare all my properties as either @dynamic or I have to add setters and getters? Is there a way to just turn off the warning?

Thanks,

Brendan

Jens Alfke

unread,
Jun 5, 2015, 11:42:59 AM6/5/15
to mobile-c...@googlegroups.com

On Jun 4, 2015, at 10:28 PM, Brendan Duddridge <bren...@gmail.com> wrote:

But I get warnings that I have to add setters and getters for the properties I don't want persisted. Is that the case? Do I really have to declare all my properties as either @dynamic or I have to add setters and getters?

Use @synthesize to tell Xcode to generate getters/setters for the other properties.

(@synthesize is optional in recent versions of Clang, so some people aren’t even aware of it. But in CBLModel.h I added a declaration to the @interface that tells the compiler to stop implicitly synthesizing properties. I did this because a lot of people ran into problems where they forgot to add “@dynamic” for a persistent property, and Xcode just silently made it a synthesized property without any warning, so their model class just behaved incorrectly. This was confusing and difficult to debug.)

—Jens

Brendan Duddridge

unread,
Jun 5, 2015, 12:22:49 PM6/5/15
to mobile-c...@googlegroups.com
Ah I see. Ok. I used to synthesize all my properties, but once Clang didn't require it anymore, I removed all the @synthesize declarations. Guess it's back to 2 years ago :-)
Reply all
Reply to author
Forward
0 new messages