You need to tell CBL that nestedObjectArray is an array of NestedObject objects.
You do that by adding this piece of code to your NestingModel implementation:

+ (Class)nestedObjectArrayItemClass
{
        return [NestedObject class];
}

 Nico


> On Mar 13, 2015, at 10:51 AM, SeanDev <xyvictorw...@gmail.com> wrote:
> 
> 
> 
> Hi Guys,
> 
> I've been experimenting on CBLJSONEncoding which needs implementation of the 
> CBLJSONEncoding protocol:
> - (id)encodeAsJSON
> - (instancetype)initWithJSON:(id)jsonObject
> 
> When saving the nesting CBLModel subclass, encodeAsJSON worked as expected. 
> But when reading, I can only get a __NSCFDictionary, not the 
> NSObject<CBLJSONEncoding> one. And the break point for - 
> (instancetype)initWithJSON:(id)jsonObject is not reached.
> 
> Following are the code I tought might be useful, I think I must had missed 
> something:
> 
> The Nesting CBLModel
> 
> @interface NestingModel : CBLModel
> @property (readwrite) NSArray *nestedObjectArray; //An array of the following 
> NestedObject 
> @end
> 
> @implementation NestingModel
> @dynamic nestedObjectArray
> @end
> 
> 
> The Nested NSObject <CBLJSONEncoding>
> 
> 
> @interface NestedObject : NSObject <CBLJSONEncoding>
> @property (readwrite) NSString  *nestedObjectName;
> - (instancetype)initWithJSON:(id)jsonObject;
> - (id)encodeAsJSON;
> @end
> 
> @implementation NestedObject
> - (id)initWithJSON:(id)jsonObject {
>     self = [self init];
>     if(self) {
>         self. nestedObjectName = jsonObject[@"nestedObjectName"];
>     }    
>     return self;
> }
> 
> - (id)encodeAsJSON {
>     return @{@"nestedObjectName" : self. nestedObjectName};
> }
> @end
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Couchbase Mobile" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to mobile-couchbase+unsubscr...@googlegroups.com 
> <mailto:mobile-couchbase+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/mobile-couchbase/bdee77aa-092b-474c-b14a-92ae06f949b2%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/mobile-couchbase/bdee77aa-092b-474c-b14a-92ae06f949b2%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mobile-couchbase+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/751555B8-50F3-4FF7-ABF0-12B06B912308%40conceited.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to