WIP: Xcode 8 beta 6

This commit is contained in:
John Estropia
2016-09-06 09:57:28 +09:00
parent e9be711d4c
commit 0ba63c6e72
78 changed files with 472 additions and 450 deletions

View File

@@ -36,7 +36,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
// MARK: Internal
@nonobjc
internal convenience init<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<T>? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) {
internal convenience init<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<T>? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (_ fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) {
self.init(
context: dataStack.mainContext,
@@ -48,14 +48,14 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
}
@nonobjc
internal init<T: NSManagedObject>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<T>? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) {
internal init<T: NSManagedObject>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest<NSManagedObject>, from: From<T>? = nil, sectionBy: SectionBy? = nil, applyFetchClauses: (_ fetchRequest: NSFetchRequest<NSManagedObject>) -> Void) {
_ = from?.applyToFetchRequest(
fetchRequest,
context: context,
applyAffectedStores: false
)
applyFetchClauses(fetchRequest: unsafeBitCast(fetchRequest, to: NSFetchRequest<NSManagedObject>.self))
applyFetchClauses(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSManagedObject>.self))
if let from = from {
@@ -88,7 +88,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
@nonobjc
internal func performFetchFromSpecifiedStores() throws {
if !self.reapplyAffectedStores(fetchRequest: self.fetchRequest, context: self.managedObjectContext) {
if !self.reapplyAffectedStores(self.fetchRequest, self.managedObjectContext) {
CoreStore.log(
.warning,
@@ -113,7 +113,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
// MARK: Private
@nonobjc
private let reapplyAffectedStores: (fetchRequest: NSFetchRequest<NSManagedObject>, context: NSManagedObjectContext) -> Bool
private let reapplyAffectedStores: (_ fetchRequest: NSFetchRequest<NSManagedObject>, _ context: NSManagedObjectContext) -> Bool
}
#endif

View File

@@ -0,0 +1,90 @@
//
// DispatchQueue+CoreStore.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
// MARK: - DispatchQueue
internal extension DispatchQueue {
internal convenience init(serialWith label: String) {
self.init(
label: label,
qos: .default,
attributes: .allZeros,
autoreleaseFrequency: .inherit,
target: nil
)
}
internal convenience init(concurrentWith label: String) {
self.init(
label: label,
qos: .default,
attributes: .concurrent,
autoreleaseFrequency: .inherit,
target: nil
)
}
internal func cs_isCurrentExecutionContext() -> Bool {
let specific = ObjectIdentifier(self)
self.setSpecific(key: Static.specificKey, value: specific)
return DispatchQueue.getSpecific(key: Static.specificKey) == specific
}
internal func cs_sync<T>(_ closure: () throws -> T) rethrows -> T {
return self.sync { autoreleasepool(invoking: closure) }
}
internal func cs_async(_ closure: () -> Void) {
self.async { autoreleasepool(invoking: closure) }
}
internal func cs_barrierSync<T>(_ closure: () throws -> T) rethrows -> T {
return self.sync(flags: .barrier) { autoreleasepool(invoking: closure) }
}
internal func cs_barrierAsync(_ closure: () -> Void) {
self.async(flags: .barrier) { autoreleasepool(invoking: closure) }
}
// MARK: Private
private enum Static {
static let specificKey = DispatchSpecificKey<ObjectIdentifier>()
}
}

View File

@@ -27,7 +27,7 @@ import Foundation
// MARK: Associated Objects
internal func cs_getAssociatedObjectForKey<T: AnyObject>(_ key: UnsafePointer<Void>, inObject object: AnyObject) -> T? {
internal func cs_getAssociatedObjectForKey<T: AnyObject>(_ key: UnsafeRawPointer, inObject object: AnyObject) -> T? {
switch objc_getAssociatedObject(object, key) {
@@ -42,17 +42,17 @@ internal func cs_getAssociatedObjectForKey<T: AnyObject>(_ key: UnsafePointer<Vo
}
}
internal func cs_setAssociatedRetainedObject<T: AnyObject>(_ associatedObject: T?, forKey key: UnsafePointer<Void>, inObject object: AnyObject) {
internal func cs_setAssociatedRetainedObject<T: AnyObject>(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: AnyObject) {
objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
internal func cs_setAssociatedCopiedObject<T: AnyObject>(_ associatedObject: T?, forKey key: UnsafePointer<Void>, inObject object: AnyObject) {
internal func cs_setAssociatedCopiedObject<T: AnyObject>(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: AnyObject) {
objc_setAssociatedObject(object, key, associatedObject, .OBJC_ASSOCIATION_COPY_NONATOMIC)
}
internal func cs_setAssociatedWeakObject<T: AnyObject>(_ associatedObject: T?, forKey key: UnsafePointer<Void>, inObject object: AnyObject) {
internal func cs_setAssociatedWeakObject<T: AnyObject>(_ associatedObject: T?, forKey key: UnsafeRawPointer, inObject object: AnyObject) {
if let associatedObject = associatedObject {
@@ -69,7 +69,7 @@ internal func cs_setAssociatedWeakObject<T: AnyObject>(_ associatedObject: T?, f
internal func cs_typeName<T>(_ value: T) -> String {
return "'\(String(reflecting: value.dynamicType))'"
return "'\(String(reflecting: type(of: value)))'"
}
internal func cs_typeName<T>(_ value: T.Type) -> String {

View File

@@ -25,9 +25,6 @@
import Foundation
import CoreData
#if USE_FRAMEWORKS
import GCDKit
#endif
// MARK: - NSManagedObjectContext

View File

@@ -99,7 +99,7 @@ internal extension NSManagedObjectContext {
internal func fetchOne<T: NSManagedObject>(_ fetchRequest: NSFetchRequest<T>) -> T? {
var fetchResults: [T]?
var fetchError: ErrorProtocol?
var fetchError: Error?
self.performAndWait {
do {
@@ -152,7 +152,7 @@ internal extension NSManagedObjectContext {
internal func fetchAll<T: NSManagedObject>(_ fetchRequest: NSFetchRequest<T>) -> [T]? {
var fetchResults: [T]?
var fetchError: ErrorProtocol?
var fetchError: Error?
self.performAndWait {
do {
@@ -202,7 +202,7 @@ internal extension NSManagedObjectContext {
internal func fetchCount(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> Int? {
var count = 0
var countError: ErrorProtocol?
var countError: Error?
self.performAndWait {
do {
@@ -255,7 +255,7 @@ internal extension NSManagedObjectContext {
internal func fetchObjectID(_ fetchRequest: NSFetchRequest<NSManagedObjectID>) -> NSManagedObjectID? {
var fetchResults: [NSManagedObjectID]?
var fetchError: ErrorProtocol?
var fetchError: Error?
self.performAndWait {
do {
@@ -308,7 +308,7 @@ internal extension NSManagedObjectContext {
internal func fetchObjectIDs(_ fetchRequest: NSFetchRequest<NSManagedObjectID>) -> [NSManagedObjectID]? {
var fetchResults: [NSManagedObjectID]?
var fetchError: ErrorProtocol?
var fetchError: Error?
self.performAndWait {
do {
@@ -363,7 +363,7 @@ internal extension NSManagedObjectContext {
internal func deleteAll<T: NSManagedObject>(_ fetchRequest: NSFetchRequest<T>) -> Int? {
var numberOfDeletedObjects: Int?
var fetchError: ErrorProtocol?
var fetchError: Error?
self.performAndWait {
autoreleasepool {
@@ -426,7 +426,7 @@ internal extension NSManagedObjectContext {
internal func queryValue<U: SelectValueResultType>(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> U? {
var fetchResults: [AnyObject]?
var fetchError: ErrorProtocol?
var fetchError: Error?
self.performAndWait {
do {
@@ -459,7 +459,7 @@ internal extension NSManagedObjectContext {
internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> AnyObject? {
var fetchResults: [AnyObject]?
var fetchError: ErrorProtocol?
var fetchError: Error?
self.performAndWait {
do {
@@ -519,7 +519,7 @@ internal extension NSManagedObjectContext {
internal func queryAttributes(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> [[NSString: AnyObject]]? {
var fetchResults: [AnyObject]?
var fetchError: ErrorProtocol?
var fetchError: Error?
self.performAndWait {
do {

View File

@@ -25,9 +25,6 @@
import Foundation
import CoreData
#if USE_FRAMEWORKS
import GCDKit
#endif
// MARK: - NSManagedObjectContext
@@ -150,13 +147,13 @@ internal extension NSManagedObjectContext {
}
@nonobjc
internal func saveAsynchronouslyWithCompletion(_ completion: ((result: SaveResult) -> Void) = { _ in }) {
internal func saveAsynchronouslyWithCompletion(_ completion: ((_ result: SaveResult) -> Void) = { _ in }) {
self.perform {
guard self.hasChanges else {
GCDQueue.main.async {
DispatchQueue.main.async {
completion(result: SaveResult(hasChanges: false))
}
@@ -176,7 +173,7 @@ internal extension NSManagedObjectContext {
saveError,
"Failed to save \(cs_typeName(NSManagedObjectContext.self))."
)
GCDQueue.main.async {
DispatchQueue.main.async {
completion(result: SaveResult(saveError))
}
@@ -189,7 +186,7 @@ internal extension NSManagedObjectContext {
}
else {
GCDQueue.main.async {
DispatchQueue.main.async {
completion(result: SaveResult(hasChanges: true))
}

View File

@@ -36,7 +36,7 @@ internal extension NSManagedObjectModel {
@nonobjc
internal static func fromBundle(_ bundle: Bundle, modelName: String, modelVersionHints: Set<String> = []) -> NSManagedObjectModel {
guard let modelFilePath = bundle.pathForResource(modelName, ofType: "momd") else {
guard let modelFilePath = bundle.path(forResource: modelName, ofType: "momd") else {
CoreStore.abort("Could not find \"\(modelName).momd\" from the bundle. \(bundle)")
}

View File

@@ -26,23 +26,19 @@
import Foundation
import CoreData
#if USE_FRAMEWORKS
import GCDKit
#endif
// MARK: - NSPersistentStoreCoordinator
internal extension NSPersistentStoreCoordinator {
@nonobjc
internal func performAsynchronously(_ closure: () -> Void) {
internal func performAsynchronously(_ closure: @escaping () -> Void) {
self.perform(closure)
}
@nonobjc
internal func performSynchronously<T>(_ closure: () -> T) -> T {
internal func performSynchronously<T>(_ closure: @escaping () -> T) -> T {
var result: T?
self.performAndWait {
@@ -53,9 +49,9 @@ internal extension NSPersistentStoreCoordinator {
}
@nonobjc
internal func performSynchronously<T>(_ closure: () throws -> T) throws -> T {
internal func performSynchronously<T>(_ closure: @escaping () throws -> T) throws -> T {
var closureError: ErrorProtocol?
var closureError: Error?
var result: T?
self.performAndWait {

View File

@@ -36,7 +36,7 @@ internal final class NotificationObserver {
let object: AnyObject?
let observer: NSObjectProtocol
init(notificationName: Notification.Name, object: AnyObject?, queue: OperationQueue? = nil, closure: (note: Notification) -> Void) {
init(notificationName: Notification.Name, object: AnyObject?, queue: OperationQueue? = nil, closure: @escaping (_ note: Notification) -> Void) {
self.notificationName = notificationName
self.object = object