CoreDataModel
public struct CoreDataModel
extension CoreDataModel: Equatable
An instance of CoreDataModel represents a Core Data model — a .xcdatamodeld file package.
It provides the model and store URLs as well as methods for interacting with the store.
-
The name of the Core Data model resource.
Declaration
Swift
public let name: String -
The bundle in which the model is located. The default is the main bundle.
Declaration
Swift
public let bundle: Bundle -
The type of the Core Data persistent store for the model. The default is
.sqlitewith the user’s documents directory.Declaration
Swift
public let storeType: StoreType -
The file URL specifying the full path to the store.
Note
If the store is in-memory, then this value will benil.Declaration
Swift
public var storeURL: URL? { get } -
The file URL specifying the model file in the bundle specified by
bundle.Declaration
Swift
public var modelURL: URL { get } -
The database file name for the store.
Declaration
Swift
public var databaseFileName: String { get } -
The managed object model for the model specified by
name.Declaration
Swift
public var managedObjectModel: NSManagedObjectModel { get } -
Queries the meta data for the persistent store specified by the receiver and returns whether or not a migration is needed.
Declaration
Swift
public var needsMigration: Bool { get }Return Value
trueif the store requires a migration,falseotherwise.
-
Constructs a new
CoreDataModelinstance with the specified name and bundle.Declaration
Swift
public init(name: String, bundle: Bundle = .main, storeType: StoreType = .sqlite(defaultDirectoryURL()))Parameters
nameThe name of the Core Data model.
bundleThe bundle in which the model is located. The default is the main bundle.
storeTypeThe store type for the Core Data model. The default is
.sqlitewith the user’s documents directory.Return Value
A new
CoreDataModelinstance.
-
The default directory used to initialize a
CoreDataModel. On tvOS, this is the caches directory. All other platforms use the document directory.Declaration
Swift
public static func defaultDirectoryURL() -> URL -
Removes the existing model store specfied by the receiver.
Throws
If removing the store fails or errors, then this function throws anNSError.Declaration
Swift
public func removeExistingStore() throws -
Progressively migrates the persistent store of the
CoreDataModelbased on mapping models found in the model’s bundle. If the model returns false fromneedsMigration, then this function does nothing.Throws
If an error occurs, either an
NSErroror aMigrationErroris thrown. If anNSErroris thrown, it could specify any of the following: an error checking persistent store metadata, an error fromNSMigrationManager, or an error fromNSFileManager.Warning
Migration is only supported for on-disk persistent stores. A complete ‘path’ of mapping models must exist between the peristent store’s version and the model’s version.
Declaration
Swift
public func migrate() throws
View on GitHub
CoreDataModel Structure Reference