This commit is contained in:
John Rommel Estropia
2016-07-21 02:45:42 +09:00
parent 267c21063a
commit a638620858
85 changed files with 1621 additions and 1819 deletions

View File

@@ -98,6 +98,7 @@ public extension CoreStore {
- throws: a `CoreStoreError` value indicating the failure
- returns: the `StorageInterface` added to the `defaultStack`
*/
@discardableResult
public static func addStorageAndWait<T: StorageInterface>(_ storage: T) throws -> T {
return try self.defaultStack.addStorageAndWait(storage)
@@ -113,6 +114,7 @@ public extension CoreStore {
- throws: a `CoreStoreError` value indicating the failure
- returns: the local storage added to the `defaultStack`
*/
@discardableResult
public static func addStorageAndWait<T: LocalStorage where T: DefaultInitializableStore>(_ storageType: T.Type) throws -> T {
return try self.defaultStack.addStorageAndWait(storageType.init())
@@ -128,6 +130,7 @@ public extension CoreStore {
- 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.
*/
@discardableResult
public static func addStorageAndWait<T: LocalStorage>(_ storage: T) throws -> T {
return try self.defaultStack.addStorageAndWait(storage)
@@ -154,6 +157,7 @@ public extension CoreStore {
- 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.
*/
@discardableResult
public static func addStorageAndWait<T: CloudStorage>(_ storage: T) throws -> T {
return try self.defaultStack.addStorageAndWait(storage)

View File

@@ -120,6 +120,7 @@ public final class DataStack {
- throws: a `CoreStoreError` value indicating the failure
- returns: the local SQLite storage added to the stack
*/
@discardableResult
public func addStorageAndWait() throws -> SQLiteStore {
return try self.addStorageAndWait(SQLiteStore.self)
@@ -135,6 +136,7 @@ public final class DataStack {
- throws: a `CoreStoreError` value indicating the failure
- returns: the `StorageInterface` added to the stack
*/
@discardableResult
public func addStorageAndWait<T: StorageInterface where T: DefaultInitializableStore>(_ storeType: T.Type) throws -> T {
return try self.addStorageAndWait(storeType.init())
@@ -150,6 +152,7 @@ public final class DataStack {
- throws: a `CoreStoreError` value indicating the failure
- returns: the `StorageInterface` added to the stack
*/
@discardableResult
public func addStorageAndWait<T: StorageInterface>(_ storage: T) throws -> T {
do {
@@ -189,6 +192,7 @@ public final class DataStack {
- throws: a `CoreStoreError` value indicating the failure
- returns: the local storage added to the stack
*/
@discardableResult
public func addStorageAndWait<T: LocalStorage where T: DefaultInitializableStore>(_ storageType: T.Type) throws -> T {
return try self.addStorageAndWait(storageType.init())
@@ -204,6 +208,7 @@ public final class DataStack {
- 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.
*/
@discardableResult
public func addStorageAndWait<T: LocalStorage>(_ storage: T) throws -> T {
return try self.coordinator.performSynchronously {
@@ -304,6 +309,7 @@ public final class DataStack {
- 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.
*/
@discardableResult
public func addStorageAndWait<T: CloudStorage>(_ storage: T) throws -> T {
return try self.coordinator.performSynchronously {
@@ -388,7 +394,7 @@ public final class DataStack {
internal let mainContext: NSManagedObjectContext
internal let model: NSManagedObjectModel
internal let migrationChain: MigrationChain
internal let childTransactionQueue: GCDQueue = .createSerial("com.coreStore.dataStack.childTransactionQueue")
internal let childTransactionQueue = GCDQueue.createSerial("com.coreStore.dataStack.childTransactionQueue")
internal let storeMetadataUpdateQueue = GCDQueue.createConcurrent("com.coreStore.persistentStoreBarrierQueue")
internal let migrationQueue: OperationQueue = {
@@ -396,10 +402,7 @@ public final class DataStack {
migrationQueue.maxConcurrentOperationCount = 1
migrationQueue.name = "com.coreStore.migrationOperationQueue"
migrationQueue.qualityOfService = .utility
migrationQueue.underlyingQueue = DispatchQueue(
label: "com.coreStore.migrationQueue",
attributes: .serial
)
migrationQueue.underlyingQueue = GCDQueue.createSerial("com.coreStore.migrationQueue").dispatchQueue()
return migrationQueue
}()

View File

@@ -121,7 +121,7 @@ public class ICloudStore: CloudStorage {
self.registerNotification(
&self.willFinishInitialImportKey,
name: ICloudUbiquitousStoreWillFinishInitialImportNotification,
name: Notification.Name.iCloudUbiquitousStoreWillFinishInitialImport,
toObserver: observer,
callback: { (observer, storage, dataStack) in
@@ -130,7 +130,7 @@ public class ICloudStore: CloudStorage {
)
self.registerNotification(
&self.didFinishInitialImportKey,
name: ICloudUbiquitousStoreDidFinishInitialImportNotification,
name: Notification.Name.iCloudUbiquitousStoreDidFinishInitialImport,
toObserver: observer,
callback: { (observer, storage, dataStack) in
@@ -139,7 +139,7 @@ public class ICloudStore: CloudStorage {
)
self.registerNotification(
&self.willAddAccountKey,
name: ICloudUbiquitousStoreWillAddAccountNotification,
name: Notification.Name.iCloudUbiquitousStoreWillAddAccount,
toObserver: observer,
callback: { (observer, storage, dataStack) in
@@ -148,7 +148,7 @@ public class ICloudStore: CloudStorage {
)
self.registerNotification(
&self.didAddAccountKey,
name: ICloudUbiquitousStoreDidAddAccountNotification,
name: Notification.Name.iCloudUbiquitousStoreDidAddAccount,
toObserver: observer,
callback: { (observer, storage, dataStack) in
@@ -157,7 +157,7 @@ public class ICloudStore: CloudStorage {
)
self.registerNotification(
&self.willRemoveAccountKey,
name: ICloudUbiquitousStoreWillRemoveAccountNotification,
name: Notification.Name.iCloudUbiquitousStoreWillRemoveAccount,
toObserver: observer,
callback: { (observer, storage, dataStack) in
@@ -166,7 +166,7 @@ public class ICloudStore: CloudStorage {
)
self.registerNotification(
&self.didRemoveAccountKey,
name: ICloudUbiquitousStoreDidRemoveAccountNotification,
name: Notification.Name.iCloudUbiquitousStoreDidRemoveAccount,
toObserver: observer,
callback: { (observer, storage, dataStack) in
@@ -175,7 +175,7 @@ public class ICloudStore: CloudStorage {
)
self.registerNotification(
&self.willRemoveContentKey,
name: ICloudUbiquitousStoreWillRemoveContentNotification,
name: Notification.Name.iCloudUbiquitousStoreWillRemoveContent,
toObserver: observer,
callback: { (observer, storage, dataStack) in
@@ -184,7 +184,7 @@ public class ICloudStore: CloudStorage {
)
self.registerNotification(
&self.didRemoveContentKey,
name: ICloudUbiquitousStoreDidRemoveContentNotification,
name: Notification.Name.iCloudUbiquitousStoreDidRemoveContent,
toObserver: observer,
callback: { (observer, storage, dataStack) in
@@ -280,40 +280,40 @@ public class ICloudStore: CloudStorage {
cs_setAssociatedRetainedObject(
NotificationObserver(
notificationName: NSNotification.Name.NSPersistentStoreCoordinatorStoresWillChange.rawValue,
notificationName: Notification.Name.NSPersistentStoreCoordinatorStoresWillChange,
object: coordinator,
closure: { [weak self, weak dataStack] (note) -> Void in
guard let `self` = self,
let dataStack = dataStack,
let userInfo = (note as NSNotification).userInfo,
let userInfo = note.userInfo,
let transitionType = userInfo[NSPersistentStoreUbiquitousTransitionTypeKey] as? NSNumber else {
return
}
let notification: String
let notification: Notification.Name
switch NSPersistentStoreUbiquitousTransitionType(rawValue: transitionType.uintValue) {
case .initialImportCompleted?:
notification = ICloudUbiquitousStoreWillFinishInitialImportNotification
notification = Notification.Name.iCloudUbiquitousStoreWillFinishInitialImport
case .accountAdded?:
notification = ICloudUbiquitousStoreWillAddAccountNotification
notification = Notification.Name.iCloudUbiquitousStoreWillAddAccount
case .accountRemoved?:
notification = ICloudUbiquitousStoreWillRemoveAccountNotification
notification = Notification.Name.iCloudUbiquitousStoreWillRemoveAccount
case .contentRemoved?:
notification = ICloudUbiquitousStoreWillRemoveContentNotification
notification = Notification.Name.iCloudUbiquitousStoreWillRemoveContent
default:
return
}
NotificationCenter.default.post(
name: Notification.Name(rawValue: notification),
name: notification,
object: self,
userInfo: [UserInfoKeyDataStack: dataStack]
userInfo: [String(DataStack.self): dataStack]
)
}
),
@@ -322,40 +322,40 @@ public class ICloudStore: CloudStorage {
)
cs_setAssociatedRetainedObject(
NotificationObserver(
notificationName: NSNotification.Name.NSPersistentStoreCoordinatorStoresDidChange.rawValue,
notificationName: NSNotification.Name.NSPersistentStoreCoordinatorStoresDidChange,
object: coordinator,
closure: { [weak self, weak dataStack] (note) -> Void in
guard let `self` = self,
let dataStack = dataStack,
let userInfo = (note as NSNotification).userInfo,
let userInfo = note.userInfo,
let transitionType = userInfo[NSPersistentStoreUbiquitousTransitionTypeKey] as? NSNumber else {
return
}
let notification: String
let notification: Notification.Name
switch NSPersistentStoreUbiquitousTransitionType(rawValue: transitionType.uintValue) {
case .initialImportCompleted?:
notification = ICloudUbiquitousStoreDidFinishInitialImportNotification
notification = Notification.Name.iCloudUbiquitousStoreDidFinishInitialImport
case .accountAdded?:
notification = ICloudUbiquitousStoreDidAddAccountNotification
notification = Notification.Name.iCloudUbiquitousStoreDidAddAccount
case .accountRemoved?:
notification = ICloudUbiquitousStoreDidRemoveAccountNotification
notification = Notification.Name.iCloudUbiquitousStoreDidRemoveAccount
case .contentRemoved?:
notification = ICloudUbiquitousStoreDidRemoveContentNotification
notification = Notification.Name.iCloudUbiquitousStoreDidRemoveContent
default:
return
}
NotificationCenter.default.post(
name: Notification.Name(rawValue: notification),
name: notification,
object: self,
userInfo: [UserInfoKeyDataStack: dataStack]
userInfo: [String(DataStack.self): dataStack]
)
}
),
@@ -429,7 +429,7 @@ public class ICloudStore: CloudStorage {
// TODO: check if attached to persistent store
let cacheFileURL = self.cacheFileURL
try cs_autoreleasepool {
try autoreleasepool {
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
let options = [
@@ -471,7 +471,7 @@ public class ICloudStore: CloudStorage {
private weak var dataStack: DataStack?
private func registerNotification<T: ICloudStoreObserver>(_ notificationKey: UnsafePointer<Void>, name: String, toObserver observer: T, callback: (observer: T, storage: ICloudStore, dataStack: DataStack) -> Void) {
private func registerNotification<T: ICloudStoreObserver>(_ notificationKey: UnsafePointer<Void>, name: Notification.Name, toObserver observer: T, callback: (observer: T, storage: ICloudStore, dataStack: DataStack) -> Void) {
cs_setAssociatedRetainedObject(
NotificationObserver(
@@ -481,7 +481,7 @@ public class ICloudStore: CloudStorage {
guard let `self` = self,
let observer = observer,
let dataStack = (note as NSNotification).userInfo?[UserInfoKeyDataStack] as? DataStack
let dataStack = note.userInfo?[String(DataStack.self)] as? DataStack
where self.dataStack === dataStack else {
return
@@ -497,16 +497,17 @@ public class ICloudStore: CloudStorage {
// MARK: - Notification Keys
private let ICloudUbiquitousStoreWillFinishInitialImportNotification = "ICloudUbiquitousStoreWillFinishInitialImportNotification"
private let ICloudUbiquitousStoreDidFinishInitialImportNotification = "ICloudUbiquitousStoreDidFinishInitialImportNotification"
private let ICloudUbiquitousStoreWillAddAccountNotification = "ICloudUbiquitousStoreWillAddAccountNotification"
private let ICloudUbiquitousStoreDidAddAccountNotification = "ICloudUbiquitousStoreDidAddAccountNotification"
private let ICloudUbiquitousStoreWillRemoveAccountNotification = "ICloudUbiquitousStoreWillRemoveAccountNotification"
private let ICloudUbiquitousStoreDidRemoveAccountNotification = "ICloudUbiquitousStoreDidRemoveAccountNotification"
private let ICloudUbiquitousStoreWillRemoveContentNotification = "ICloudUbiquitousStoreWillRemoveContentNotification"
private let ICloudUbiquitousStoreDidRemoveContentNotification = "ICloudUbiquitousStoreDidRemoveContentNotification"
private let UserInfoKeyDataStack = "UserInfoKeyDataStack"
private extension Notification.Name {
private static let iCloudUbiquitousStoreWillFinishInitialImport = Notification.Name(rawValue: "iCloudUbiquitousStoreWillFinishInitialImport")
private static let iCloudUbiquitousStoreDidFinishInitialImport = Notification.Name(rawValue: "iCloudUbiquitousStoreDidFinishInitialImport")
private static let iCloudUbiquitousStoreWillAddAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreWillAddAccount")
private static let iCloudUbiquitousStoreDidAddAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreDidAddAccount")
private static let iCloudUbiquitousStoreWillRemoveAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreWillRemoveAccount")
private static let iCloudUbiquitousStoreDidRemoveAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreDidRemoveAccount")
private static let iCloudUbiquitousStoreWillRemoveContent = Notification.Name(rawValue: "iCloudUbiquitousStoreWillRemoveContent")
private static let iCloudUbiquitousStoreDidRemoveContent = Notification.Name(rawValue: "iCloudUbiquitousStoreDidRemoveContent")
}
#endif

View File

@@ -170,7 +170,7 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
// TODO: check if attached to persistent store
let fileURL = self.fileURL
try cs_autoreleasepool {
try autoreleasepool {
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
let store = try journalUpdatingCoordinator.addPersistentStore(
@@ -190,7 +190,7 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
internal static let defaultRootDirectory: URL = {
#if os(tvOS)
let systemDirectorySearchPath = NSSearchPathDirectory.CachesDirectory
let systemDirectorySearchPath = FileManager.SearchPathDirectory.cachesDirectory
#else
let systemDirectorySearchPath = FileManager.SearchPathDirectory.applicationSupportDirectory
#endif

View File

@@ -167,7 +167,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
// TODO: check if attached to persistent store
let fileURL = self.fileURL
try cs_autoreleasepool {
try autoreleasepool {
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
let store = try journalUpdatingCoordinator.addPersistentStore(
@@ -187,7 +187,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
internal static let defaultRootDirectory: URL = {
#if os(tvOS)
let systemDirectorySearchPath = NSSearchPathDirectory.CachesDirectory
let systemDirectorySearchPath = FileManager.SearchPathDirectory.cachesDirectory
#else
let systemDirectorySearchPath = FileManager.SearchPathDirectory.applicationSupportDirectory
#endif