[__NSArrayM intValue]: unrecognized selector sent to instance

1.3k views Asked by At

I'm using MagicalRecord to pull a json file from my server. All my Objects load fine except for an equipment object. Here's the log of the JSON file

    "Equipment":[
  {
    "equipmentID":1,
    "equipmentName":"Barbell",
    "equipmentDescription":"Barbell"
  }
]

My Equipment class is a pretty basic setup

@property (nonatomic, retain) NSNumber * equipmentID;
@property (nonatomic, retain) NSString * equipmentName;
@property (nonatomic, retain) NSString * equipmentDescription;

In the data model, I have equipmentID as Integer 16. If I change it to Integer 64 then I get this error.

[__NSArrayM longLongValue]: unrecognized selector sent to instance

I don't understand what's the issue, the format is consistent with other objects in the same JSON file. The equipmentID is obviously an intValue and the Equipment class is setup as a NSNumber with equipmentID as an integer.

Any help? Is there a bug with Magical Record?

2

There are 2 answers

0
iPatel On

You need to write like,

self.equipmentID = [NSNumber numberWithInt:[[[[myDic objectForKey:@"Equipment"] objectAtIndex:0] objectForKey:@"equipmentID"] intValue]]; // Or floatValue or whatever you need.
self.equipmentName = [[[myDic objectForKey:@"Equipment"] objectAtIndex:0] objectForKey:@"equipmentName"]; 
self.equipmentDescription = [[[myDic objectForKey:@"Equipment"] objectAtIndex:0] objectForKey:@"equipmentDescription"]; 
0
jon_na_fun On

So it turns out my json is an array format (should've known from the brackets). I used MR_importFromObject instead of MR_importFromArray. Very stupid of me.