key value observing - [iOS]KVO setValuesForKeysWithDictionary -


i using setvaluesforkeyswithdictionary populate model object . model object defined as

@interface commonmodel : nsobject     @property (nonatomic,copy)nsstring *imageurl;     @property (nonatomic,copy)nsstring *name;     @property (nonatomic,copy)nsstring *uuid;     @property (nonatomic,strong)metadatamodel *metadata;     @property (nonatomic,copy)nsstring *type;     @property (nonatomic,copy)nsstring *age; @end 

and init class follows

commonmodel *model = [[commonmodel alloc] init]; [model setvaluesforkeyswithdictionary:dic]; 

the dic server data

{     category = random;     created = 1436348796510;     duration = 259;     metadata =     {         path = "/songs/396677ea-2556-11e5-afe1-033c8b2070b7";     };     modified = 1436348796510;     name = "\u6ce1\u6cab";     type = song;     url = "http://www.devinzhao.com/pomo.mp3";     uuid = "396677ea-2556-11e5-afe1-033c8b2070b7"; } 

i knew type should "song" not song.

when use [model setvalue:@"type" forkey:@"type"]; doesn't crash.

but don't want use like

[model setvalue:@"type" forkey:@"type"]; 

how solve problem?

forget using kvc , manually code init method accepts nsdictionary.

you can make decisions how each value in dictionary interpreted; example type should enum, not string, imageurl should nsurl, uuid should nsuuid, etc.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -