ios - How to tell the difference between a Boolean and an NSNumber in CoreData -


i have parsing code i'm using serialising , deserialising objects our web service , i've hit bit of problem when serialising booleans.

the serialisation looks this:

 - (nsdictionary *)dictionaryrepresentationwithmapping:(nsdictionary *)mappingdictionary {     nsmutabledictionary *dictionary = [[nsmutabledictionary alloc]init];      (id key in[mappingdictionary allkeys])     {         id value = [self valueforkey:key];          if ((value != [nsnull null]) && (![value iskindofclass:[nsnull class]]) && (value != nil))         {             [dictionary setobject:value forkey:mappingdictionary[key]];         }     }      return [nsdictionary dictionarywithdictionary:dictionary]; } 

the problem when call valueforkey: on nsmanagedobject , add dictionary end value being set if calling:

[dictionary setobject:@1 forkey:mappingdictionary[key]]; 

instead of:

[dictionary setobject:@yes forkey:mappingdictionary[key]]; 

this means when turn json, in next stage, i'm sending 1 instead of true server.

so need way of retaining fact nsnumber representing bool opposed number. i've tried asking class nsnumber. there way can retain automatically or failing that, there way can consult model see attribute type set to?

each entity has metadata stored in nsentitydescription , nsattributedescription. can access them nsmanagedobject in following way:

//you can put inside loop nsattributedescription *attributedescription = self.entity.attributesbyname[key]; if(attributedescription.attributetype == nsbooleanattributetype) {   //it boolean attribute } 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -