mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-16 05:56:50 +01:00
WIP: objective C storages
This commit is contained in:
@@ -149,10 +149,6 @@
|
||||
B546F95E1C9A12B800D5AC55 /* CSSQliteStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F95C1C9A12B800D5AC55 /* CSSQliteStore.swift */; };
|
||||
B546F95F1C9A12B800D5AC55 /* CSSQliteStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F95C1C9A12B800D5AC55 /* CSSQliteStore.swift */; };
|
||||
B546F9601C9A12B800D5AC55 /* CSSQliteStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F95C1C9A12B800D5AC55 /* CSSQliteStore.swift */; };
|
||||
B546F9641C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9631C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift */; };
|
||||
B546F9651C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9631C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift */; };
|
||||
B546F9661C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9631C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift */; };
|
||||
B546F9671C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9631C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift */; };
|
||||
B546F9691C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */; };
|
||||
B546F96A1C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */; };
|
||||
B546F96B1C9AF26D00D5AC55 /* CSInMemoryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */; };
|
||||
@@ -377,7 +373,6 @@
|
||||
B52DD17D1BE1F8CC00949AFE /* CoreStoreTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CoreStoreTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B546F9571C99B17400D5AC55 /* CSCoreStore+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CSCoreStore+Setup.swift"; sourceTree = "<group>"; };
|
||||
B546F95C1C9A12B800D5AC55 /* CSSQliteStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSSQliteStore.swift; sourceTree = "<group>"; };
|
||||
B546F9631C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSLegacySQLiteStore.swift; sourceTree = "<group>"; };
|
||||
B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSInMemoryStore.swift; sourceTree = "<group>"; };
|
||||
B546F96D1C9B14AC00D5AC55 /* CSStorageInterface.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSStorageInterface.swift; sourceTree = "<group>"; };
|
||||
B54A6A541BA15F2A007870FD /* FetchedResultsControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedResultsControllerDelegate.swift; sourceTree = "<group>"; };
|
||||
@@ -658,7 +653,6 @@
|
||||
B546F96D1C9B14AC00D5AC55 /* CSStorageInterface.swift */,
|
||||
B546F9681C9AF26D00D5AC55 /* CSInMemoryStore.swift */,
|
||||
B546F95C1C9A12B800D5AC55 /* CSSQliteStore.swift */,
|
||||
B546F9631C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift */,
|
||||
);
|
||||
name = StorageInterfaces;
|
||||
sourceTree = "<group>";
|
||||
@@ -1132,7 +1126,6 @@
|
||||
B5E84F251AFF84860064E85B /* ObjectObserver.swift in Sources */,
|
||||
B5E84F2F1AFF849C0064E85B /* NotificationObserver.swift in Sources */,
|
||||
B5F1DA8D1B9AA97D007C5CBB /* ImportableObject.swift in Sources */,
|
||||
B546F9641C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift in Sources */,
|
||||
B56965241B356B820075EE4A /* MigrationResult.swift in Sources */,
|
||||
B5FE4DAC1C85D44E00FA6A91 /* SQLiteStore.swift in Sources */,
|
||||
2F291E2719C6D3CF007AF63F /* CoreStore.swift in Sources */,
|
||||
@@ -1226,7 +1219,6 @@
|
||||
82BA18BC1C4BBD4A00A0916E /* OrderBy.swift in Sources */,
|
||||
82BA18B01C4BBD3100A0916E /* NSManagedObject+Transaction.swift in Sources */,
|
||||
82BA18D41C4BBD7100A0916E /* NSManagedObjectContext+Querying.swift in Sources */,
|
||||
B546F9651C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift in Sources */,
|
||||
82BA18D51C4BBD7100A0916E /* NSManagedObjectContext+Setup.swift in Sources */,
|
||||
B5FE4DA31C8481E100FA6A91 /* StorageInterface.swift in Sources */,
|
||||
82BA18C91C4BBD5900A0916E /* MigrationType.swift in Sources */,
|
||||
@@ -1329,7 +1321,6 @@
|
||||
B52DD1CA1BE1F94600949AFE /* NSManagedObjectModel+Setup.swift in Sources */,
|
||||
B52DD1A41BE1F92F00949AFE /* ImportableObject.swift in Sources */,
|
||||
B52DD1AE1BE1F93900949AFE /* OrderBy.swift in Sources */,
|
||||
B546F9671C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift in Sources */,
|
||||
B52DD1BA1BE1F94000949AFE /* MigrationChain.swift in Sources */,
|
||||
B50392FB1C479640009900CA /* NSManagedObject+Transaction.swift in Sources */,
|
||||
B52DD1A31BE1F92C00949AFE /* SaveResult.swift in Sources */,
|
||||
@@ -1403,7 +1394,6 @@
|
||||
B56321AB1BD6521C006C9394 /* FetchedResultsControllerDelegate.swift in Sources */,
|
||||
B56321821BD65216006C9394 /* SetupResult.swift in Sources */,
|
||||
B563219C1BD65216006C9394 /* SectionBy.swift in Sources */,
|
||||
B546F9661C9AEFBA00D5AC55 /* CSLegacySQLiteStore.swift in Sources */,
|
||||
B56321B21BD6521C006C9394 /* NSManagedObjectContext+Querying.swift in Sources */,
|
||||
B5FE4DA41C8481E100FA6A91 /* StorageInterface.swift in Sources */,
|
||||
B56321B31BD6521C006C9394 /* NSManagedObjectContext+Setup.swift in Sources */,
|
||||
|
||||
@@ -31,25 +31,46 @@
|
||||
|
||||
@implementation BridgingTests
|
||||
|
||||
- (void)testFlags {
|
||||
|
||||
XCTAssertEqual([CSLocalStorageOptions none], 0);
|
||||
XCTAssertEqual([CSLocalStorageOptions recreateStoreOnModelMismatch], 1);
|
||||
XCTAssertEqual([CSLocalStorageOptions preventProgressiveMigration], 2);
|
||||
XCTAssertEqual([CSLocalStorageOptions allowSynchronousLightweightMigration], 4);
|
||||
}
|
||||
|
||||
- (void)testDataStack {
|
||||
|
||||
CSDataStack *dataStack = [[CSDataStack alloc]
|
||||
initWithModelName: @"Model"
|
||||
bundle: [NSBundle bundleForClass:[self class]]
|
||||
versionChain: nil];
|
||||
initWithModelName:@"Model"
|
||||
bundle:[NSBundle bundleForClass:[self class]]
|
||||
versionChain:nil];
|
||||
XCTAssertNotNil(dataStack);
|
||||
|
||||
[CSCoreStore setDefaultStack:dataStack];
|
||||
XCTAssertTrue([dataStack isEqual:[CSCoreStore defaultStack]]);
|
||||
|
||||
CSInMemoryStore *storage = [CSCoreStore
|
||||
addStorageAndWait:[CSInMemoryStore new]
|
||||
error:nil];
|
||||
XCTAssertNotNil(storage);
|
||||
XCTAssertEqual([[storage class] storeType], [CSInMemoryStore storeType]);
|
||||
XCTAssertEqual([[storage class] storeType], NSInMemoryStoreType);
|
||||
XCTAssertNil(storage.configuration);
|
||||
XCTAssertNil(storage.storeOptions);
|
||||
NSError *memoryError;
|
||||
CSInMemoryStore *memoryStorage = [CSCoreStore
|
||||
addInMemoryStorageAndWait:[CSInMemoryStore new]
|
||||
error:&memoryError];
|
||||
XCTAssertNotNil(memoryStorage);
|
||||
XCTAssertEqualObjects([[memoryStorage class] storeType], [CSInMemoryStore storeType]);
|
||||
XCTAssertEqualObjects([[memoryStorage class] storeType], NSInMemoryStoreType);
|
||||
XCTAssertNil(memoryStorage.configuration);
|
||||
XCTAssertNil(memoryStorage.storeOptions);
|
||||
XCTAssertNil(memoryError);
|
||||
|
||||
NSError *sqliteError;
|
||||
CSSQLiteStore *sqliteStorage = [CSCoreStore
|
||||
addSQLiteStorageAndWait:[CSSQLiteStore new]
|
||||
error:&sqliteError];
|
||||
XCTAssertNotNil(sqliteStorage);
|
||||
XCTAssertEqualObjects([[sqliteStorage class] storeType], [CSSQLiteStore storeType]);
|
||||
XCTAssertEqualObjects([[sqliteStorage class] storeType], NSSQLiteStoreType);
|
||||
XCTAssertNil(sqliteStorage.configuration);
|
||||
XCTAssertEqualObjects(sqliteStorage.storeOptions, @{ NSSQLitePragmasOption: @{ @"journal_mode": @"WAL" } });
|
||||
XCTAssertNil(sqliteError);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -23,7 +23,7 @@ public extension CSCoreStore {
|
||||
Returns the entity name-to-class type mapping from the `defaultStack`'s model.
|
||||
*/
|
||||
@objc
|
||||
public static var entityTypesByName: [String: NSManagedObject.Type] {
|
||||
public static var entityClassesByName: [String: NSManagedObject.Type] {
|
||||
|
||||
return CoreStore.defaultStack.entityTypesByName
|
||||
}
|
||||
@@ -32,69 +32,72 @@ public extension CSCoreStore {
|
||||
Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass from `defaultStack`'s model.
|
||||
*/
|
||||
@objc
|
||||
public static func entityDescriptionForType(type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
public static func entityDescriptionForClass(type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
|
||||
return CoreStore.defaultStack.entityDescriptionForType(type)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates an `CSSQLiteStore` with default parameters and adds it to the `defaultStack`. This method blocks until completion.
|
||||
Creates an `CSInMemoryStore` with default parameters and adds it to the `defaultStack`. This method blocks until completion.
|
||||
```
|
||||
CSSQLiteStore *storage = [CSCoreStore addStorageAndWaitAndReturnError:&error];
|
||||
CSSQLiteStore *storage = [CSCoreStore addInMemoryStorageAndWaitAndReturnError:&error];
|
||||
```
|
||||
|
||||
- returns: the local SQLite storage added to the `defaultStack`
|
||||
- returns: the `CSInMemoryStore` added to the `defaultStack`
|
||||
*/
|
||||
@objc
|
||||
public static func addStorageAndWait() throws -> CSSQLiteStore {
|
||||
public static func addInMemoryStorageAndWait() throws -> CSInMemoryStore {
|
||||
|
||||
return try CoreStore.defaultStack.addStorageAndWait(InMemoryStore).objc
|
||||
}
|
||||
|
||||
/**
|
||||
Creates an `CSSQLiteStore` with default parameters and adds it to the `defaultStack`. This method blocks until completion.
|
||||
```
|
||||
CSSQLiteStore *storage = [CSCoreStore addSQLiteStorageAndWaitAndReturnError:&error];
|
||||
```
|
||||
|
||||
- returns: the `CSSQLiteStore` added to the `defaultStack`
|
||||
*/
|
||||
@objc
|
||||
public static func addSQLiteStorageAndWait() throws -> CSSQLiteStore {
|
||||
|
||||
return try CoreStore.defaultStack.addStorageAndWait(SQLiteStore).objc
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a `StorageInterface` to the `defaultStack` and blocks until completion.
|
||||
Adds a `CSInMemoryStore` to the `defaultStack` and blocks until completion.
|
||||
```
|
||||
CSInMemoryStore *storage = [CoreStore
|
||||
addStorageAndWait: [[InMemoryStore alloc] initWithConfiguration: @"Config1"]
|
||||
NSError *error;
|
||||
CSInMemoryStore *storage = [CSCoreStore
|
||||
addStorageAndWait: [[CSInMemoryStore alloc] initWithConfiguration: @"Config1"]
|
||||
error: &error];
|
||||
```
|
||||
|
||||
- parameter storage: the `StorageInterface`
|
||||
- returns: the `StorageInterface` added to the `defaultStack`
|
||||
- parameter storage: the `CSInMemoryStore`
|
||||
- returns: the `CSInMemoryStore` added to the `defaultStack`
|
||||
*/
|
||||
@objc
|
||||
public static func addStorageAndWait(storage: CSInMemoryStore) throws -> CSInMemoryStore {
|
||||
public static func addInMemoryStorageAndWait(storage: CSInMemoryStore) throws -> CSInMemoryStore {
|
||||
|
||||
return try CoreStore.defaultStack.addStorageAndWait(storage.swift).objc
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `LocalStorageface` of the specified store type with default values and adds it to the `defaultStack`. This method blocks until completion.
|
||||
Adds a `CSSQLiteStore` to the `defaultStack` and blocks until completion.
|
||||
```
|
||||
try CoreStore.addStorageAndWait(SQLiteStore)
|
||||
NSError *error;
|
||||
CSSQLiteStore *storage = [CSCoreStore
|
||||
addStorageAndWait: [[CSSQLiteStore alloc] initWithConfiguration: @"Config1"]
|
||||
error: &error];
|
||||
```
|
||||
|
||||
- parameter storeType: the `LocalStorageface` type
|
||||
- returns: the local storage added to the `defaultStack`
|
||||
- parameter storage: the `CSSQLiteStore`
|
||||
- returns: the `CSSQLiteStore` added to the `defaultStack`
|
||||
*/
|
||||
// @objc
|
||||
// public static func addStorageAndWait<T: LocalStorage where T: DefaultInitializableStore>(storageType: T.Type) throws -> T {
|
||||
//
|
||||
// return try self.defaultStack.swift.addStorageAndWait(storageType.init())
|
||||
// }
|
||||
|
||||
/**
|
||||
Adds a `LocalStorage` to the `defaultStack` and blocks until completion.
|
||||
```
|
||||
try CoreStore.addStorageAndWait(SQLiteStore(configuration: "Config1"))
|
||||
```
|
||||
|
||||
- parameter storage: the local storage
|
||||
- returns: the local storage added to the `defaultStack`. Note that this may not always be the same instance as the parameter argument if a previous `LocalStorage` was already added at the same URL and with the same configuration.
|
||||
*/
|
||||
// @objc
|
||||
// public static func addStorageAndWait<T: LocalStorage>(storage: T) throws -> T {
|
||||
//
|
||||
// return try self.defaultStack.swift.addStorageAndWait(storage)
|
||||
// }
|
||||
@objc
|
||||
public static func addSQLiteStorageAndWait(storage: CSSQLiteStore) throws -> CSSQLiteStore {
|
||||
|
||||
return try CoreStore.defaultStack.addStorageAndWait(storage.swift).objc
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,97 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the stack's model version. The version string is the same as the name of the version-specific .xcdatamodeld file.
|
||||
*/
|
||||
@objc
|
||||
public var modelVersion: String {
|
||||
|
||||
return self.swift.modelVersion
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the entity name-to-class type mapping from the stack's model.
|
||||
*/
|
||||
@objc
|
||||
public var entityClassesByName: [String: NSManagedObject.Type] {
|
||||
|
||||
return self.swift.entityTypesByName
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass from stack's model.
|
||||
*/
|
||||
@objc
|
||||
public func entityDescriptionForClass(type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
|
||||
return self.swift.entityDescriptionForType(type)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates an `CSInMemoryStore` with default parameters and adds it to the stack. This method blocks until completion.
|
||||
```
|
||||
CSSQLiteStore *storage = [dataStack addInMemoryStorageAndWaitAndReturnError:&error];
|
||||
```
|
||||
|
||||
- returns: the `CSInMemoryStore` added to the stack
|
||||
*/
|
||||
@objc
|
||||
public func addInMemoryStorageAndWait() throws -> CSInMemoryStore {
|
||||
|
||||
return try self.swift.addStorageAndWait(InMemoryStore).objc
|
||||
}
|
||||
|
||||
/**
|
||||
Creates an `CSSQLiteStore` with default parameters and adds it to the stack. This method blocks until completion.
|
||||
```
|
||||
CSSQLiteStore *storage = [dataStack addSQLiteStorageAndWaitAndReturnError:&error];
|
||||
```
|
||||
|
||||
- returns: the `CSSQLiteStore` added to the stack
|
||||
*/
|
||||
@objc
|
||||
public func addSQLiteStorageAndWait() throws -> CSSQLiteStore {
|
||||
|
||||
return try self.swift.addStorageAndWait(SQLiteStore).objc
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a `CSInMemoryStore` to the stack and blocks until completion.
|
||||
```
|
||||
NSError *error;
|
||||
CSInMemoryStore *storage = [dataStack
|
||||
addStorageAndWait: [[CSInMemoryStore alloc] initWithConfiguration: @"Config1"]
|
||||
error: &error];
|
||||
```
|
||||
|
||||
- parameter storage: the `CSInMemoryStore`
|
||||
- returns: the `CSInMemoryStore` added to the stack
|
||||
*/
|
||||
@objc
|
||||
public func addInMemoryStorageAndWait(storage: CSInMemoryStore) throws -> CSInMemoryStore {
|
||||
|
||||
return try self.swift.addStorageAndWait(storage.swift).objc
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a `CSSQLiteStore` to the stack and blocks until completion.
|
||||
```
|
||||
NSError *error;
|
||||
CSSQLiteStore *storage = [dataStack
|
||||
addStorageAndWait: [[CSSQLiteStore alloc] initWithConfiguration: @"Config1"]
|
||||
error: &error];
|
||||
```
|
||||
|
||||
- parameter storage: the `CSSQLiteStore`
|
||||
- returns: the `CSSQLiteStore` added to the stack
|
||||
*/
|
||||
@objc
|
||||
public func addSQLiteStorageAndWait(storage: CSSQLiteStore) throws -> CSSQLiteStore {
|
||||
|
||||
return try self.swift.addStorageAndWait(storage.swift).objc
|
||||
}
|
||||
|
||||
|
||||
// MARK: NSObject
|
||||
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
//
|
||||
// CSLegacySQLiteStore.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2016 John Rommel Estropia
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
|
||||
// MARK: - LegacySQLiteStore
|
||||
|
||||
extension LegacySQLiteStore: CoreStoreBridgeable {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
|
||||
public typealias ObjCType = CSLegacySQLiteStore
|
||||
}
|
||||
|
||||
|
||||
// MARK: - CSSQLiteStore
|
||||
|
||||
/**
|
||||
The `CSLegacySQLiteStore` serves as the Objective-C bridging type for `LegacySQLiteStore`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSLegacySQLiteStore: NSObject, CoreStoreBridge {
|
||||
|
||||
|
||||
|
||||
// MARK: NSObject
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return ObjectIdentifier(self.swift).hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
|
||||
guard let object = object as? CSLegacySQLiteStore else {
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift === object.swift
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
|
||||
public let swift: LegacySQLiteStore
|
||||
|
||||
public required init(_ swiftObject: LegacySQLiteStore) {
|
||||
|
||||
self.swift = swiftObject
|
||||
}
|
||||
}
|
||||
@@ -51,17 +51,17 @@ public final class CSSQLiteStore: NSObject, CoreStoreBridge {
|
||||
- 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 localStorageOptions: When the `CSSQLiteStore` is passed to the `CSDataStack`'s `addStorage()` methods, tells the `CSDataStack` how to setup the persistent store. Defaults to `.None`.
|
||||
- parameter localStorageOptions: When the `CSSQLiteStore` is passed to the `CSDataStack`'s `addStorage()` methods, tells the `CSDataStack` how to setup the persistent store. Defaults to `[CSLocalStorageOptions none]`.
|
||||
*/
|
||||
@objc
|
||||
public convenience init(fileURL: NSURL, configuration: String?, mappingModelBundles: [NSBundle]?, localStorageOptions: CSLocalStorageOptions) {
|
||||
public convenience init(fileURL: NSURL, configuration: String?, mappingModelBundles: [NSBundle]?, localStorageOptions: Int) {
|
||||
|
||||
self.init(
|
||||
SQLiteStore(
|
||||
fileURL: fileURL,
|
||||
configuration: configuration,
|
||||
mappingModelBundles: mappingModelBundles ?? NSBundle.allBundles(),
|
||||
localStorageOptions: LocalStorageOptions(rawValue: localStorageOptions.rawValue)
|
||||
localStorageOptions: LocalStorageOptions(rawValue: localStorageOptions)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -73,17 +73,17 @@ public final class CSSQLiteStore: NSObject, CoreStoreBridge {
|
||||
- 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 mappingModelBundles: a list of `NSBundle`s from which to search mapping models for migration
|
||||
- parameter localStorageOptions: When the `CSSQLiteStore` is passed to the `CSDataStack`'s `addStorage()` methods, tells the `CSDataStack` how to setup the persistent store. Defaults to `.None`.
|
||||
- parameter localStorageOptions: When the `CSSQLiteStore` is passed to the `CSDataStack`'s `addStorage()` methods, tells the `CSDataStack` how to setup the persistent store. Defaults to `[CSLocalStorageOptions none]`.
|
||||
*/
|
||||
@objc
|
||||
public convenience init(fileName: String, configuration: String?, mappingModelBundles: [NSBundle]?, localStorageOptions: CSLocalStorageOptions) {
|
||||
public convenience init(fileName: String, configuration: String?, mappingModelBundles: [NSBundle]?, localStorageOptions: Int) {
|
||||
|
||||
self.init(
|
||||
SQLiteStore(
|
||||
fileName: fileName,
|
||||
configuration: configuration,
|
||||
mappingModelBundles: mappingModelBundles ?? NSBundle.allBundles(),
|
||||
localStorageOptions: LocalStorageOptions(rawValue: localStorageOptions.rawValue)
|
||||
localStorageOptions: LocalStorageOptions(rawValue: localStorageOptions)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -123,10 +123,9 @@ public final class CSSQLiteStore: NSObject, CoreStoreBridge {
|
||||
Options that tell the `CSDataStack` how to setup the persistent store
|
||||
*/
|
||||
@objc
|
||||
public var localStorageOptions: CSLocalStorageOptions {
|
||||
public var localStorageOptions: Int {
|
||||
|
||||
// TODO: allow options
|
||||
return CSLocalStorageOptions(rawValue: self.swift.localStorageOptions.rawValue) ?? .None
|
||||
return self.swift.localStorageOptions.rawValue
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,27 +40,39 @@ public protocol CSStorageInterface {
|
||||
The `CSLocalStorageOptions` provides settings that tells the `CSDataStack` how to setup the persistent store for `CSLocalStorage` implementers.
|
||||
*/
|
||||
@objc
|
||||
public enum CSLocalStorageOptions: Int {
|
||||
public final class CSLocalStorageOptions: NSObject {
|
||||
|
||||
/**
|
||||
Tells the `DataStack` that the store should not be migrated or recreated, and should simply fail on model mismatch
|
||||
*/
|
||||
case None = 0
|
||||
@objc
|
||||
public static let none = 0
|
||||
|
||||
/**
|
||||
Tells the `DataStack` to delete and recreate the store on model mismatch, otherwise exceptions will be thrown on failure instead
|
||||
*/
|
||||
case RecreateStoreOnModelMismatch = 1
|
||||
@objc
|
||||
public static let recreateStoreOnModelMismatch = 1
|
||||
|
||||
/**
|
||||
Tells the `DataStack` to prevent progressive migrations for the store
|
||||
*/
|
||||
case PreventProgressiveMigration = 2
|
||||
@objc
|
||||
public static let preventProgressiveMigration = 2
|
||||
|
||||
/**
|
||||
Tells the `DataStack` to allow lightweight migration for the store when added synchronously
|
||||
*/
|
||||
case AllowSynchronousLightweightMigration = 4
|
||||
@objc
|
||||
public static let allowSynchronousLightweightMigration = 4
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private override init() {
|
||||
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +100,7 @@ public protocol CSLocalStorage: CSStorageInterface {
|
||||
Options that tell the `DataStack` how to setup the persistent store
|
||||
*/
|
||||
@objc
|
||||
var localStorageOptions: CSLocalStorageOptions { get }
|
||||
var localStorageOptions: Int { get }
|
||||
|
||||
/**
|
||||
Called by the `CSDataStack` 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)
|
||||
|
||||
Reference in New Issue
Block a user