objective c - How to Incorporate an Array Into Model Object With Mantle? -
i have json object so:
{ "name": "brendan", "images": ["some.url.to.image1", "some.url.to.image2", "some.url.to.image3"] }
my class follows:
@interface mymodel : mtlmodel <mtljsonserializing> @property (nonatomic, copy) nsstring *name; @property (nonatomic, copy) nsarray *images; @end @implementation mymodel + (nsdictionary*)jsonkeypathsbypropertykey { return @{ @"name" : @"name", @"images" : @"images" }; } @end
i can verify mymodel object has name
set, images
set null
. how can populate array of strings mantle?
update: apparently mtl_externalrepresentationarraytransformerwithmodelclass:
deprecated. might work:
[mtljsonadapter arraytransformerwithmodelclass:[nsstring class]];
you need specify value transformer key images
array value transformer. can class method (on mymodel
class) correct name. might work. have not tested code.
+ (nsvaluetransformer *)imagestransformer { return [nsvaluetransformer mtl_externalrepresentationarraytransformerwithmodelclass:[nsstring class]]; }
Comments
Post a Comment