如何在iOS 10中将coredata迁移到Action扩展中

时间:2017-03-30 07:23:08

标签: objective-c core-data safari-extension core-data-migration

我是核心数据的新手,我使用this来执行某些步骤,但是从iOS 10开始,默认情况下会创建方法,

- (NSPersistentContainer *)persistentContainer {
// The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.
@synchronized (self) {
    if (_persistentContainer == nil) {
        _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"namanCoreData"];
        [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
            if (error != nil) {
                // Replace this implementation with code to handle the error appropriately.
                // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

                /*
                 Typical reasons for an error here include:
                 * The parent directory does not exist, cannot be created, or disallows writing.
                 * The persistent store is not accessible, due to permissions or data protection when the device is locked.
                 * The device is out of space.
                 * The store could not be migrated to the current model version.
                 Check the error message to determine what the actual problem was.
                */
                NSLog(@"Unresolved error %@, %@", error, error.userInfo);
                abort();
            }
        }];
    }
}

return _persistentContainer;}

关于如何将核心数据用于Action Extension的任何想法/链接/建议?救命 。 。 。

2 个答案:

答案 0 :(得分:0)

你可以做同样的事情。在initWithName之后和loadPersistentStoresWithCompletionHandler创建NSPersistent​Store​Description对象之前,设置其网址,然后将_persistentContainer的{​​{1}}属性设置为它。

答案 1 :(得分:0)