I am doing something wrong here... I know that
I'm using Xcode and I have created the following class using the data modeller:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface Project : NSManagedObject {
@private
}
@property (nonatomic, retain) NSNumber * indent;
@property (nonatomic, retain) NSNumber * collapsed;
@property (nonatomic, retain) NSString * color;
@property (nonatomic, retain) NSNumber * project_id;
@property (nonatomic, retain) NSNumber * item_order;
@property (nonatomic, retain) NSNumber * cache_count;
@property (nonatomic, retain) NSNumber * user_id;
@property (nonatomic, retain) NSString * name;
@end
When I am trying to propagate this class with data from a JSON source using the following code:
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"projects" ofType:@"json"];
if (filePath) {
NSString* jsonString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
DLog(@"JSON for Projects:%@", jsonString);
SBJsonParser* jsonParser = [SBJsonParser new];
id response = [jsonParser objectWithString:jsonString];
NSArray* array = (NSArray*) response;
NSEnumerator* e = [array objectEnumerator];
NSDictionary* dictionary;
while ((dictionary = (NSDictionary*)[e nextObject])) {
Project* project = [[Project alloc] init];
project.user_id = [dictionary objectForKey:@"user_id"];
project.name = [dictionary objectForKey:@"name"];
project.color = [dictionary objectForKey:@"color"];
project.collapsed = [dictionary objectForKey:@"collapsed"];
project.item_order = [dictionary objectForKey:@"item_order"];
project.cache_count = [dictionary objectForKey:@"cache_count"];
project.indent = [dictionary objectForKey:@"indent"];
project.project_id = [dictionary objectForKey:@"project_id"];
[elementArray addObject:project];
[project release];
}
}
However, the code stops at the project.user_id = [dictionary objectForKey:@"user_id"];
line with an exception "* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Project setUser_id:]: unrecognized selector sent to instance 0x590bcb0'"
I don't know why this is happening or how to resolve this.