MagicalRecord-如何处理不推荐使用的方法?

时间:2018-07-26 07:46:16

标签: ios objective-c core-data magicalrecord

我有一个旧的代码(大部分写于2014-2015年),我需要尽可能轻松地对其进行更新。

第一部分:

NSManagedObjectContext *parentContext = [NSManagedObjectContext MR_contextForCurrentThread];
NSManagedObjectContext *context = [NSManagedObjectContext MR_contextWithParent:parentContext];

它说:

  

不推荐使用“ MR_contextForCurrentThread”:   在MagicalRecord 3.0中删除

我试图通过互联网实施解决方案,但没有一个对我有帮助。

第二部分:

 (IBAction)addButtonAction:(id)sender {
    NSString *title = @"";
    AppActionSheet *actionSheet = [AppActionSheet actionSheet];
    [actionSheet setButtonWithTitle:AppLocalizedString(@"eventsCreateMenuCreateEvent") block:^{
        [self actionSheetCreateNewEventDidSelected];
    }];
[actionSheet showInView:self.view];
}

- (void)actionSheetCreateNewEventDidSelected {
    NSManagedObjectContext *context = [NSManagedObjectContext MR_context];
    AppEvent *event = [AppEvent MR_createEntityInContext:context];
    AppContact *contact = [[AppUserSettings shared] authorizedUserInContext:context];
    [event.participantsSet addObject:contact];
    [event.activeParticipantsSet addObject:contact];
    event.owner = contact;
    event.modificationDate = [NSDate date];
    AppEventContact *item = [AppEventContact MR_createEntityInContext:context];
    item.contact = contact;
    item.event = event;
    item.index = @0;

    AppAddEventViewController *addEventVC = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]
                                            instantiateViewControllerWithIdentifier:@"AppAddEventViewController"];
    addEventVC.delegate = self;
    addEventVC.context = context;
    addEventVC.event = event;
    [self.navigationController pushViewController:addEventVC animated:YES];
}

AddButton打开按钮列表,并且该列表中的一个按钮应该打开视图CreateNewEvent。 调试时,当我按CreateEvent时,它会停在第4个字符串上,但不会转发到[self actionSheetCreateNewEventDidSelected]; 第三和最后一个:

[managedContext lock];
    [managedContext reset];
    //delete the store from the current managedObjectContext
    if ([[managedContext persistentStoreCoordinator] removePersistentStore:[[[managedContext persistentStoreCoordinator] persistentStores] lastObject] error:&error]) {
        // remove the file containing the data
        [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
        //recreate the store like in the  appDelegate method
        [[managedContext persistentStoreCoordinator] addPersistentStoreWithType:NSSQLiteStoreType
                                                                 configuration:nil
                                                                           URL:storeURL
                                                                       options:nil
                                                                         error:&error];
    }
[managedContext unlock];

它抱怨锁定和解锁,但是简单地删除这两个字符串是不正确的(无论如何它们不再起作用了,而应用程序似乎正在起作用)?

我正在考虑快速重写所有内容,但希望现在有办法对其进行修复。 并预先感谢!

0 个答案:

没有答案