2017-09-05 11 views
0

NSPersistentContainerを作成してデータを保存していますが、コンテキスト上でsave()を呼び出すとデータベースファイルが作成されません。NSPersistentContainerはデータベースファイルを作成しません

私はあるNSPersistentContainerを作成するために使用していたコード:私はNSPersistentStoreDescription経由で自動移行オプションを設定すると問題になると、コンテナはデフォルトのストア・ファイル・パスを使用することwouldntのことを期待していた

let container = NSPersistentContainer(name: "Model") 

let description = NSPersistentStoreDescription() 
description.shouldInferMappingModelAutomatically = true 
description.shouldMigrateStoreAutomatically = true 

container.persistentStoreDescriptions = [description] 

container.loadPersistentStores { ... } 

答えて

0

。しかし、それwasnt。

1は、問題を修正し、独自の道を、提供しなければならないので、そのデフォルトのパスへのフォールバックはありませんが判明:

let container = NSPersistentContainer(name: "Model") 

let dbURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent("DB.sql") 
let description = NSPersistentStoreDescription(url: dbURL) 
description.shouldInferMappingModelAutomatically = true 
description.shouldMigrateStoreAutomatically = true 

container.persistentStoreDescriptions = [description] 

container.loadPersistentStores { ... } 
関連する問題