我试图将 CoreData 与 RestKit 0.20.0 一起使用,但出现 CoreData 错误。
// 响应.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface Response : NSManagedObject
@property (nonatomic, retain) NSString * status;
@property (nonatomic, retain) NSString * responseCode;
@property (nonatomic, retain) NSString * responseMsg;
@property (nonatomic, retain) NSString * error;
@property (nonatomic, retain) NSString * statisticsDetails;
@end
和实施文件是
// 响应.m
导入“响应.h”
@implementation Response
@dynamic error;
@dynamic responseCode;
@dynamic responseMsg;
@dynamic statisticsDetails;
@dynamic status;
@end
我的 ViewController 代码是
// ViewController.m
#import "ViewController.h"
#import "StatisticsDetails.h"
#import "TopProjects.h"
#import <RestKit.h>
- (void)viewDidLoad
{
[super viewDidLoad];
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://mylocalUrl.com/Port"]];
/*managed object model */
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"momd"];
NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
NSLog(@"managed object model: %@", managedObjectModel);
/* managed object store */
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
manager.managedObjectStore = managedObjectStore;
NSLog(@"managed object store: %@", managedObjectStore);
/* persistent store*/
NSError *error;
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"Model.sqlite"];
NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:nil withConfiguration:nil options:nil error:&error];
if (error) {
NSLog(@"unresolved error , ");
NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);
}
/* managed object contexts*/
[managedObjectStore createManagedObjectContexts];
/* entity mapping */
RKEntityMapping *responseEntityMapping =[RKEntityMapping mappingForEntityForName:@"Response" inManagedObjectStore:managedObjectStore];
[responseEntityMapping addAttributeMappingsFromDictionary:@{
@"status" : @"status",
@"responseCode":@"responseCode",
@"responseMsg":@"responseMsg",
@"error":@"error",
@"statisticsDetails":@"statisticsDetails"
}];
RKResponseDescriptor *ResponseDescriptor = [ RKResponseDescriptor responseDescriptorWithMapping:responseEntityMapping pathPattern:nil keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] getObjectsAtPath:@"getStatistics/4" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
/* NSLog(@"mapping result: %d", [mappingResult array].count);
NSLog(@"Mapping Result: %@", mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(@"Operation failed with error: %@", error);
}];
错误是
2013-07-12 12:35:09.098 Dashboard[85919:5403] CoreData: error: Failed to call designated initializer on NSManagedObject class 'ResponseClas'
请帮我。提前致谢