mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-20 08:34:23 +01:00
minor Swift 3 cleanup
This commit is contained in:
@@ -214,7 +214,7 @@ fileprivate func createFRC<T: NSManagedObject>(fromContext context: NSManagedObj
|
||||
fetchRequest.sortDescriptors?.isEmpty == false,
|
||||
"An \(cs_typeName(NSFetchedResultsController<NSManagedObject>.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.dynamicCast()
|
||||
}
|
||||
|
||||
@@ -93,17 +93,34 @@ public extension NSManagedObject {
|
||||
return primitiveValue
|
||||
}
|
||||
|
||||
/**
|
||||
Provides a convenience wrapper for accessing `primitiveValueForKey(...)` with proper calls to `willAccessValueForKey(...)` and `didAccessValueForKey(...)`. This is useful when implementing accessor methods for transient attributes.
|
||||
|
||||
- parameter KVCKey: the KVC key
|
||||
- parameter closure: a closure that receives the accessed value. This closure is executed between `willAccessValueForKey(...)` and `didAccessValueForKey(...)`
|
||||
- returns: the primitive value for the KVC key
|
||||
*/
|
||||
@nonobjc
|
||||
public func accessValueForKVCKey(_ KVCKey: KeyPath, _ closure: (Any?) -> Void) {
|
||||
|
||||
self.willAccessValue(forKey: KVCKey)
|
||||
closure(self.primitiveValue(forKey: KVCKey))
|
||||
self.didAccessValue(forKey: KVCKey)
|
||||
}
|
||||
|
||||
/**
|
||||
Provides a convenience wrapper for setting `setPrimitiveValue(...)` with proper calls to `willChangeValueForKey(...)` and `didChangeValueForKey(...)`. This is useful when implementing mutator methods for transient attributes.
|
||||
|
||||
- parameter value: the value to set the KVC key with
|
||||
- parameter closure: a closure that receives the accessed value. This closure is executed between `willChangeValue(...)` and `didChangeValue(...)`
|
||||
- parameter KVCKey: the KVC key
|
||||
*/
|
||||
@nonobjc
|
||||
public func setValue(_ value: Any?, forKVCKey KVCKey: KeyPath) {
|
||||
public func setValue(_ value: Any?, forKVCKey KVCKey: KeyPath, _ closure: () -> Void = {}) {
|
||||
|
||||
self.willChangeValue(forKey: KVCKey)
|
||||
self.setPrimitiveValue(value, forKey: KVCKey)
|
||||
closure()
|
||||
self.didChangeValue(forKey: KVCKey)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user