Realm objective c - array of array -


i have features in product json. list of strings. but, have localized. so, becomes array of array.

i not able array of array in realm. can suggest me how can achieve in realm objective-c ?

{  "name" : "product 1",  "features" : [  [   { "locale" : "en", value : "feature1"},   { "locale" : "cn", value : "feature1 in cn"}  ],  [   { "locale" : "en", value : "feature2"},   { "locale" : "cn", value : "feature2 in cn"}  ] ] } 

thanks

by modifying json slightly, either @ source or part of mapping step in code, can pass directly realm's kvc initialization mechanism:

{   "name": "product 1",   "features": [     [[       { "locale": "en", "value": "feature1" },       { "locale": "cn", "value": "feature1 in cn" }     ]],     [[       { "locale": "en", "value": "feature2" },       { "locale": "cn", "value": "feature2 in cn" }     ]]   ] } 

which maps these realm models:

@interface feature : rlmobject @property nsstring *locale; @property nsstring *value; @end @implementation feature @end  rlm_array_type(feature);  @interface featurelist : rlmobject @property rlmarray<feature> *features; @end @implementation featurelist @end  rlm_array_type(featurelist);  @interface product : rlmobject @property nsstring *name; @property rlmarray<featurelist> *features; @end @implementation product @end 

at point, can deserialize json dictionary , initialize realm object graph this:

nsdictionary *productdictionary = [nsjsonserialization jsonobjectwithdata:[nsdata datawithcontentsofurl:[[nsbundle mainbundle] urlforresource:@"product" withextension:@"json"]] options:0 error:nil]; [product createindefaultrealmwithvalue:productdictionary]; 

which gives following object graph:

[0] product {   name = product 1;   features = rlmarray <0x7fe43366be00> (     [0] featurelist {       features = rlmarray <0x7fec3a772c10> (         [0] feature {           locale = en;           value = feature1;         },         [1] feature {           locale = cn;           value = feature1 in cn;         }       );     },     [1] featurelist {       features = rlmarray <0x7fec3a773d20> (         [0] feature {           locale = en;           value = feature2;         },         [1] feature {           locale = cn;           value = feature2 in cn;         }       );     }   ); } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -