2013-07-12 58 views
1

我正在嘗試使用CoreData以及RestKit 0.20.0我得到了CoreData錯誤。CoreData:錯誤:無法調用NSManagedObject類'Class Name'上的指定初始值設定項

// Response.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 

和Implementaion文件

// Response.m

進口 「Response.h」

@implementation Response 

@dynamic error; 
@dynamic responseCode; 
@dynamic responseMsg; 
@dynamic statisticsDetails; 
@dynamic status; 

@end 

和我的視圖控制器代碼是

// 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' 

請幫助我。在此先感謝

回答

2

您正在創建RKObjectManager實例,但未提供對managedObjectStore的引用,這很可能是問題的原因。

+2

manager.managedObjectStore = managedObjectStore;你在談論這一行嗎? 如果不是,請幫助我。 – Suresh

相關問題