WIP: documentation

This commit is contained in:
John Rommel Estropia
2016-03-12 00:16:54 +09:00
parent fa947faa57
commit 4ff7b2d6d9
4 changed files with 112 additions and 21 deletions

View File

@@ -28,8 +28,16 @@ import CoreData
// MARK: - InMemoryStore
/**
A storage interface that is backed only by memory.
*/
public class InMemoryStore: StorageInterface, DefaultInitializableStore {
/**
Initializes an `InMemoryStore` for the specified configuration
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`, the "Default" configuration.
*/
public required init(configuration: String?) {
self.configuration = configuration
@@ -38,6 +46,9 @@ public class InMemoryStore: StorageInterface, DefaultInitializableStore {
// MARK: DefaultInitializableStore
/**
Initializes an `InMemoryStore` with the "Default" configuration
*/
public required init() {
self.configuration = nil
@@ -45,16 +56,19 @@ public class InMemoryStore: StorageInterface, DefaultInitializableStore {
// MARK: StorageInterface
/**
The string identifier for the `NSPersistentStore`'s `type` property. For `InMemoryStore`s, this is always set to `NSInMemoryStoreType`.
*/
public static let storeType = NSInMemoryStoreType
public static func validateStoreURL(storeURL: NSURL?) -> Bool {
return storeURL == nil
}
/**
The configuration name in the model file
*/
public let configuration: String?
public let storeOptions: [String: AnyObject]? = nil
public var internalStore: NSPersistentStore?
/**
The options dictionary for the `NSPersistentStore`. For `InMemoryStore`s, this is always set to `nil`.
*/
public let storeOptions: [String: AnyObject]? = nil
}

View File

@@ -28,8 +28,20 @@ import Foundation
// MARK: - LegacySQLiteStore
/**
A storage interface backed by an SQLite database that was created before CoreStore 2.0.0.
- Warning: The default SQLite file location for the `LegacySQLiteStore` and `SQLiteStore` are different. If the app was depending on CoreStore's default directories prior to 2.0.0, make sure to use `LegacySQLiteStore` instead of `SQLiteStore`.
*/
public final class LegacySQLiteStore: SQLiteStore {
/**
Initializes an SQLite store interface from the given SQLite file URL. When this instance is passed to the `DataStack`'s `addStorage()` methods, a new SQLite file will be created if it does not exist.
- parameter fileURL: the local file URL for the target SQLite persistent store. Note that if you have multiple configurations, you will need to specify a different `fileURL` explicitly for each of them.
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`, the "Default" configuration. Note that if you have multiple configurations, you will need to specify a different `fileURL` explicitly for each of them.
- parameter mappingModelBundles: a list of `NSBundle`s from which to search mapping models for migration.
- parameter resetStoreOnModelMismatch: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, a `true` value tells the `DataStack` to delete the store on model mismatch; a `false` value lets exceptions be thrown on failure instead. Typically should only be set to true when debugging, or if the persistent store can be recreated easily. If not specified, defaults to `false`.
*/
public required init(fileURL: NSURL, configuration: String? = nil, mappingModelBundles: [NSBundle] = NSBundle.allBundles(), resetStoreOnModelMismatch: Bool = false) {
super.init(

View File

@@ -28,14 +28,19 @@ import CoreData
// MARK: - SQLiteStore
/**
A storage interface that is backed by an SQLite database.
- Warning: The default SQLite file location for the `LegacySQLiteStore` and `SQLiteStore` are different. If the app was depending on CoreStore's default directories prior to 2.0.0, make sure to use `LegacySQLiteStore` instead of `SQLiteStore`.
*/
public class SQLiteStore: LocalStorage, DefaultInitializableStore {
/**
Initializes an SQLite store interface from the given SQLite file URL. When this instance is passed to the `DataStack`'s `addStorage()` methods, a new SQLite file will be created if it does not exist.
- parameter fileURL: the local file URL for the target SQLite persistent store. If not specified, defaults to a file URL pointing to a "<Application name>.sqlite" file in the "Application Support/<bundle id>" directory (or the "Caches/<bundle id>" directory on tvOS). Note that if you have multiple configurations, you will need to specify a different `fileURL` explicitly for each of them.
- parameter fileURL: the local file URL for the target SQLite persistent store. Note that if you have multiple configurations, you will need to specify a different `fileURL` explicitly for each of them.
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`, the "Default" configuration. Note that if you have multiple configurations, you will need to specify a different `fileURL` explicitly for each of them.
- parameter resetStoreOnModelMismatch: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, a true value tells the `DataStack` to delete the store on model mismatch; a false value lets exceptions be thrown on failure instead. Typically should only be set to true when debugging, or if the persistent store can be recreated easily. If not specified, defaults to false.
- parameter mappingModelBundles: a list of `NSBundle`s from which to search mapping models for migration.
- parameter resetStoreOnModelMismatch: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, a `true` value tells the `DataStack` to delete the store on model mismatch; a `false` value lets exceptions be thrown on failure instead. Typically should only be set to true when debugging, or if the persistent store can be recreated easily. If not specified, defaults to `false`.
*/
public required init(fileURL: NSURL, configuration: String? = nil, mappingModelBundles: [NSBundle] = NSBundle.allBundles(), resetStoreOnModelMismatch: Bool = false) {
@@ -47,10 +52,12 @@ public class SQLiteStore: LocalStorage, DefaultInitializableStore {
/**
Initializes an SQLite store interface from the given SQLite file name. When this instance is passed to the `DataStack`'s `addStorage()` methods, a new SQLite file will be created if it does not exist.
- Warning: The default SQLite file location for the `LegacySQLiteStore` and `SQLiteStore` are different. If the app was depending on CoreStore's default directories prior to 2.0.0, make sure to use `LegacySQLiteStore` instead of `SQLiteStore`.
- parameter fileName: the local filename for the SQLite persistent store in the "Application Support/<bundle id>" directory (or the "Caches/<bundle id>" directory on tvOS). Note that if you have multiple configurations, you will need to specify a different `fileName` explicitly for each of them.
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`, the "Default" configuration. Note that if you have multiple configurations, you will need to specify a different `fileName` explicitly for each of them.
- parameter resetStoreOnModelMismatch: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, a true value tells the `DataStack` to delete the store on model mismatch; a false value lets exceptions be thrown on failure instead. Typically should only be set to true when debugging, or if the persistent store can be recreated easily. If not specified, defaults to false.
- parameter mappingModelBundles: a list of `NSBundle`s from which to search mapping models for migration
- parameter resetStoreOnModelMismatch: When the `SQLiteStore` is passed to the `DataStack`'s `addStorage()` methods, a `true` value tells the `DataStack` to delete the store on model mismatch; a `false` value lets exceptions be thrown on failure instead. Typically should only be set to true when debugging, or if the persistent store can be recreated easily. If not specified, defaults to `false`.
*/
public required init(fileName: String, configuration: String? = nil, mappingModelBundles: [NSBundle] = NSBundle.allBundles(), resetStoreOnModelMismatch: Bool = false) {
@@ -64,6 +71,9 @@ public class SQLiteStore: LocalStorage, DefaultInitializableStore {
// MARK: DefaultInitializableStore
/**
Initializes an `SQLiteStore` with an all-default settings: a `fileURL` pointing to a "<Application name>.sqlite" file in the "Application Support/<bundle id>" directory (or the "Caches/<bundle id>" directory on tvOS), a `nil` `configuration` pertaining to the "Default" configuration, a `mappingModelBundles` set to search all `NSBundle`s, and `resetStoreOnModelMismatch` disabled.
*/
public required init() {
self.fileURL = SQLiteStore.defaultFileURL
@@ -75,26 +85,45 @@ public class SQLiteStore: LocalStorage, DefaultInitializableStore {
// MAKR: LocalStorage
/**
The `NSURL` that points to the SQLite file
*/
public let fileURL: NSURL
/**
The `NSBundle`s from which to search mapping models for migrations
*/
public let mappingModelBundles: [NSBundle]
/**
When `true`, tells the `DataStack` to delete and recreate the store on model mismatch, otherwise exceptions will be thrown on failure instead.
*/
public let resetStoreOnModelMismatch: Bool
// MARK: StorageInterface
/**
The string identifier for the `NSPersistentStore`'s `type` property. For `SQLiteStore`s, this is always set to `NSSQLiteStoreType`.
*/
public static let storeType = NSSQLiteStoreType
public static func validateStoreURL(storeURL: NSURL?) -> Bool {
return storeURL?.fileURL == true
}
/**
The configuration name in the model file
*/
public let configuration: String?
/**
The options dictionary for the `NSPersistentStore`. For `SQLiteStore`s, this is always set to
```
[NSSQLitePragmasOption: ["journal_mode": "WAL"]]
```
*/
public let storeOptions: [String: AnyObject]? = [NSSQLitePragmasOption: ["journal_mode": "WAL"]]
public let mappingModelBundles: [NSBundle]
public var internalStore: NSPersistentStore?
/**
Called by the `DataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
*/
public func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel) throws {
// TODO: check if attached to persistent store

View File

@@ -28,31 +28,67 @@ import CoreData
// MARK: - StorageInterface
/**
The `StorageInterface` represents the data store managed (or to be managed) by the `DataStack`. When added to the `DataStack`, the `StorageInterface` serves as the interface for the `NSPersistentStore`. This may be a database file, an in-memory store, etc.
*/
public protocol StorageInterface: class {
/**
The string identifier for the `NSPersistentStore`'s `type` property. This is the same string CoreStore will use to create the `NSPersistentStore` from the `NSPersistentStoreCoordinator`'s `addPersistentStoreWithType(...)` method.
*/
static var storeType: String { get }
/**
The configuration name in the model file
*/
var configuration: String? { get }
/**
The options dictionary for the `NSPersistentStore`
*/
var storeOptions: [String: AnyObject]? { get }
}
// MARK: - DefaultInitializableStore
/**
The `DefaultInitializableStore` represents `StorageInterface`s that can be initialized with default values
*/
public protocol DefaultInitializableStore: StorageInterface {
/**
Initializes the `StorageInterface` with the default configurations
*/
init()
}
// MARK: - LocalStorage
/**
The `LocalStorage` represents `StorageInterface`s that are backed by local files.
*/
public protocol LocalStorage: StorageInterface {
/**
The `NSURL` that points to the store file
*/
var fileURL: NSURL { get }
/**
The `NSBundle`s from which to search mapping models for migrations
*/
var mappingModelBundles: [NSBundle] { get }
/**
When `true`, tells the `DataStack` to delete and recreate the store on model mismatch, otherwise exceptions will be thrown on failure instead.
*/
var resetStoreOnModelMismatch: Bool { get }
/**
Called by the `DataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. Implementers can use the `sourceModel` to perform necessary store operations. (SQLite stores for example, can convert WAL journaling mode to DELETE before deleting)
*/
func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel) throws
}