NSKeyValueCoding support for CBLModel class?

13 views
Skip to first unread message

Brendan Duddridge

unread,
Aug 5, 2015, 2:30:40 PM8/5/15
to Couchbase Mobile
Hi,

I've got an NSTokenField in my app and I'm trying to allow the user to drag and drop tokens. Because of that, I need to archive the represented objects (my CBLModel subclass) and do the things that need to be done to make that work, such as implement `encodeWithCoder` and `initWithCoder`. But since CBLModel doesn't implement NSCoding nor does it extend eventually from NSResponder, I'm having a hard time making this work.

In my previous model I defined my base class like this:

@interface BaseEntity : NSResponder <NSCoding>


And that seemed to allow NSKeyValueCoding to function properly for my drag and drop needs.

I'm wondering if there's an alternative technique I should be using to support drag and drop? This is a Mac OS X app btw.

When I try to implement encodeWithCoder and initWithCoder, I am unable to call super and I also get the following error from CBL:

*** Assertion failure in -[TFField setValue:ofProperty:], /Projects/iPhone/couchbase-lite-ios/Source/API/CBLModel.m:481

Invalid parameter not satisfying: _document


I tried encoding 'document', but it's a read-only property:

self.document = [aDecoder decodeObjectForKey:@"document"];


Perhaps I'm going about this all wrong.

Thanks,

Brendan

Jens Alfke

unread,
Aug 5, 2015, 2:57:17 PM8/5/15
to mobile-c...@googlegroups.com

On Aug 5, 2015, at 11:30 AM, Brendan Duddridge <bren...@gmail.com> wrote:

When I try to implement encodeWithCoder and initWithCoder, I am unable to call super and I also get the following error from CBL:

Oh, interesting. Yeah, making models encodable is problematic because they should be unique — there should only be one CBLModel instance corresponding to a specific document. Whereas if you could encode/decode them, you could easily end up with duplicates (encode a model, then decode it — now you have two of it.)

I suggest making the token objects just be stubs — for example, use the document ID (an NSString) as the token. It’s easy to map between that and the model object in either direction.

—Jens

Brendan Duddridge

unread,
Aug 5, 2015, 4:22:17 PM8/5/15
to Couchbase Mobile
Hi Jens,

I think I'll need to create some sort of "proxy" class to represent the model object. Because I need to intermix text and tokens, so there would be no way to distinguish a token from text if the tokens were just instances of NSString.

Right now I have a TFField class that I was trying to encode and I think I'll just create a TFFieldProxy class and use that to convert between the document ID to real TFField objects.

Thanks,

Brendan
Reply all
Reply to author
Forward
0 new messages