Reputation: 1223
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?
Upvotes: 1
Views: 1346
Reputation: 1223
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.
Upvotes: 0
Reputation: 47089
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"];
Upvotes: 1