mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-20 08:34:23 +01:00
WIP: demo app
This commit is contained in:
@@ -53,9 +53,9 @@ public extension CoreStore {
|
||||
/**
|
||||
Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass from `defaultStack`'s model.
|
||||
*/
|
||||
public static func entityDescriptionForType(_ type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
public static func entityDescription(for type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
|
||||
return self.defaultStack.entityDescriptionForType(type)
|
||||
return self.defaultStack.entityDescription(for: type)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,6 @@ public extension CoreStore {
|
||||
```
|
||||
try CoreStore.addStorageAndWait()
|
||||
```
|
||||
|
||||
- returns: the local SQLite storage added to the `defaultStack`
|
||||
*/
|
||||
@discardableResult
|
||||
@@ -77,7 +76,6 @@ public extension CoreStore {
|
||||
```
|
||||
try CoreStore.addStorageAndWait(InMemoryStore.self)
|
||||
```
|
||||
|
||||
- parameter storeType: the `StorageInterface` type
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the `StorageInterface` added to the `defaultStack`
|
||||
@@ -93,7 +91,6 @@ public extension CoreStore {
|
||||
```
|
||||
try CoreStore.addStorageAndWait(InMemoryStore(configuration: "Config1"))
|
||||
```
|
||||
|
||||
- parameter storage: the `StorageInterface`
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the `StorageInterface` added to the `defaultStack`
|
||||
@@ -109,7 +106,6 @@ public extension CoreStore {
|
||||
```
|
||||
try CoreStore.addStorageAndWait(SQLiteStore.self)
|
||||
```
|
||||
|
||||
- parameter storeType: the `LocalStorageface` type
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the local storage added to the `defaultStack`
|
||||
@@ -125,7 +121,6 @@ public extension CoreStore {
|
||||
```
|
||||
try CoreStore.addStorageAndWait(SQLiteStore(configuration: "Config1"))
|
||||
```
|
||||
|
||||
- parameter storage: the local storage
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- 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.
|
||||
@@ -152,7 +147,6 @@ public extension CoreStore {
|
||||
}
|
||||
try CoreStore.addStorageAndWait(storage)
|
||||
```
|
||||
|
||||
- parameter storage: the local storage
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the cloud storage added to the stack. Note that this may not always be the same instance as the parameter argument if a previous `CloudStorage` was already added at the same URL and with the same configuration.
|
||||
@@ -162,4 +156,16 @@ public extension CoreStore {
|
||||
|
||||
return try self.defaultStack.addStorageAndWait(storage)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Deprecated
|
||||
|
||||
/**
|
||||
Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass from `defaultStack`'s model.
|
||||
*/
|
||||
@available(*, deprecated: 3.0.0, renamed: "entityDescription(for:)")
|
||||
public static func entityDescriptionForType(_ type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
|
||||
return self.entityDescription(for: type)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public final class DataStack {
|
||||
/**
|
||||
Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass.
|
||||
*/
|
||||
public func entityDescriptionForType(_ type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
public func entityDescription(for type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
|
||||
return NSEntityDescription.entity(
|
||||
forEntityName: self.model.entityNameForClass(type),
|
||||
@@ -116,7 +116,6 @@ public final class DataStack {
|
||||
```
|
||||
try dataStack.addStorageAndWait()
|
||||
```
|
||||
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the local SQLite storage added to the stack
|
||||
*/
|
||||
@@ -131,7 +130,6 @@ public final class DataStack {
|
||||
```
|
||||
try dataStack.addStorageAndWait(InMemoryStore.self)
|
||||
```
|
||||
|
||||
- parameter storeType: the `StorageInterface` type
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the `StorageInterface` added to the stack
|
||||
@@ -147,7 +145,6 @@ public final class DataStack {
|
||||
```
|
||||
try dataStack.addStorageAndWait(InMemoryStore(configuration: "Config1"))
|
||||
```
|
||||
|
||||
- parameter storage: the `StorageInterface`
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the `StorageInterface` added to the stack
|
||||
@@ -187,7 +184,6 @@ public final class DataStack {
|
||||
```
|
||||
try dataStack.addStorageAndWait(SQLiteStore.self)
|
||||
```
|
||||
|
||||
- parameter storeType: the `LocalStorageface` type
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the local storage added to the stack
|
||||
@@ -203,7 +199,6 @@ public final class DataStack {
|
||||
```
|
||||
try dataStack.addStorageAndWait(SQLiteStore(configuration: "Config1"))
|
||||
```
|
||||
|
||||
- parameter storage: the local storage
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the local storage added to the stack. 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.
|
||||
@@ -226,8 +221,8 @@ public final class DataStack {
|
||||
|
||||
if let persistentStore = self.coordinator.persistentStore(for: fileURL as URL) {
|
||||
|
||||
if let existingStorage = persistentStore.storageInterface as? T
|
||||
where storage.matchesPersistentStore(persistentStore) {
|
||||
if let existingStorage = persistentStore.storageInterface as? T,
|
||||
storage.matchesPersistentStore(persistentStore) {
|
||||
|
||||
return existingStorage
|
||||
}
|
||||
@@ -304,7 +299,6 @@ public final class DataStack {
|
||||
}
|
||||
try dataStack.addStorageAndWait(storage)
|
||||
```
|
||||
|
||||
- parameter storage: the local storage
|
||||
- throws: a `CoreStoreError` value indicating the failure
|
||||
- returns: the cloud storage added to the stack. Note that this may not always be the same instance as the parameter argument if a previous `CloudStorage` was already added at the same URL and with the same configuration.
|
||||
@@ -322,8 +316,8 @@ public final class DataStack {
|
||||
let cacheFileURL = storage.cacheFileURL
|
||||
if let persistentStore = self.coordinator.persistentStore(for: cacheFileURL as URL) {
|
||||
|
||||
if let existingStorage = persistentStore.storageInterface as? T
|
||||
where storage.matchesPersistentStore(persistentStore) {
|
||||
if let existingStorage = persistentStore.storageInterface as? T,
|
||||
storage.matchesPersistentStore(persistentStore) {
|
||||
|
||||
return existingStorage
|
||||
}
|
||||
@@ -518,12 +512,20 @@ public final class DataStack {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Deprecated
|
||||
|
||||
@available(*, deprecated: 3.0.0, renamed: "entityDescription(for:)")
|
||||
public func entityDescriptionForType(_ type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
|
||||
return self.entityDescription(for: type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - DataStack: Equatable
|
||||
|
||||
@warn_unused_result
|
||||
public func == (lhs: DataStack, rhs: DataStack) -> Bool {
|
||||
|
||||
return lhs === rhs
|
||||
|
||||
@@ -57,7 +57,6 @@ public class ICloudStore: CloudStorage {
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
- parameter ubiquitousContentName: the name of the store in iCloud. This is required and should not be empty, and should not contain periods (`.`).
|
||||
- parameter ubiquitousContentTransactionLogsSubdirectory: an optional subdirectory path for the transaction logs
|
||||
- parameter ubiquitousContainerID: a container if your app has multiple ubiquity container identifiers in its entitlements
|
||||
@@ -481,8 +480,8 @@ public class ICloudStore: CloudStorage {
|
||||
|
||||
guard let `self` = self,
|
||||
let observer = observer,
|
||||
let dataStack = note.userInfo?[String(DataStack.self)] as? DataStack
|
||||
where self.dataStack === dataStack else {
|
||||
let dataStack = note.userInfo?[String(DataStack.self)] as? DataStack,
|
||||
self.dataStack === dataStack else {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
#if USE_FRAMEWORKS
|
||||
import GCDKit
|
||||
#endif
|
||||
|
||||
|
||||
// MARK: - LegacySQLiteStore
|
||||
@@ -180,7 +183,29 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
options: [NSSQLitePragmasOption: ["journal_mode": "DELETE"]]
|
||||
)
|
||||
try journalUpdatingCoordinator.remove(store)
|
||||
try FileManager.default.removeItem(at: fileURL)
|
||||
|
||||
let fileManager = FileManager.default
|
||||
do {
|
||||
|
||||
let temporaryFile = try URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!)
|
||||
.appendingPathComponent(Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack", isDirectory: true)
|
||||
.appendingPathComponent("trash", isDirectory: true)
|
||||
.appendingPathComponent(UUID().uuidString, isDirectory: false)
|
||||
try fileManager.createDirectory(
|
||||
at: try temporaryFile.deletingLastPathComponent(),
|
||||
withIntermediateDirectories: true,
|
||||
attributes: nil
|
||||
)
|
||||
try fileManager.moveItem(at: fileURL, to: temporaryFile)
|
||||
GCDQueue.background.async {
|
||||
|
||||
_ = try? fileManager.removeItem(at: temporaryFile)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
|
||||
try fileManager.removeItem(at: fileURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
//
|
||||
|
||||
import CoreData
|
||||
#if USE_FRAMEWORKS
|
||||
import GCDKit
|
||||
#endif
|
||||
|
||||
|
||||
// MARK: - SQLiteStore
|
||||
@@ -177,7 +180,29 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
|
||||
options: [NSSQLitePragmasOption: ["journal_mode": "DELETE"]]
|
||||
)
|
||||
try journalUpdatingCoordinator.remove(store)
|
||||
try FileManager.default.removeItem(at: fileURL)
|
||||
|
||||
let fileManager = FileManager.default
|
||||
do {
|
||||
|
||||
let temporaryFile = try URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!)
|
||||
.appendingPathComponent(Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack", isDirectory: true)
|
||||
.appendingPathComponent("trash", isDirectory: true)
|
||||
.appendingPathComponent(UUID().uuidString, isDirectory: false)
|
||||
try fileManager.createDirectory(
|
||||
at: try temporaryFile.deletingLastPathComponent(),
|
||||
withIntermediateDirectories: true,
|
||||
attributes: nil
|
||||
)
|
||||
try fileManager.moveItem(at: fileURL, to: temporaryFile)
|
||||
GCDQueue.background.async {
|
||||
|
||||
_ = try? fileManager.removeItem(at: temporaryFile)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
|
||||
try fileManager.removeItem(at: fileURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user