小编Mic*_*ose的帖子

RestKit 0.20 - CoreData:错误:无法在NSManagedObject类上调用指定的初始化程序

我遇到了一个新的问题,我似乎无法找到解决方法......这是我的RestKit代码,遵循Twitter核心数据示例:

//
// RESTKIT
//

// restkit object manager
NSString *baseURL = @"http://test1.website.com";
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:baseURL]];

// enable activity indicator
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;

// managed object model
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"AppName" withExtension:@"momd"];
NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
// NSLog(@"managed object model: %@", managedObjectModel);

// managed object store
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
objectManager.managedObjectStore = managedObjectStore;
// NSLog(@"managed object store: %@", managedObjectStore);

// persistent store
NSError *error;
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"AppName.sqlite"];
NSPersistentStore …
Run Code Online (Sandbox Code Playgroud)

objective-c restkit restkit-0.20

19
推荐指数
1
解决办法
6212
查看次数

RestKit 0.20 - 创建新NSManagedObject的首选方法是什么?

我很想知道在RestKit 0.20中创建一个新的NSManagedObject的最佳方法是什么?目前我的代码看起来像这样:

#pragma mark - navigation buttons

- (void)createButtonDidTouch
{
    // create new album object    
    NSManagedObjectContext *context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
    NSManagedObjectContext *parentContext = RKObjectManager.sharedManager.managedObjectStore.mainQueueManagedObjectContext;
    context.parentContext = parentContext;
    NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Album" inManagedObjectContext:parentContext];
    Album *newAlbum = [[Album alloc] initWithEntity:entityDescription insertIntoManagedObjectContext:context];

    // pass object to create view to manipulate
    AlbumCreateViewController *createViewController = [[AlbumCreateViewController alloc] initWithData:newAlbum];
    createViewController.delegate = self;
    createViewController.managedObjectContext = context;

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:createViewController];
    navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

    [self presentViewController:navController animated:YES completion:nil];
}

#pragma mark - create view …
Run Code Online (Sandbox Code Playgroud)

restkit restkit-0.20

8
推荐指数
1
解决办法
4523
查看次数

标签 统计

restkit ×2

restkit-0.20 ×2

objective-c ×1