2
votes

I work with core data and I try to assign an int value (id) from WS to core data attribute (Integer 32) . The attribute is an NSNumber and when I code it :

        NSNumber *v = [responseMembers valueForKey:@"id"];
        newMember.idMember = v;

And, this error appears :

2013-06-17 11:08:24.407 EPNet[2190:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable

type of value for attribute: property = "idMember"; desired type = NSNumber; given type = __NSArrayI; value = ( 1, 2, 3, 4, 10, 14, 17, 5, 6, 7, 8, 9, 11, 12, 13, 15, 16, 18, 19, 20 ).'

Can you help me please ?

1
show the declaration of idMember.Bhavin
The declaration generated by xcode: @property (nonatomic, retain) NSNumber * idMember;Benjamin
What's responseMembers ?Bhavin

1 Answers

1
votes

The Property idMember is a NSNumber, but for some reason the value for your key @"id" seems to be an array (looks like there where all ids in it?)

edit: responseMembers is a NSMutableArray, you should not be able to ask for a valueForKey. Try something like this instead:

foreach (NSDictionary *member in responseMembers)
{
    NSNumber *v = [member valueForKey:@"id"];
    //do something with this id
}

the json you are reading looks like an array with many dictionaries, and your ids are one layer deeper:

[
  //first member
  {
    "content": "some entry",
    "id": 5,
    // some more attributes
  },
  //second member
  {
    "content": "some entry",
    "id": 5,
    // some more attributes
  },
  //and so on
]