私はObjective-Cが初めてで、RestKitに非常にこだわっています。Web サーバーで JSON からのデータを使用して非常に単純なものを作成しようとしてUITableView
いますが、しばらく立ち往生しています。
これは私の単純な JSON です。
{
"restaurants": [
{
"id": "27",
"franchise_name": "Franchise 1",
"branch_name": "Branch 1",
"branch_phone": "0200 111 0000",
"cuisine": "Salad",
"cooking_time": "15",
"is_open": 1
},
{
"id": "97",
"franchise_name": "Franchise 2",
"branch_name": "Branch 2",
"branch_phone": "0207 222 0000",
"cuisine": "Healthy",
"cooking_time": "10",
"is_open": 1
}
]
}
これは私のコアデータモデルです:
Entities: Restaurant
Attributes: branchName -> String
franchiseName -> String
id -> integer 16
readyTime-> integer 16
ビューコントローラーに次のコードがあります。ではviewDidLoad
、RKEntityMapping
例外が発生します。
RKManagedObjectStore *managedObjectStore = [RKManagedObjectStore defaultStore];
RKEntityMapping *entityMapping = [RKEntityMapping mappingForEntityForName:@"Restaurant" inManagedObjectStore:managedObjectStore]; //THIS LINE CAUSES THE CRASH
[entityMapping addAttributeMappingsFromDictionary:@{
@"id": @"id",
@"cooking_time": @"readyTime",
@"branch_name": @"branchName",
@"franchise_name": @"franchiseName"}];
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:@"/api/restaurants" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; //I GET AN ISSUE HERE AS WELL INVOLVING responseDescriptorWithMapping BEING DEPRECIATED.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http//mywebserver.com/api/resturants"]];
RKManagedObjectRequestOperation *managedObjectRequestOperation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor ]];
managedObjectRequestOperation.managedObjectContext = self.managedObjectContext;
[[NSOperationQueue currentQueue] addOperation:managedObjectRequestOperation];
いくつかのエラーメッセージがありますが、実際にはどれも得られません:
NSAssert(objectClass, @"Cannot initialize an entity mapping for an entity with a nil managed object class: Got nil class for managed object class name '%@'. Maybe you forgot to add the class files to your target?", [entity managedObjectClassName]);
コンソールで:
*** Assertion failure in -[RKEntityMapping initWithEntity:],