WIP: segfault

This commit is contained in:
John Rommel Estropia
2016-07-20 08:12:04 +09:00
parent f486ace437
commit 267c21063a
129 changed files with 2205 additions and 3282 deletions

View File

@@ -26,198 +26,199 @@
import Foundation
import CoreData
#if os(iOS) || os(watchOS) || os(tvOS)
// MARK: - NSFetchedResultsController
public extension NSFetchedResultsController {
/**
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter dataStack: the `DataStack` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes a `DataStack`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(dataStack: DataStack, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
return self.createFromContext(
dataStack.mainContext,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter dataStack: the `DataStack` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes a `DataStack`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(dataStack: DataStack, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
return self.createFromContext(
dataStack.mainContext,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter dataStack: the `DataStack` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes a `DataStack`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(dataStack: DataStack, _ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
return self.createFromContext(
dataStack.mainContext,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter dataStack: the `DataStack` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes a `DataStack`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(dataStack: DataStack, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
return self.createFromContext(
dataStack.mainContext,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter transaction: the `UnsafeDataTransaction` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(transaction: UnsafeDataTransaction, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
return self.createFromContext(
transaction.context,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter transaction: the `UnsafeDataTransaction` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(transaction: UnsafeDataTransaction, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
return self.createFromContext(
transaction.context,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter transaction: the `UnsafeDataTransaction` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
*/
@nonobjc
public static func createFor<T: NSManagedObject>(transaction: UnsafeDataTransaction, _ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
return self.createFromContext(
transaction.context,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
/**
Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
- parameter transaction: the `UnsafeDataTransaction` to observe objects from
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
*/
@nonobjc
public static func createFor<T: NSManagedObject>(transaction: UnsafeDataTransaction, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
return self.createFromContext(
transaction.context,
fetchRequest: CoreStoreFetchRequest(),
from: from,
sectionBy: nil,
fetchClauses: fetchClauses
)
}
// MARK: Internal
@nonobjc
internal static func createFromContext<T: NSManagedObject>(context: NSManagedObjectContext, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController {
return CoreStoreFetchedResultsController(
context: context,
fetchRequest: fetchRequest,
from: from,
sectionBy: sectionBy,
applyFetchClauses: { fetchRequest in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(NSFetchedResultsController)) requires a sort information. Specify from a \(cs_typeName(OrderBy)) clause or any custom \(cs_typeName(FetchClause)) that provides a sort descriptor."
)
}
)
}
}
#endif
// TODO: Uncomment
//#if os(iOS) || os(watchOS) || os(tvOS)
//
//// MARK: - NSFetchedResultsController
//
//public extension NSFetchedResultsController {
//
// /**
// Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter dataStack: the `DataStack` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes a `DataStack`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ dataStack: DataStack, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController<NSFetchRequestResult> {
//
// return self.createFromContext(
// dataStack.mainContext,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: sectionBy,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter dataStack: the `DataStack` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes a `DataStack`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ dataStack: DataStack, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
//
// return self.createFromContext(
// dataStack.mainContext,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: sectionBy,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter dataStack: the `DataStack` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes a `DataStack`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ dataStack: DataStack, _ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
//
// return self.createFromContext(
// dataStack.mainContext,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: nil,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter dataStack: the `DataStack` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes a `DataStack`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ dataStack: DataStack, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
//
// return self.createFromContext(
// dataStack.mainContext,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: nil,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter transaction: the `UnsafeDataTransaction` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ transaction: UnsafeDataTransaction, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
//
// return self.createFromContext(
// transaction.context,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: sectionBy,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter transaction: the `UnsafeDataTransaction` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter sectionBy: a `SectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ transaction: UnsafeDataTransaction, _ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
//
// return self.createFromContext(
// transaction.context,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: sectionBy,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter transaction: the `UnsafeDataTransaction` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// - returns: an `NSFetchedResultsController` that observes an `UnsafeDataTransaction`
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ transaction: UnsafeDataTransaction, _ from: From<T>, _ fetchClauses: FetchClause...) -> NSFetchedResultsController {
//
// return self.createFromContext(
// transaction.context,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: nil,
// fetchClauses: fetchClauses
// )
// }
//
// /**
// Utility for creating an `NSFetchedResultsController` from an `UnsafeDataTransaction`. This is useful when an `NSFetchedResultsController` is preferred over the overhead of `ListMonitor`s abstraction.
//
// - parameter transaction: the `UnsafeDataTransaction` to observe objects from
// - parameter from: a `From` clause indicating the entity type
// - parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
// */
// @nonobjc
// public static func createFor<T: NSManagedObject>(_ transaction: UnsafeDataTransaction, _ from: From<T>, _ fetchClauses: [FetchClause]) -> NSFetchedResultsController {
//
// return self.createFromContext(
// transaction.context,
// fetchRequest: CoreStoreFetchRequest(),
// from: from,
// sectionBy: nil,
// fetchClauses: fetchClauses
// )
// }
//
//
// // MARK: Internal
//
// @nonobjc
// internal static func createFromContext<T: NSManagedObject>(_ context: NSManagedObjectContext, fetchRequest: CoreStoreFetchRequest<T>, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController<NSFetchRequestResult> {
//
// let controller = CoreStoreFetchedResultsController(
// context: context,
// fetchRequest: fetchRequest,
// from: from,
// sectionBy: sectionBy,
// applyFetchClauses: { fetchRequest in
//
// fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
//
// CoreStore.assert(
// fetchRequest.sortDescriptors?.isEmpty == false,
// "An \(cs_typeName(NSFetchedResultsController<T>.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor."
// )
// }
// )
// return controller.upcast()
// }
//}
//
//#endif

View File

@@ -39,11 +39,11 @@ public extension NSManagedObject {
*/
@nonobjc
@warn_unused_result
public func accessValueForKVCKey(KVCKey: KeyPath) -> AnyObject? {
public func accessValueForKVCKey(_ KVCKey: KeyPath) -> AnyObject? {
self.willAccessValueForKey(KVCKey)
let primitiveValue: AnyObject? = self.primitiveValueForKey(KVCKey)
self.didAccessValueForKey(KVCKey)
self.willAccessValue(forKey: KVCKey)
let primitiveValue: AnyObject? = self.primitiveValue(forKey: KVCKey)
self.didAccessValue(forKey: KVCKey)
return primitiveValue
}
@@ -55,11 +55,11 @@ public extension NSManagedObject {
- parameter KVCKey: the KVC key
*/
@nonobjc
public func setValue(value: AnyObject?, forKVCKey KVCKey: KeyPath) {
public func setValue(_ value: AnyObject?, forKVCKey KVCKey: KeyPath) {
self.willChangeValueForKey(KVCKey)
self.willChangeValue(forKey: KVCKey)
self.setPrimitiveValue(value, forKey: KVCKey)
self.didChangeValueForKey(KVCKey)
self.didChangeValue(forKey: KVCKey)
}
/**
@@ -68,7 +68,7 @@ public extension NSManagedObject {
@nonobjc
public func refreshAsFault() {
self.managedObjectContext?.refreshObject(self, mergeChanges: false)
self.managedObjectContext?.refresh(self, mergeChanges: false)
}
/**
@@ -77,6 +77,6 @@ public extension NSManagedObject {
@nonobjc
public func refreshAndMerge() {
self.managedObjectContext?.refreshObject(self, mergeChanges: true)
self.managedObjectContext?.refresh(self, mergeChanges: true)
}
}

View File

@@ -31,7 +31,7 @@ import Foundation
// MARK: - NSProgress
public extension NSProgress {
public extension Progress {
/**
Sets a closure that the `NSProgress` calls whenever its `fractionCompleted` changes. You can use this instead of setting up KVO.
@@ -39,7 +39,7 @@ public extension NSProgress {
- parameter closure: the closure to execute on progress change
*/
@nonobjc
public func setProgressHandler(closure: ((progress: NSProgress) -> Void)?) {
public func setProgressHandler(_ closure: ((progress: Progress) -> Void)?) {
self.progressObserver.progressHandler = closure
}
@@ -81,8 +81,8 @@ public extension NSProgress {
@objc
private final class ProgressObserver: NSObject {
private unowned let progress: NSProgress
private var progressHandler: ((progress: NSProgress) -> Void)? {
private unowned let progress: Progress
private var progressHandler: ((progress: Progress) -> Void)? {
didSet {
@@ -97,7 +97,7 @@ private final class ProgressObserver: NSObject {
self.progress.addObserver(
self,
forKeyPath: "fractionCompleted",
options: [.Initial, .New],
options: [.initial, .new],
context: nil
)
}
@@ -108,7 +108,7 @@ private final class ProgressObserver: NSObject {
}
}
private init(_ progress: NSProgress) {
private init(_ progress: Progress) {
self.progress = progress
super.init()
@@ -123,14 +123,14 @@ private final class ProgressObserver: NSObject {
}
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey : AnyObject]?, context: UnsafeMutablePointer<Void>?) {
guard let progress = object as? NSProgress where progress == self.progress && keyPath == "fractionCompleted" else {
guard let progress = object as? Progress where progress == self.progress && keyPath == "fractionCompleted" else {
return
}
GCDQueue.Main.async { [weak self] () -> Void in
GCDQueue.main.async { [weak self] () -> Void in
self?.progressHandler?(progress: progress)
}