array of custom objects in CBModel

10 views
Skip to first unread message

Андрей Максимкин

unread,
Jan 17, 2017, 11:48:34 AM1/17/17
to Couchbase Mobile

I have a class

@interface QLCBBenefitModel : CBLModel


@property (nonatomic, copy, readonly) NSString *title;

@property (copy) NSArray<QLCBCategoryModel *> *categories;


+ (Class) itemClassForArrayProperty: (NSString*)property;


@end


@implementation QLCBBenefitModel


@dynamic title;

@dynamic categories;


+ (Class) itemClassForArrayProperty: (NSString*)property

{

   return [QLCBCategoryModel class];

}


@end


interface QLCBCategoryModel : NSObject


@property NSString *name;

@property NSString *slug;

@end


When I try to access the categories property on an instance, I get the following error message:


Dynamic property QLCBBenefitModel.categories has type '@"NSArray"' unsupported by QLCBBenefitModel


Anybody know how resolve this problem?

Jens Alfke

unread,
Jan 17, 2017, 12:07:25 PM1/17/17
to mobile-c...@googlegroups.com

> On Jan 17, 2017, at 6:55 AM, Андрей Максимкин <andrem...@gmail.com> wrote:
>
> interface QLCBCategoryModel : NSObject
>
> @property NSString *name;
> @property NSString *slug;
> @end

CBLModel doesn’t know how to convert JSON to/from QLCBCategoryModel. That class will need to implement the CBLJSONEncoding protocol (declared in CBLJSON.h.)

—Jens

Reply all
Reply to author
Forward
0 new messages