我正在成功使用Core Data的自动轻量级迁移.但是,当在迁移期间创建特定实体时,我想用一些数据填充它.当然,我可以在每次应用程序启动时检查实体是否为空,但是当Core Data具有迁移框架时,这似乎效率低下.
是否可以检测轻量级迁移何时发生(可能使用KVO或通知),还是需要实现标准迁移?
我尝试过使用它NSPersistentStoreCoordinatorStoresDidChangeNotification,但是在迁移发生时它不会触发.
我的应用程序包中有一个"解压缩"文件夹.我需要获取txt类型的所有文件的资源路径.我一直在用这个,
NSArray *filePaths = [NSBundle pathsForResourcesOfType:@"txt" inDirectory:[[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/unzipped"]];
Run Code Online (Sandbox Code Playgroud)
但它只获取第一个目录中的文件.我错过了哪个递归版本的某个地方?
我试图在手机IOS 13 Beta上从Xcode11 beta构建我的应用程序。加载应用程序时发生崩溃。
2019-07-22 13:58:12.910460 + 0300 GoodWine [3738:792501] [错误]错误:此应用程序中的一个或多个模型使用的可变形属性的变压器名称未设置或设置为NSKeyedUnarchiveFromDataTransformerName。请改用“ NSSecureUnarchiveFromData”或NSSecureUnarchiveFromDataTransformer的子类。在某些时候,当指定nil时,Core Data将默认使用“ NSSecureUnarchiveFromData”,并且包含不支持NSSecureCoding的类的可转换属性将变得不可读。
CoreData:错误:此应用程序中的一个或多个模型正在使用可变形的属性,且其变压器名称未设置或设置为NSKeyedUnarchiveFromDataTransformerName。请改用“ NSSecureUnarchiveFromData”或NSSecureUnarchiveFromDataTransformer的子类。在某些时候,当指定nil时,Core Data将默认使用“ NSSecureUnarchiveFromData”,并且包含不支持NSSecureCoding的类的可转换属性将变得不可读。
2019-07-22 13:58:12.910595 + 0300 GoodWine [3738:792501] [错误] CoreData:此应用程序中的一个或多个模型使用的可变形属性的变压器名称未设置或设置为NSKeyedUnarchiveFromDataTransformerName。请改用“ NSSecureUnarchiveFromData”或NSSecureUnarchiveFromDataTransformer的子类。在某些时候,当指定nil时,Core Data将默认使用“ NSSecureUnarchiveFromData”,并且包含不支持NSSecureCoding的类的可转换属性将变得不可读。
CoreData:警告:实体“ SFMCKeyValueEntity”上的属性“值”正在使用nil或不安全的NSValueTransformer。请改用“ NSSecureUnarchiveFromData”或NSSecureUnarchiveFromDataTransformer的子类。
我有一个ios应用程序,预先存在sqlite数据库,我正在使用核心数据.现在我发布了一个新版本的应用程序,在核心数据预先存在存储(sqlite)中进行了一些属性更改.现在用户更新应用程序,然后应用程序在加载时崩溃并给出下面给出的错误.我通常在iphone simulatore中修复此错误但重置模拟器.但现在如何为我的实时用户处理这个问题.
如果我的用户删除了应用程序,然后安装新版本,那么它可以正常工作

我正在尝试使用CoreData中的迁移功能.我已经关注了Apple文档.我在以下方法中遇到问题:
/**
Returns the managed object model for the application.
If the model doesn't already exist, it is created by merging all of the models found in the application bundle.
*/
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel != nil) {
return managedObjectModel;
}
/*
* NSInvalidArgumentException', reason: '*** -[NSCFArray insertObject:atIndex:]: attempt to insert nil'
* 2010-02-17 16:27:15.338 Patrimoine[3037:207]
*/
managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
return managedObjectModel;
}
Run Code Online (Sandbox Code Playgroud)
http://iphonedevelopment.blogspot.com/2009/09/core-data-migration-problems.html上似乎存在同样的问题
然而,我确实选择了Apple建议的方法,使用菜单选项"添加模型版本".
你有什么主意吗?
我有一个核心数据EntityDescription,我在其中创建了数据.然后,我更改了EntityDescription,添加了新的,使用编辑器xcdatamodeld文件删除旧的.
现在,我的核心数据代码都会导致此错误"The model used to open the store is incompatible with the one used to create the store}".详情如下.我该怎么办?我更喜欢删除数据模型中的所有内容并重新启动新数据模型.
谢谢你的任何建议!
reason=The model used to open the store is incompatible with the one used to create the store}, {
metadata = {
NSPersistenceFrameworkVersion = 320;
NSStoreModelVersionHashes = {
Promotion = <472663da d6da8cb6 ed22de03 eca7d7f4 9f692d88 a0f273b7 8db38989 0d34ba35>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
);
NSStoreType = SQLite;
NSStoreUUID = "9D6F4C7E-53E2-476A-9829-5024691CED03";
"_NSAutoVacuumLevel" = …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的问题,涉及轻量级迁移和核心数据版本控制的使用。
众所周知,在修改 Core Data 模型时,需要确保可以从旧模型转换到新模型。
对于简单的更改(例如添加新属性),只需轻量级迁移即可。网上有很多信息表明,为了确保一切顺利,需要:
通过以下选项支持轻量级迁移:
让选项 = [NSMigratePersistentStoresAutomaticallyOption:true,NSInferMappingModelAutomaticallyOption:true]
这种方法肯定效果很好。然而,我还发现,对于简单的更改,不需要新的模型版本。在我的一个应用程序中,我已经发布了几项更新,其中包括对核心数据模型的更改(所有这些更新都包含新属性的添加),并且在没有任何新模型版本的情况下成功应用了轻量级迁移。
根据我的经验,当修改核心数据版本时,它似乎会被分配某种新的标识符。然后,当该版本在具有该型号旧版本的手机上启动时,进行轻量级迁移不会出现任何简单更改的问题。
然而,鉴于每个教程都建议创建一个新的模型版本,有人可以告诉我是否错过了我的方法会导致崩溃的某些场景?
为什么在运行以下代码时出现此错误?:
“内部错误”(1/1000);“未收到资产的authToken”
我认为这与setObject最后一行中的代码有关。
let documentsDirectoryPath:NSString = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
var imageURL: URL!
let imageData = UIImageJPEGRepresentation(self.newImage, 1.0)
let path:String = documentsDirectoryPath.appendingPathComponent(self.newImage.description)
try? UIImageJPEGRepresentation(self.newImage, 1.0)!.write(to: URL(fileURLWithPath: path), options: [.atomicWrite])
imageURL = URL(fileURLWithPath: path)
try? imageData?.write(to: imageURL, options: [.atomicWrite])
let imageAsset:CKAsset? = CKAsset(fileURL: URL(fileURLWithPath: path))
curImages = record["Images"] as! [CKAsset]
curImages.append(imageAsset!)
print("saving image")
record.setObject(curImages as CKRecordValue?, forKey: "Images")
Run Code Online (Sandbox Code Playgroud) 我刚刚关注了CoreData的教程,遇到了一个问题.首先myApp崩溃,因为我没有正确命名数据库(如教程中所示),通过调试器找到了.但是现在我的程序执行得很好,但是会抛出以下错误:
Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed
Run Code Online (Sandbox Code Playgroud)
这是在以下方法中:
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
/*
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 persistent store is not accessible;
* The schema for the persistent store is incompatible …Run Code Online (Sandbox Code Playgroud)