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

@@ -38,7 +38,6 @@ public extension NSManagedObject {
- returns: the primitive value for the KVC key
*/
@nonobjc
@warn_unused_result
public func accessValueForKVCKey(_ KVCKey: KeyPath) -> AnyObject? {
self.willAccessValue(forKey: KVCKey)

View File

@@ -75,7 +75,7 @@ public enum CoreStoreError: ErrorProtocol, Hashable {
return CoreStoreErrorCode.unknownError.rawValue
case .differentStorageExistsAtURL:
return CoreStoreErrorCode.differentPersistentStoreExistsAtURL.rawValue
return CoreStoreErrorCode.differentStorageExistsAtURL.rawValue
case .mappingModelNotFound:
return CoreStoreErrorCode.mappingModelNotFound.rawValue
@@ -174,7 +174,7 @@ public enum CoreStoreErrorCode: Int {
/**
The `NSPersistentStore` could note be initialized because another store existed at the specified `NSURL`.
*/
case differentPersistentStoreExistsAtURL
case differentStorageExistsAtURL
/**
An `NSMappingModel` could not be found for a specific source and destination model versions.

View File

@@ -37,7 +37,6 @@ public extension BaseDataTransaction {
- parameter object: a reference to the object created/fetched outside the transaction
- returns: the `NSManagedObject` instance if the object exists in the transaction, or `nil` if not found.
*/
@warn_unused_result
public func fetchExisting<T: NSManagedObject>(_ object: T) -> T? {
do {
@@ -56,7 +55,6 @@ public extension BaseDataTransaction {
- parameter objectID: the `NSManagedObjectID` for the object
- returns: the `NSManagedObject` instance if the object exists in the transaction, or `nil` if not found.
*/
@warn_unused_result
public func fetchExisting<T: NSManagedObject>(_ objectID: NSManagedObjectID) -> T? {
do {
@@ -75,7 +73,6 @@ public extension BaseDataTransaction {
- parameter objects: an array of `NSManagedObject`s created/fetched outside the transaction
- returns: the `NSManagedObject` array for objects that exists in the transaction
*/
@warn_unused_result
public func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == T>(_ objects: S) -> [T] {
return objects.flatMap { (try? self.context.existingObject(with: $0.objectID)) as? T }
@@ -87,7 +84,6 @@ public extension BaseDataTransaction {
- parameter objectIDs: the `NSManagedObjectID` array for the objects
- returns: the `NSManagedObject` array for objects that exists in the transaction
*/
@warn_unused_result
public func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == NSManagedObjectID>(_ objectIDs: S) -> [T] {
return objectIDs.flatMap { (try? self.context.existingObject(with: $0)) as? T }
@@ -100,7 +96,6 @@ public extension BaseDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
return self.fetchOne(from, fetchClauses)
@@ -113,7 +108,6 @@ public extension BaseDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
CoreStore.assert(
@@ -130,7 +124,6 @@ public extension BaseDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
return self.fetchAll(from, fetchClauses)
@@ -143,7 +136,6 @@ public extension BaseDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
CoreStore.assert(
@@ -160,7 +152,6 @@ public extension BaseDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
return self.fetchCount(from, fetchClauses)
@@ -173,7 +164,6 @@ public extension BaseDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
CoreStore.assert(
@@ -191,7 +181,6 @@ public extension BaseDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
return self.fetchObjectID(from, fetchClauses)
@@ -204,7 +193,6 @@ public extension BaseDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
CoreStore.assert(
@@ -221,7 +209,6 @@ public extension BaseDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
return self.fetchObjectIDs(from, fetchClauses)
@@ -234,7 +221,6 @@ public extension BaseDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
CoreStore.assert(
@@ -251,6 +237,7 @@ public extension BaseDataTransaction {
- parameter deleteClauses: a series of `DeleteClause` instances for the delete request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the number of `NSManagedObject`s deleted
*/
@discardableResult
public func deleteAll<T: NSManagedObject>(_ from: From<T>, _ deleteClauses: DeleteClause...) -> Int? {
CoreStore.assert(
@@ -268,6 +255,7 @@ public extension BaseDataTransaction {
- parameter deleteClauses: a series of `DeleteClause` instances for the delete request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the number of `NSManagedObject`s deleted
*/
@discardableResult
public func deleteAll<T: NSManagedObject>(_ from: From<T>, _ deleteClauses: [DeleteClause]) -> Int? {
CoreStore.assert(
@@ -288,7 +276,6 @@ public extension BaseDataTransaction {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
CoreStore.assert(
@@ -309,7 +296,6 @@ public extension BaseDataTransaction {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
CoreStore.assert(
@@ -330,7 +316,6 @@ public extension BaseDataTransaction {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[NSString: AnyObject]]? {
CoreStore.assert(
@@ -351,7 +336,6 @@ public extension BaseDataTransaction {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[NSString: AnyObject]]? {
CoreStore.assert(

View File

@@ -32,7 +32,7 @@ import CoreData
/**
A `From` clause specifies the source entity and source persistent store for fetch and query methods. A common usage is to just indicate the entity:
```
let person = transaction.fetchOne(From(MyPersonEntity))
let person = transaction.fetchOne(From<MyPersonEntity>())
```
For cases where multiple `NSPersistentStore`s contain the same entity, the source configuration's name needs to be specified as well:
```
@@ -88,7 +88,7 @@ public struct From<T: NSManagedObject> {
CoreStore.assert(
entityClass is T.Type,
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
"Attempted to create generic type \(cs_typeName(From<T>.self)) with entity class \(cs_typeName(entityClass))"
)
self.init(entityClass: entityClass, configurations: nil)
}
@@ -163,7 +163,7 @@ public struct From<T: NSManagedObject> {
CoreStore.assert(
entityClass is T.Type,
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
"Attempted to create generic type \(cs_typeName(From<T>.self)) with entity class \(cs_typeName(entityClass))"
)
self.init(entityClass: entityClass, configurations: [configuration] + otherConfigurations)
}
@@ -181,7 +181,7 @@ public struct From<T: NSManagedObject> {
CoreStore.assert(
entityClass is T.Type,
"Attempted to create generic type \(cs_typeName(From<T>)) with entity class \(cs_typeName(entityClass))"
"Attempted to create generic type \(cs_typeName(From<T>.self)) with entity class \(cs_typeName(entityClass))"
)
self.init(entityClass: entityClass, configurations: configurations)
}
@@ -189,7 +189,6 @@ public struct From<T: NSManagedObject> {
// MARK: Internal
@warn_unused_result
internal func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>, context: NSManagedObjectContext, applyAffectedStores: Bool = true) -> Bool {
fetchRequest.entity = context.entityDescriptionForEntityClass(self.entityClass)

View File

@@ -96,7 +96,6 @@ public struct GroupBy: QueryClause, Hashable {
// MARK: - GroupBy: Equatable
@warn_unused_result
public func == (lhs: GroupBy, rhs: GroupBy) -> Bool {
return lhs.keyPaths == rhs.keyPaths

View File

@@ -27,12 +27,12 @@ import Foundation
import CoreData
public func +(left: OrderBy, right: OrderBy) -> OrderBy {
public func + (left: OrderBy, right: OrderBy) -> OrderBy {
return OrderBy(left.sortDescriptors + right.sortDescriptors)
}
public func +=(left: inout OrderBy, right: OrderBy) {
public func += (left: inout OrderBy, right: OrderBy) {
left = left + right
}
@@ -163,7 +163,6 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
// MARK: - OrderBy: Equatable
@warn_unused_result
public func == (lhs: OrderBy, rhs: OrderBy) -> Bool {
return lhs.sortDescriptors == rhs.sortDescriptors

View File

@@ -70,15 +70,15 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute. A shorter way to do the same is to assign from the string keypath directly:
```
let fullName = CoreStore.queryValue(
From(MyPersonEntity),
Select<String>(.Attribute("fullName")),
From<MyPersonEntity>(),
Select<String>(.attribute("fullName")),
Where("employeeID", isEqualTo: 1111)
)
```
is equivalent to:
```
let fullName = CoreStore.queryValue(
From(MyPersonEntity),
From<MyPersonEntity>(),
Select<String>("fullName"),
Where("employeeID", isEqualTo: 1111)
)
@@ -96,8 +96,8 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
Provides a `SelectTerm` to a `Select` clause for querying the average value of an attribute.
```
let averageAge = CoreStore.queryValue(
From(MyPersonEntity),
Select<Int>(.Average("age"))
From<MyPersonEntity>(),
Select<Int>(.average("age"))
)
```
@@ -119,8 +119,8 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
Provides a `SelectTerm` to a `Select` clause for a count query.
```
let numberOfEmployees = CoreStore.queryValue(
From(MyPersonEntity),
Select<Int>(.Count("employeeID"))
From<MyPersonEntity>(),
Select<Int>(.count("employeeID"))
)
```
@@ -142,8 +142,8 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
Provides a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute.
```
let maximumAge = CoreStore.queryValue(
From(MyPersonEntity),
Select<Int>(.Maximum("age"))
From<MyPersonEntity>(),
Select<Int>(.maximum("age"))
)
```
@@ -165,8 +165,8 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
Provides a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute.
```
let minimumAge = CoreStore.queryValue(
From(MyPersonEntity),
Select<Int>(.Minimum("age"))
From<MyPersonEntity>(),
Select<Int>(.minimum("age"))
)
```
@@ -188,8 +188,8 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
Provides a `SelectTerm` to a `Select` clause for querying the sum value for an attribute.
```
let totalAge = CoreStore.queryValue(
From(MyPersonEntity),
Select<Int>(.Sum("age"))
From<MyPersonEntity>(),
Select<Int>(.sum("age"))
)
```
@@ -211,7 +211,7 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
Provides a `SelectTerm` to a `Select` clause for querying the `NSManagedObjectID`.
```
let objectID = CoreStore.queryValue(
From(MyPersonEntity),
From<MyPersonEntity>(),
Select<NSManagedObjectID>(),
Where("employeeID", isEqualTo: 1111)
)
@@ -276,7 +276,6 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
// MARK: - SelectTerm: Equatable
@warn_unused_result
public func == (lhs: SelectTerm, rhs: SelectTerm) -> Bool {
switch (lhs, rhs) {
@@ -308,15 +307,15 @@ public func == (lhs: SelectTerm, rhs: SelectTerm) -> Bool {
You can bind the return type by specializing the initializer:
```
let maximumAge = CoreStore.queryValue(
From(MyPersonEntity),
Select<Int>(.Maximum("age"))
From<MyPersonEntity>(),
Select<Int>(.maximum("age"))
)
```
or by casting the type of the return value:
```
let maximumAge: Int = CoreStore.queryValue(
From(MyPersonEntity),
Select(.Maximum("age"))
From<MyPersonEntity>(),
Select(.maximum("age"))
)
```
Valid return types depend on the query:
@@ -395,7 +394,6 @@ public extension Select where T: NSManagedObjectID {
// MARK: - Select: Equatable
@warn_unused_result
public func == <T: SelectResultType, U: SelectResultType>(lhs: Select<T>, rhs: Select<U>) -> Bool {
return lhs.selectTerms == rhs.selectTerms
@@ -573,6 +571,38 @@ extension String: SelectValueResultType {
}
// MARK: - Date: SelectValueResultType
extension Date: SelectValueResultType {
public static var attributeType: NSAttributeType {
return .dateAttributeType
}
public static func fromResultObject(_ result: AnyObject) -> Date? {
return result as? Date
}
}
// MARK: - Data: SelectValueResultType
extension Data: SelectValueResultType {
public static var attributeType: NSAttributeType {
return .binaryDataAttributeType
}
public static func fromResultObject(_ result: AnyObject) -> Data? {
return result as? Data
}
}
// MARK: - NSNumber: SelectValueResultType
extension NSNumber: SelectValueResultType {
@@ -635,32 +665,40 @@ extension NSDecimalNumber {
// MARK: - NSDate: SelectValueResultType
extension Date: SelectValueResultType {
extension NSDate: SelectValueResultType {
public static var attributeType: NSAttributeType {
return .dateAttributeType
}
public static func fromResultObject(_ result: AnyObject) -> Date? {
public class func fromResultObject(_ result: AnyObject) -> Self? {
return result as? Date
func forceCast<T: NSDate>(_ object: AnyObject) -> T? {
return (object as? T)
}
return forceCast(result)
}
}
// MARK: - NSData: SelectValueResultType
extension Data: SelectValueResultType {
extension NSData: SelectValueResultType {
public static var attributeType: NSAttributeType {
return .binaryDataAttributeType
}
public static func fromResultObject(_ result: AnyObject) -> Data? {
public class func fromResultObject(_ result: AnyObject) -> Self? {
return result as? Data
func forceCast<T: NSData>(_ object: AnyObject) -> T? {
return (object as? T)
}
return forceCast(result)
}
}

View File

@@ -34,7 +34,7 @@ import CoreData
Sample usage:
```
let employees = transaction.fetchAll(
From(MyPersonEntity),
From<MyPersonEntity>(),
Tweak { (fetchRequest) -> Void in
fetchRequest.includesPendingChanges = false
fetchRequest.fetchLimit = 5

View File

@@ -27,17 +27,17 @@ import Foundation
import CoreData
public func &&(left: Where, right: Where) -> Where {
public func && (left: Where, right: Where) -> Where {
return Where(CompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate]))
}
public func ||(left: Where, right: Where) -> Where {
public func || (left: Where, right: Where) -> Where {
return Where(CompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate]))
}
public prefix func !(clause: Where) -> Where {
public prefix func ! (clause: Where) -> Where {
return Where(CompoundPredicate(type: .not, subpredicates: [clause.predicate]))
}
@@ -168,7 +168,6 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
// MARK: - Where: Equatable
@warn_unused_result
public func == (lhs: Where, rhs: Where) -> Bool {
return lhs.predicate == rhs.predicate

View File

@@ -37,7 +37,6 @@ public extension CoreStore {
- parameter object: a reference to the object created/fetched outside the `DataStack`
- returns: the `NSManagedObject` instance if the object exists in the `DataStack`, or `nil` if not found.
*/
@warn_unused_result
public static func fetchExisting<T: NSManagedObject>(_ object: T) -> T? {
return self.defaultStack.fetchExisting(object)
@@ -49,7 +48,6 @@ public extension CoreStore {
- parameter objectID: the `NSManagedObjectID` for the object
- returns: the `NSManagedObject` instance if the object exists in the `DataStack`, or `nil` if not found.
*/
@warn_unused_result
public static func fetchExisting<T: NSManagedObject>(_ objectID: NSManagedObjectID) -> T? {
return self.defaultStack.fetchExisting(objectID)
@@ -61,7 +59,6 @@ public extension CoreStore {
- parameter objects: an array of `NSManagedObject`s created/fetched outside the `DataStack`
- returns: the `NSManagedObject` array for objects that exists in the `DataStack`
*/
@warn_unused_result
public static func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == T>(_ objects: S) -> [T] {
return self.defaultStack.fetchExisting(objects)
@@ -73,7 +70,6 @@ public extension CoreStore {
- parameter objectIDs: the `NSManagedObjectID` array for the objects
- returns: the `NSManagedObject` array for objects that exists in the `DataStack`
*/
@warn_unused_result
public static func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == NSManagedObjectID>(_ objectIDs: S) -> [T] {
return self.defaultStack.fetchExisting(objectIDs)
@@ -86,7 +82,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public static func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
return self.defaultStack.fetchOne(from, fetchClauses)
@@ -99,7 +94,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public static func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
return self.defaultStack.fetchOne(from, fetchClauses)
@@ -112,7 +106,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public static func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
return self.defaultStack.fetchAll(from, fetchClauses)
@@ -125,7 +118,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public static func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
return self.defaultStack.fetchAll(from, fetchClauses)
@@ -138,7 +130,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public static func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
return self.defaultStack.fetchCount(from, fetchClauses)
@@ -151,7 +142,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public static func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
return self.defaultStack.fetchCount(from, fetchClauses)
@@ -164,7 +154,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public static func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
return self.defaultStack.fetchObjectID(from, fetchClauses)
@@ -177,7 +166,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public static func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
return self.defaultStack.fetchObjectID(from, fetchClauses)
@@ -190,7 +178,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public static func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
return self.defaultStack.fetchObjectIDs(from, fetchClauses)
@@ -203,7 +190,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public static func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
return self.defaultStack.fetchObjectIDs(from, fetchClauses)
@@ -219,7 +205,6 @@ public extension CoreStore {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public static func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
return self.defaultStack.queryValue(from, selectClause, queryClauses)
@@ -235,7 +220,6 @@ public extension CoreStore {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public static func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
return self.defaultStack.queryValue(from, selectClause, queryClauses)
@@ -251,7 +235,6 @@ public extension CoreStore {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public static func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[NSString: AnyObject]]? {
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
@@ -267,7 +250,6 @@ public extension CoreStore {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public static func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[NSString: AnyObject]]? {
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)

View File

@@ -40,7 +40,6 @@ public extension DataStack {
- parameter object: a reference to the object created/fetched outside the `DataStack`
- returns: the `NSManagedObject` instance if the object exists in the `DataStack`, or `nil` if not found.
*/
@warn_unused_result
public func fetchExisting<T: NSManagedObject>(_ object: T) -> T? {
do {
@@ -59,7 +58,6 @@ public extension DataStack {
- parameter objectID: the `NSManagedObjectID` for the object
- returns: the `NSManagedObject` instance if the object exists in the `DataStack`, or `nil` if not found.
*/
@warn_unused_result
public func fetchExisting<T: NSManagedObject>(_ objectID: NSManagedObjectID) -> T? {
do {
@@ -78,7 +76,6 @@ public extension DataStack {
- parameter objects: an array of `NSManagedObject`s created/fetched outside the `DataStack`
- returns: the `NSManagedObject` array for objects that exists in the `DataStack`
*/
@warn_unused_result
public func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == T>(_ objects: S) -> [T] {
return objects.flatMap { (try? self.mainContext.existingObject(with: $0.objectID)) as? T }
@@ -90,7 +87,6 @@ public extension DataStack {
- parameter objectIDs: the `NSManagedObjectID` array for the objects
- returns: the `NSManagedObject` array for objects that exists in the `DataStack`
*/
@warn_unused_result
public func fetchExisting<T: NSManagedObject, S: Sequence where S.Iterator.Element == NSManagedObjectID>(_ objectIDs: S) -> [T] {
return objectIDs.flatMap { (try? self.mainContext.existingObject(with: $0)) as? T }
@@ -103,7 +99,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> T? {
CoreStore.assert(
@@ -120,7 +115,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the first `NSManagedObject` instance that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public func fetchOne<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> T? {
CoreStore.assert(
@@ -137,7 +131,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [T]? {
CoreStore.assert(
@@ -154,7 +147,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: all `NSManagedObject` instances that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchAll<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [T]? {
CoreStore.assert(
@@ -171,7 +163,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> Int? {
CoreStore.assert(
@@ -188,7 +179,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the number `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchCount<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> Int? {
CoreStore.assert(
@@ -205,7 +195,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> NSManagedObjectID? {
CoreStore.assert(
@@ -222,7 +211,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `FetchClause`s
*/
@warn_unused_result
public func fetchObjectID<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID? {
CoreStore.assert(
@@ -239,7 +227,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> [NSManagedObjectID]? {
CoreStore.assert(
@@ -256,7 +243,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `FetchClause`s
*/
@warn_unused_result
public func fetchObjectIDs<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]? {
CoreStore.assert(
@@ -276,7 +262,6 @@ public extension DataStack {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
CoreStore.assert(
@@ -296,7 +281,6 @@ public extension DataStack {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
CoreStore.assert(
@@ -316,7 +300,6 @@ public extension DataStack {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[NSString: AnyObject]]? {
CoreStore.assert(
@@ -336,7 +319,6 @@ public extension DataStack {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/
@warn_unused_result
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[NSString: AnyObject]]? {
CoreStore.assert(

View File

@@ -47,8 +47,8 @@ public extension BaseDataTransaction {
self.isRunningInAllowedQueue(),
"Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue."
)
return try cs_autoreleasepool {
return try autoreleasepool {
guard T.shouldInsertFromImportSource(source, inTransaction: self) else {
@@ -77,7 +77,7 @@ public extension BaseDataTransaction {
"Attempted to import an object of type \(cs_typeName(object)) outside the transaction's designated queue."
)
try cs_autoreleasepool {
try autoreleasepool {
guard T.shouldInsertFromImportSource(source, inTransaction: self) else {
@@ -105,7 +105,7 @@ public extension BaseDataTransaction {
"Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue."
)
return try cs_autoreleasepool {
return try autoreleasepool {
return try sourceArray.flatMap { (source) -> T? in
@@ -114,7 +114,7 @@ public extension BaseDataTransaction {
return nil
}
return try cs_autoreleasepool {
return try autoreleasepool {
let object = self.create(into)
try object.didInsertFromImportSource(source, inTransaction: self)
@@ -141,7 +141,7 @@ public extension BaseDataTransaction {
"Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue."
)
return try cs_autoreleasepool {
return try autoreleasepool {
let uniqueIDKeyPath = T.uniqueIDKeyPath
guard let uniqueIDValue = try T.uniqueIDFromImportSource(source, inTransaction: self) else {
@@ -149,7 +149,7 @@ public extension BaseDataTransaction {
return nil
}
if let object = self.fetchOne(From(T), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) {
if let object = self.fetchOne(From<T>(), Where(uniqueIDKeyPath, isEqualTo: uniqueIDValue)) {
guard T.shouldUpdateFromImportSource(source, inTransaction: self) else {
@@ -187,17 +187,17 @@ public extension BaseDataTransaction {
public func importUniqueObjects<T, S: Sequence where T: NSManagedObject, T: ImportableUniqueObject, S.Iterator.Element == T.ImportSource>(
_ into: Into<T>,
sourceArray: S,
@noescape preProcess: (mapping: [T.UniqueIDType: T.ImportSource]) throws -> [T.UniqueIDType: T.ImportSource] = { $0 }) throws -> [T] {
preProcess: @noescape (mapping: [T.UniqueIDType: T.ImportSource]) throws -> [T.UniqueIDType: T.ImportSource] = { $0 }) throws -> [T] {
CoreStore.assert(
self.isRunningInAllowedQueue(),
"Attempted to import an object of type \(cs_typeName(into.entityClass)) outside the transaction's designated queue."
)
return try cs_autoreleasepool {
return try autoreleasepool {
var mapping = Dictionary<T.UniqueIDType, T.ImportSource>()
let sortedIDs = try cs_autoreleasepool {
let sortedIDs = try autoreleasepool {
return try sourceArray.flatMap { (source) -> T.UniqueIDType? in
@@ -211,12 +211,12 @@ public extension BaseDataTransaction {
}
}
mapping = try cs_autoreleasepool { try preProcess(mapping: mapping) }
mapping = try autoreleasepool { try preProcess(mapping: mapping) }
var objects = Dictionary<T.UniqueIDType, T>()
for object in self.fetchAll(From(T), Where(T.uniqueIDKeyPath, isMemberOf: sortedIDs)) ?? [] {
for object in self.fetchAll(From<T>(), Where(T.uniqueIDKeyPath, isMemberOf: sortedIDs)) ?? [] {
try cs_autoreleasepool {
try autoreleasepool {
let uniqueIDValue = object.uniqueIDValue
@@ -233,7 +233,7 @@ public extension BaseDataTransaction {
for (uniqueIDValue, source) in mapping {
try cs_autoreleasepool {
try autoreleasepool {
guard T.shouldInsertFromImportSource(source, inTransaction: self) else {

View File

@@ -40,7 +40,7 @@ import CoreData
CoreStore.beginAsynchronous { (transaction) -> Void in
let json: NSDictionary = // ...
let person = try! transaction.importObject(
Into(MyPersonEntity),
Into<MyPersonEntity>(),
source: json
)
// ...

View File

@@ -41,7 +41,7 @@ import CoreData
CoreStore.beginAsynchronous { (transaction) -> Void in
let json: NSDictionary = // ...
let person = try! transaction.importUniqueObject(
Into(MyPersonEntity),
Into<MyPersonEntity>(),
source: json
)
// ...

View File

@@ -55,7 +55,7 @@ internal final class CoreStoreFetchedResultsController: NSFetchedResultsControll
context: context,
applyAffectedStores: false
)
applyFetchClauses(fetchRequest: fetchRequest.cs_dynamicCast())
applyFetchClauses(fetchRequest: unsafeBitCast(fetchRequest, to: NSFetchRequest<NSManagedObject>.self))
if let from = from {

View File

@@ -47,7 +47,7 @@ internal protocol FetchedResultsControllerHandler: class {
// MARK: - FetchedResultsControllerDelegate
internal final class FetchedResultsControllerDelegate<EntityType: NSManagedObject>: NSObject, NSFetchedResultsControllerDelegate {
internal final class FetchedResultsControllerDelegate<EntityType: NSManagedObject>: NSObject, NSFetchedResultsControllerDelegate {
// MARK: Internal

View File

@@ -25,68 +25,7 @@
import Foundation
// MARK: - Custom AutoreleasePool
internal func cs_autoreleasepool(@noescape _ closure: () -> Void) {
autoreleasepool(closure)
}
internal func cs_autoreleasepool<T>(@noescape _ closure: () -> T) -> T {
var closureValue: T!
autoreleasepool {
closureValue = closure()
}
return closureValue
}
internal func cs_autoreleasepool<T>(@noescape _ closure: () throws -> T) throws -> T {
var closureValue: T!
var closureError: ErrorProtocol?
autoreleasepool {
do {
closureValue = try closure()
}
catch {
closureError = error
}
}
if let closureError = closureError {
throw closureError
}
return closureValue
}
internal func cs_autoreleasepool(@noescape _ closure: () throws -> Void) throws {
var closureError: ErrorProtocol?
autoreleasepool {
do {
try closure()
}
catch {
closureError = error
}
}
if let closureError = closureError {
throw closureError
}
}
// MARK: Associated Objects
internal func cs_getAssociatedObjectForKey<T: AnyObject>(_ key: UnsafePointer<Void>, inObject object: AnyObject) -> T? {

View File

@@ -56,7 +56,7 @@ internal final class MigrationManager: NSMigrationManager, ProgressReporting {
}
// MARK: NSProgressReporting
// MARK: ProgressReporting
let progress: Progress
}

View File

@@ -1,20 +0,0 @@
//
// NSFetchRequest+CoreStore.swift
// CoreStore
//
// Created by John Rommel Estropia on 2016/07/20.
// Copyright © 2016 John Rommel Estropia. All rights reserved.
//
import CoreData
internal extension NSFetchRequest {
// MARK: Internal
@nonobjc
internal func cs_dynamicCast<U: NSFetchRequestResult>() -> NSFetchRequest<U> {
return unsafeBitCast(self, to: NSFetchRequest<U>.self)
}
}

View File

@@ -78,20 +78,10 @@ internal extension NSManagedObjectContext {
@nonobjc
internal func setupForCoreStoreWithContextName(_ contextName: String) {
#if USE_FRAMEWORKS
self.name = contextName
#else
if #available(iOS 8.0, *) {
self.name = contextName
}
#endif
self.name = contextName
self.observerForWillSaveNotification = NotificationObserver(
notificationName: NSNotification.Name.NSManagedObjectContextWillSave.rawValue,
notificationName: NSNotification.Name.NSManagedObjectContextWillSave,
object: self,
closure: { (note) -> Void in

View File

@@ -199,7 +199,7 @@ internal extension NSManagedObjectContext {
}
@nonobjc
internal func fetchCount<T: NSManagedObject>(_ fetchRequest: NSFetchRequest<T>) -> Int? {
internal func fetchCount(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> Int? {
var count = 0
var countError: ErrorProtocol?
@@ -366,7 +366,7 @@ internal extension NSManagedObjectContext {
var fetchError: ErrorProtocol?
self.performAndWait {
cs_autoreleasepool {
autoreleasepool {
do {

View File

@@ -72,16 +72,18 @@ internal extension NSManagedObjectContext {
#if os(iOS) || os(OSX)
context.observerForDidImportUbiquitousContentChangesNotification = NotificationObserver(
notificationName: NSNotification.Name.NSPersistentStoreDidImportUbiquitousContentChanges.rawValue,
notificationName: NSNotification.Name.NSPersistentStoreDidImportUbiquitousContentChanges,
object: coordinator,
closure: { [weak context] (note) -> Void in
context?.perform { () -> Void in
let updatedObjectIDs = ((note as NSNotification).userInfo?[NSUpdatedObjectsKey] as? Set<NSManagedObjectID>) ?? []
for objectID in updatedObjectIDs {
if let updatedObjectIDs = (note.userInfo?[NSUpdatedObjectsKey] as? Set<NSManagedObjectID>) {
context?.object(with: objectID).willAccessValue(forKey: nil)
for objectID in updatedObjectIDs {
context?.object(with: objectID).willAccessValue(forKey: nil)
}
}
context?.mergeChanges(fromContextDidSave: note)
}
@@ -102,7 +104,7 @@ internal extension NSManagedObjectContext {
context.undoManager = nil
context.setupForCoreStoreWithContextName("com.corestore.maincontext")
context.observerForDidSaveNotification = NotificationObserver(
notificationName: NSNotification.Name.NSManagedObjectContextDidSave.rawValue,
notificationName: NSNotification.Name.NSManagedObjectContextDidSave,
object: rootContext,
closure: { [weak context] (note) -> Void in
@@ -113,10 +115,12 @@ internal extension NSManagedObjectContext {
}
let mergeChanges = { () -> Void in
let updatedObjects = ((note as NSNotification).userInfo?[NSUpdatedObjectsKey] as? Set<NSManagedObject>) ?? []
for object in updatedObjects {
if let updatedObjects = (note.userInfo?[NSUpdatedObjectsKey] as? Set<NSManagedObject>) {
context.object(with: object.objectID).willAccessValue(forKey: nil)
for object in updatedObjects {
context.object(with: object.objectID).willAccessValue(forKey: nil)
}
}
context.mergeChanges(fromContextDidSave: note)
}

View File

@@ -47,7 +47,7 @@ internal extension NSManagedObjectModel {
guard let versionInfo = NSDictionary(contentsOf: versionInfoPlistURL),
let versionHashes = versionInfo["NSManagedObjectModel_VersionHashes"] as? [String: AnyObject] else {
CoreStore.abort("Could not load \(cs_typeName(NSManagedObjectModel)) metadata from path \"\(versionInfoPlistURL)\".")
CoreStore.abort("Could not load \(cs_typeName(NSManagedObjectModel.self)) metadata from path \"\(versionInfoPlistURL)\".")
}
let modelVersions = Set(versionHashes.keys)
@@ -106,7 +106,7 @@ internal extension NSManagedObjectModel {
return rootModel
}
CoreStore.abort("Could not create an \(cs_typeName(NSManagedObjectModel)) from the model at URL \"\(modelFileURL)\".")
CoreStore.abort("Could not create an \(cs_typeName(NSManagedObjectModel.self)) from the model at URL \"\(modelFileURL)\".")
}
@nonobjc

View File

@@ -32,16 +32,16 @@ internal final class NotificationObserver {
// MARK: Public
let notificationName: String
let notificationName: Notification.Name
let object: AnyObject?
let observer: NSObjectProtocol
init(notificationName: String, object: AnyObject?, queue: OperationQueue? = nil, closure: (note: Notification) -> Void) {
init(notificationName: Notification.Name, object: AnyObject?, queue: OperationQueue? = nil, closure: (note: Notification) -> Void) {
self.notificationName = notificationName
self.object = object
self.observer = NotificationCenter.default.addObserver(
forName: NSNotification.Name(rawValue: notificationName),
forName: notificationName,
object: object,
queue: queue,
using: closure
@@ -52,7 +52,7 @@ internal final class NotificationObserver {
NotificationCenter.default.removeObserver(
self.observer,
name: NSNotification.Name(rawValue: self.notificationName),
name: self.notificationName,
object: self.object
)
}

View File

@@ -710,7 +710,7 @@ extension SelectTerm: CustomDebugStringConvertible, CoreStoreDebugStringConverti
case ._attribute(let keyPath):
return createFormattedString(
".Attribute (", ")",
".attribute (", ")",
("keyPath", keyPath)
)

View File

@@ -43,7 +43,7 @@ public enum LogLevel {
// MARK: - CoreStoreLogger
/**
Custom loggers should implement the `CoreStoreLogger` protocol and pass its instance to `CoreStore.logger`. Calls to `log(...)`, `handleError(...)`, and `assert(...)` are not tied to a specific queue/thread, so it is the implementer's job to handle thread-safety.
Custom loggers should implement the `CoreStoreLogger` protocol and pass its instance to `CoreStore.logger`. Calls to `log(...)`, `assert(...)`, and `abort(...)` are not tied to a specific queue/thread, so it is the implementer's job to handle thread-safety.
*/
public protocol CoreStoreLogger {

View File

@@ -30,10 +30,6 @@ import Foundation
/**
The `DefaultLogger` is a basic implementation of the `CoreStoreLogger` protocol.
- The `log(...)` method calls `print(...)` to print the level, source file name, line number, function name, and the log message.
- The `handleError(...)` method calls `print(...)` to print the source file name, line number, function name, and the error message.
- The `assert(...)` method calls `assert(...)` on the arguments.
*/
public final class DefaultLogger: CoreStoreLogger {

View File

@@ -41,15 +41,15 @@ public extension CoreStore {
InMemoryStore.self,
completion: { result in
switch result {
case .Success(let storage): // ...
case .Failure(let error): // ...
case .success(let storage): // ...
case .failure(let error): // ...
}
}
)
```
- parameter storeType: the storage type
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.Success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
*/
public static func addStorage<T: StorageInterface where T: DefaultInitializableStore>(_ storeType: T.Type, completion: (SetupResult<T>) -> Void) {
@@ -63,15 +63,15 @@ public extension CoreStore {
InMemoryStore(configuration: "Config1"),
completion: { result in
switch result {
case .Success(let storage): // ...
case .Failure(let error): // ...
case .success(let storage): // ...
case .failure(let error): // ...
}
}
)
```
- parameter storage: the storage
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.Success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
*/
public static func addStorage<T: StorageInterface>(_ storage: T, completion: (SetupResult<T>) -> Void) {
@@ -85,15 +85,15 @@ public extension CoreStore {
SQLiteStore.self,
completion: { result in
switch result {
case .Success(let storage): // ...
case .Failure(let error): // ...
case .success(let storage): // ...
case .failure(let error): // ...
}
}
)
```
- parameter storeType: the local storage type
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.Success` 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.
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.success` 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.
- returns: an `NSProgress` instance if a migration has started, or `nil` if either no migrations are required or if a failure occured.
*/
public static func addStorage<T: LocalStorage where T: DefaultInitializableStore>(_ storeType: T.Type, completion: (SetupResult<T>) -> Void) -> Progress? {
@@ -108,15 +108,15 @@ public extension CoreStore {
SQLiteStore(fileName: "core_data.sqlite", configuration: "Config1"),
completion: { result in
switch result {
case .Success(let storage): // ...
case .Failure(let error): // ...
case .success(let storage): // ...
case .failure(let error): // ...
}
}
)
```
- parameter storage: the local storage
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.Success` 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.
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.success` 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.
- returns: an `NSProgress` instance if a migration has started, or `nil` if either no migrations are required or if a failure occured.
*/
public static func addStorage<T: LocalStorage>(_ storage: T, completion: (SetupResult<T>) -> Void) -> Progress? {
@@ -142,15 +142,15 @@ public extension CoreStore {
storage,
completion: { result in
switch result {
case .Success(let storage): // ...
case .Failure(let error): // ...
case .success(let storage): // ...
case .failure(let error): // ...
}
}
)
```
- parameter storage: the cloud storage
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `CloudStorage` associated to the `SetupResult.Success` 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.
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `CloudStorage` associated to the `SetupResult.success` 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.
*/
public static func addStorage<T: CloudStorage>(_ storage: T, completion: (SetupResult<T>) -> Void) {
@@ -161,7 +161,7 @@ public extension CoreStore {
Migrates a local storage to match the `defaultStack`'s managed object model version. This method does NOT add the migrated store to the data stack.
- parameter storage: the local storage
- parameter completion: the closure to be executed on the main queue when the migration completes, either due to success or failure. The closure's `MigrationResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a `.Failure` result if an error occurs asynchronously.
- parameter completion: the closure to be executed on the main queue when the migration completes, either due to success or failure. The closure's `MigrationResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a `.failure` result if an error occurs asynchronously.
- throws: a `CoreStoreError` value indicating the failure
- returns: an `NSProgress` instance if a migration has started, or `nil` is no migrations are required
*/
@@ -177,7 +177,6 @@ public extension CoreStore {
- throws: a `CoreStoreError` value indicating the failure
- returns: a `MigrationType` array indicating the migration steps required for the store, or an empty array if the file does not exist yet. Otherwise, an error is thrown if either inspection of the store failed, or if no mapping model was found/inferred.
*/
@warn_unused_result
public static func requiredMigrationsForStorage<T: LocalStorage>(_ storage: T) throws -> [MigrationType] {
return try self.defaultStack.requiredMigrationsForStorage(storage)

View File

@@ -41,15 +41,15 @@ public extension DataStack {
InMemoryStore.self,
completion: { result in
switch result {
case .Success(let storage): // ...
case .Failure(let error): // ...
case .success(let storage): // ...
case .failure(let error): // ...
}
}
)
```
- parameter storeType: the storage type
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.Success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
*/
public func addStorage<T: StorageInterface where T: DefaultInitializableStore>(_ storeType: T.Type, completion: (SetupResult<T>) -> Void) {
@@ -63,15 +63,15 @@ public extension DataStack {
InMemoryStore(configuration: "Config1"),
completion: { result in
switch result {
case .Success(let storage): // ...
case .Failure(let error): // ...
case .success(let storage): // ...
case .failure(let error): // ...
}
}
)
```
- parameter storage: the storage
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.Success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `StorageInterface` associated to the `SetupResult.success` may not always be the same instance as the parameter argument if a previous `StorageInterface` was already added at the same URL and with the same configuration.
*/
public func addStorage<T: StorageInterface>(_ storage: T, completion: (SetupResult<T>) -> Void) {
@@ -88,7 +88,7 @@ public extension DataStack {
do {
try self.createPersistentStoreFromStorage(
_ = try self.createPersistentStoreFromStorage(
storage,
finalURL: nil,
finalStoreOptions: storage.storeOptions
@@ -121,15 +121,15 @@ public extension DataStack {
SQLiteStore.self,
completion: { result in
switch result {
case .Success(let storage): // ...
case .Failure(let error): // ...
case .success(let storage): // ...
case .failure(let error): // ...
}
}
)
```
- parameter storeType: the local storage type
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.Success` 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.
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.success` 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.
- returns: an `NSProgress` instance if a migration has started, or `nil` if either no migrations are required or if a failure occured.
*/
public func addStorage<T: LocalStorage where T: DefaultInitializableStore>(_ storeType: T.Type, completion: (SetupResult<T>) -> Void) -> Progress? {
@@ -144,15 +144,15 @@ public extension DataStack {
SQLiteStore(fileName: "core_data.sqlite", configuration: "Config1"),
completion: { result in
switch result {
case .Success(let storage): // ...
case .Failure(let error): // ...
case .success(let storage): // ...
case .failure(let error): // ...
}
}
)
```
- parameter storage: the local storage
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.Success` 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.
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `LocalStorage` associated to the `SetupResult.success` 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.
- returns: an `NSProgress` instance if a migration has started, or `nil` if either no migrations are required or if a failure occured.
*/
public func addStorage<T: LocalStorage>(_ storage: T, completion: (SetupResult<T>) -> Void) -> Progress? {
@@ -310,15 +310,15 @@ public extension DataStack {
storage,
completion: { result in
switch result {
case .Success(let storage): // ...
case .Failure(let error): // ...
case .success(let storage): // ...
case .failure(let error): // ...
}
}
)
```
- parameter storage: the cloud storage
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `CloudStorage` associated to the `SetupResult.Success` 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.
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. Note that the `CloudStorage` associated to the `SetupResult.success` 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.
*/
public func addStorage<T: CloudStorage>(_ storage: T, completion: (SetupResult<T>) -> Void) {
@@ -421,7 +421,7 @@ public extension DataStack {
let storeError = CoreStoreError(error)
CoreStore.log(
storeError,
"Failed to load \(cs_typeName(NSPersistentStore)) metadata."
"Failed to load \(cs_typeName(NSPersistentStore.self)) metadata."
)
GCDQueue.main.async {
@@ -481,7 +481,6 @@ public extension DataStack {
- throws: a `CoreStoreError` value indicating the failure
- returns: a `MigrationType` array indicating the migration steps required for the store, or an empty array if the file does not exist yet. Otherwise, an error is thrown if either inspection of the store failed, or if no mapping model was found/inferred.
*/
@warn_unused_result
public func requiredMigrationsForStorage<T: LocalStorage>(_ storage: T) throws -> [MigrationType] {
return try self.coordinator.performSynchronously {
@@ -614,7 +613,7 @@ public extension DataStack {
return
}
cs_autoreleasepool {
autoreleasepool {
do {
@@ -644,16 +643,7 @@ public extension DataStack {
}
let migrationOperation = BlockOperation()
#if USE_FRAMEWORKS
migrationOperation.qualityOfService = .utility
#else
if #available(iOS 8.0, *) {
migrationOperation.qualityOfService = .utility
}
#endif
migrationOperation.qualityOfService = .utility
operations.forEach { migrationOperation.addDependency($0) }
migrationOperation.addExecutionBlock { () -> Void in

View File

@@ -49,9 +49,9 @@ import Foundation
// ...
let result = transaction.commit()
switch result {
case .Success(let hasChanges):
case .success(let hasChanges):
// hasChanges indicates if there were changes or not
case .Failure(let error):
case .failure(let error):
// error is a CoreStoreError enum value
}
}
@@ -60,12 +60,12 @@ import Foundation
public enum MigrationResult: Boolean, Hashable {
/**
`MigrationResult.Success` indicates either the migration succeeded, or there were no migrations needed. The associated value is an array of `MigrationType`s reflecting the migration steps completed.
`MigrationResult.success` indicates either the migration succeeded, or there were no migrations needed. The associated value is an array of `MigrationType`s reflecting the migration steps completed.
*/
case success([MigrationType])
/**
`SaveResult.Failure` indicates that the migration failed. The associated object for this value is the a `CoreStoreError` enum value.
`SaveResult.failure` indicates that the migration failed. The associated object for this value is the a `CoreStoreError` enum value.
*/
case failure(CoreStoreError)
@@ -119,7 +119,6 @@ public enum MigrationResult: Boolean, Hashable {
// MARK: - SetupResult: Equatable
@warn_unused_result
public func == (lhs: MigrationResult, rhs: MigrationResult) -> Bool {
switch (lhs, rhs) {

View File

@@ -144,7 +144,6 @@ public enum MigrationType: Boolean, Hashable {
// MARK: - MigrationType: Equatable
@warn_unused_result
public func == (lhs: MigrationType, rhs: MigrationType) -> Bool {
switch (lhs, rhs) {

View File

@@ -51,9 +51,9 @@ import CoreData
SQLiteStore(),
completion: { (result: SetupResult) -> Void in
switch result {
case .Success(let storage):
case .success(let storage):
// storage is the related StorageInterface instance
case .Failure(let error):
case .failure(let error):
// error is the CoreStoreError enum value for the failure
}
}
@@ -63,12 +63,12 @@ import CoreData
public enum SetupResult<T: StorageInterface>: Boolean, Hashable {
/**
`SetupResult.Success` indicates that the storage setup succeeded. The associated object for this `enum` value is the related `StorageInterface` instance.
`SetupResult.success` indicates that the storage setup succeeded. The associated object for this `enum` value is the related `StorageInterface` instance.
*/
case success(T)
/**
`SetupResult.Failure` indicates that the storage setup failed. The associated object for this value is the related `CoreStoreError` enum value.
`SetupResult.failure` indicates that the storage setup failed. The associated object for this value is the related `CoreStoreError` enum value.
*/
case failure(CoreStoreError)
@@ -121,7 +121,6 @@ public enum SetupResult<T: StorageInterface>: Boolean, Hashable {
// MARK: - SetupResult: Equatable
@warn_unused_result
public func == <T: StorageInterface, U: StorageInterface>(lhs: SetupResult<T>, rhs: SetupResult<U>) -> Bool {
switch (lhs, rhs) {
@@ -147,12 +146,12 @@ public func == <T: StorageInterface, U: StorageInterface>(lhs: SetupResult<T>, r
public enum PersistentStoreResult: Boolean {
/**
Deprecated. Replaced by `SetupResult.Success` when using the new `addStorage(_:completion:)` method variants.
Deprecated. Replaced by `SetupResult.success` when using the new `addStorage(_:completion:)` method variants.
*/
case success(NSPersistentStore)
/**
Deprecated. Replaced by `SetupResult.Failure` when using the new `addStorage(_:completion:)` method variants.
Deprecated. Replaced by `SetupResult.failure` when using the new `addStorage(_:completion:)` method variants.
*/
case failure(NSError)

View File

@@ -99,7 +99,6 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
@warn_unused_result
public override func editObject(_ object: NSManagedObject?) -> AnyObject? {
return self.bridgeToSwift.edit(object)
@@ -113,7 +112,6 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
@warn_unused_result
public override func editInto(_ into: CSInto, objectID: NSManagedObjectID) -> AnyObject? {
return self.bridgeToSwift.edit(into.bridgeToSwift, objectID)

View File

@@ -67,7 +67,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
@warn_unused_result
public func editObject(_ object: NSManagedObject?) -> AnyObject? {
return self.bridgeToSwift.edit(object)
@@ -81,7 +80,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
@warn_unused_result
public func editInto(_ into: CSInto, objectID: NSManagedObjectID) -> AnyObject? {
return self.bridgeToSwift.edit(into.bridgeToSwift, objectID)
@@ -127,7 +125,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObject`s that were inserted to the transaction.
*/
@objc
@warn_unused_result
public func insertedObjects() -> Set<NSManagedObject> {
return self.bridgeToSwift.insertedObjects()
@@ -140,7 +137,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObject`s of the specified type that were inserted to the transaction.
*/
@objc
@warn_unused_result
public func insertedObjectsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObject> {
return self.bridgeToSwift.insertedObjects(entity)
@@ -152,7 +148,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObjectID`s that were inserted to the transaction.
*/
@objc
@warn_unused_result
public func insertedObjectIDs() -> Set<NSManagedObjectID> {
return self.bridgeToSwift.insertedObjectIDs()
@@ -165,7 +160,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObjectID`s of the specified type that were inserted to the transaction.
*/
@objc
@warn_unused_result
public func insertedObjectIDsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
return self.bridgeToSwift.insertedObjectIDs(entity)
@@ -177,7 +171,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObject`s that were updated to the transaction.
*/
@objc
@warn_unused_result
public func updatedObjects() -> Set<NSManagedObject> {
return self.bridgeToSwift.updatedObjects()
@@ -190,7 +183,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObject`s of the specified type that were updated in the transaction.
*/
@objc
@warn_unused_result
public func updatedObjectsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObject> {
return self.bridgeToSwift.updatedObjects(entity)
@@ -202,7 +194,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObjectID`s that were updated in the transaction.
*/
@objc
@warn_unused_result
public func updatedObjectIDs() -> Set<NSManagedObjectID> {
return self.bridgeToSwift.updatedObjectIDs()
@@ -215,7 +206,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObjectID`s of the specified type that were updated in the transaction.
*/
@objc
@warn_unused_result
public func updatedObjectIDsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
return self.bridgeToSwift.updatedObjectIDs(entity)
@@ -227,7 +217,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObject`s that were deleted from the transaction.
*/
@objc
@warn_unused_result
public func deletedObjects() -> Set<NSManagedObject> {
return self.bridgeToSwift.deletedObjects()
@@ -240,7 +229,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObject`s of the specified type that were deleted from the transaction.
*/
@objc
@warn_unused_result
public func deletedObjectsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObject> {
return self.bridgeToSwift.deletedObjects(entity)
@@ -253,7 +241,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: an `NSSet` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
*/
@objc
@warn_unused_result
public func deletedObjectIDs() -> Set<NSManagedObjectID> {
return self.bridgeToSwift.deletedObjectIDs()
@@ -266,7 +253,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
*/
@objc
@warn_unused_result
public func deletedObjectIDsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
return self.bridgeToSwift.deletedObjectIDs(entity)

View File

@@ -80,6 +80,7 @@ public extension CSCoreStore {
- returns: the `CSInMemoryStore` added to the `defaultStack`
*/
@objc
@discardableResult
public static func addInMemoryStorageAndWaitAndReturnError(_ error: NSErrorPointer) -> CSInMemoryStore? {
return self.defaultStack.addInMemoryStorageAndWaitAndReturnError(error)
@@ -95,6 +96,7 @@ public extension CSCoreStore {
- returns: the `CSSQLiteStore` added to the `defaultStack`
*/
@objc
@discardableResult
public static func addSQLiteStorageAndWaitAndReturnError(_ error: NSErrorPointer) -> CSSQLiteStore? {
return self.defaultStack.addSQLiteStorageAndWaitAndReturnError(error)
@@ -114,6 +116,7 @@ public extension CSCoreStore {
- returns: the `CSInMemoryStore` added to the `defaultStack`
*/
@objc
@discardableResult
public static func addInMemoryStorageAndWait(_ storage: CSInMemoryStore, error: NSErrorPointer) -> CSInMemoryStore? {
return self.defaultStack.addInMemoryStorageAndWait(storage, error: error)
@@ -133,6 +136,7 @@ public extension CSCoreStore {
- returns: the `CSSQLiteStore` added to the `defaultStack`
*/
@objc
@discardableResult
public static func addSQLiteStorageAndWait(_ storage: CSSQLiteStore, error: NSErrorPointer) -> CSSQLiteStore? {
return self.defaultStack.addSQLiteStorageAndWait(storage, error: error)

View File

@@ -74,9 +74,9 @@ public extension CSDataStack {
dataStack: self.bridgeToSwift,
from: from.bridgeToSwift,
sectionBy: nil,
applyFetchClauses: { fetchRequest in
applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest.cs_dynamicCast()) }
fetchClauses.forEach { $0.applyToFetchRequest(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) }
}
)
}
@@ -104,9 +104,9 @@ public extension CSDataStack {
dataStack: self.bridgeToSwift,
from: from.bridgeToSwift,
sectionBy: nil,
applyFetchClauses: { fetchRequest in
applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest.cs_dynamicCast()) }
fetchClauses.forEach { $0.applyToFetchRequest(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) }
},
createAsynchronously: {
@@ -141,9 +141,9 @@ public extension CSDataStack {
dataStack: self.bridgeToSwift,
from: from.bridgeToSwift,
sectionBy: sectionBy.bridgeToSwift,
applyFetchClauses: { fetchRequest in
applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest.cs_dynamicCast()) }
fetchClauses.forEach { $0.applyToFetchRequest(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) }
}
)
}
@@ -171,9 +171,9 @@ public extension CSDataStack {
dataStack: self.bridgeToSwift,
from: from.bridgeToSwift,
sectionBy: sectionBy.bridgeToSwift,
applyFetchClauses: { fetchRequest in
applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest.cs_dynamicCast()) }
fetchClauses.forEach { $0.applyToFetchRequest(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) }
},
createAsynchronously: {

View File

@@ -166,6 +166,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
- returns: the `CSInMemoryStore` added to the stack
*/
@objc
@discardableResult
public func addInMemoryStorageAndWaitAndReturnError(_ error: NSErrorPointer) -> CSInMemoryStore? {
return bridge(error) {
@@ -184,6 +185,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
- returns: the `CSSQLiteStore` added to the stack
*/
@objc
@discardableResult
public func addSQLiteStorageAndWaitAndReturnError(_ error: NSErrorPointer) -> CSSQLiteStore? {
return bridge(error) {
@@ -206,6 +208,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
- returns: the `CSInMemoryStore` added to the stack
*/
@objc
@discardableResult
public func addInMemoryStorageAndWait(_ storage: CSInMemoryStore, error: NSErrorPointer) -> CSInMemoryStore? {
return bridge(error) {
@@ -228,6 +231,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
- returns: the `CSSQLiteStore` added to the stack
*/
@objc
@discardableResult
public func addSQLiteStorageAndWait(_ storage: CSSQLiteStore, error: NSErrorPointer) -> CSSQLiteStore? {
return bridge(error) {

View File

@@ -95,7 +95,7 @@ public final class CSError: NSError, CoreStoreObjectiveCType {
case .unknownError:
return .unknown
case .differentPersistentStoreExistsAtURL:
case .differentStorageExistsAtURL:
guard case let existingPersistentStoreURL as URL = info["existingPersistentStoreURL"] else {
return .unknown
@@ -148,7 +148,7 @@ public final class CSError: NSError, CoreStoreObjectiveCType {
info = [:]
case .differentStorageExistsAtURL(let existingPersistentStoreURL):
code = .differentPersistentStoreExistsAtURL
code = .differentStorageExistsAtURL
info = [
"existingPersistentStoreURL": existingPersistentStoreURL
]
@@ -208,7 +208,7 @@ public enum CSErrorCode: Int {
/**
The `NSPersistentStore` could note be initialized because another store existed at the specified `NSURL`.
*/
case differentPersistentStoreExistsAtURL
case differentStorageExistsAtURL
/**
An `NSMappingModel` could not be found for a specific source and destination model versions.

View File

@@ -515,9 +515,9 @@ public final class CSListMonitor: NSObject, CoreStoreObjectiveCType {
@objc
public func refetch(_ fetchClauses: [CSFetchClause]) {
self.bridgeToSwift.refetch { (fetchRequest: NSFetchRequest<NSManagedObject>) in
self.bridgeToSwift.refetch { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest.cs_dynamicCast()) }
fetchClauses.forEach { $0.applyToFetchRequest(unsafeBitCast(fetchRequest, to: NSFetchRequest<NSFetchRequestResult>.self)) }
}
}

View File

@@ -99,7 +99,6 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
@warn_unused_result
public override func editObject(_ object: NSManagedObject?) -> AnyObject? {
return self.bridgeToSwift.edit(object)
@@ -113,7 +112,6 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
@warn_unused_result
public override func editInto(_ into: CSInto, objectID: NSManagedObjectID) -> AnyObject? {
return self.bridgeToSwift.edit(into.bridgeToSwift, objectID)

View File

@@ -79,17 +79,17 @@ public extension CoreStoreSwiftType where ObjectiveCType: CoreStoreObjectiveCTyp
// MARK: - Internal
internal func bridge<T: CoreStoreSwiftType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType>(@noescape _ closure: () -> T) -> T.ObjectiveCType {
internal func bridge<T: CoreStoreSwiftType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType>(_ closure: @noescape () -> T) -> T.ObjectiveCType {
return closure().bridgeToObjectiveC
}
internal func bridge<T: CoreStoreSwiftType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType>(@noescape _ closure: () -> T?) -> T.ObjectiveCType? {
internal func bridge<T: CoreStoreSwiftType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType>(_ closure: @noescape () -> T?) -> T.ObjectiveCType? {
return closure()?.bridgeToObjectiveC
}
internal func bridge<T: CoreStoreSwiftType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType>(@noescape _ closure: () throws -> T) throws -> T.ObjectiveCType {
internal func bridge<T: CoreStoreSwiftType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType>(_ closure: @noescape () throws -> T) throws -> T.ObjectiveCType {
do {
@@ -101,7 +101,7 @@ internal func bridge<T: CoreStoreSwiftType where T.ObjectiveCType: CoreStoreObje
}
}
internal func bridge(@noescape _ closure: () throws -> Void) throws {
internal func bridge(_ closure: @noescape () throws -> Void) throws {
do {
@@ -113,7 +113,7 @@ internal func bridge(@noescape _ closure: () throws -> Void) throws {
}
}
internal func bridge<T: CoreStoreSwiftType>(_ error: NSErrorPointer, @noescape _ closure: () throws -> T) -> T.ObjectiveCType? {
internal func bridge<T: CoreStoreSwiftType>(_ error: NSErrorPointer, _ closure: @noescape () throws -> T) -> T.ObjectiveCType? {
do {
@@ -128,7 +128,7 @@ internal func bridge<T: CoreStoreSwiftType>(_ error: NSErrorPointer, @noescape _
}
}
internal func bridge(_ error: NSErrorPointer, @noescape _ closure: () throws -> Void) -> Bool {
internal func bridge(_ error: NSErrorPointer, _ closure: @noescape () throws -> Void) -> Bool {
do {
@@ -143,7 +143,7 @@ internal func bridge(_ error: NSErrorPointer, @noescape _ closure: () throws ->
}
}
internal func bridge<T>(_ error: NSErrorPointer, @noescape _ closure: () throws -> T?) -> T? {
internal func bridge<T>(_ error: NSErrorPointer, _ closure: @noescape () throws -> T?) -> T? {
do {
@@ -158,7 +158,7 @@ internal func bridge<T>(_ error: NSErrorPointer, @noescape _ closure: () throws
}
}
internal func bridge<T: CoreStoreSwiftType>(_ error: NSErrorPointer, @noescape _ closure: () throws -> [T]) -> [T.ObjectiveCType]? {
internal func bridge<T: CoreStoreSwiftType>(_ error: NSErrorPointer, _ closure: @noescape () throws -> [T]) -> [T.ObjectiveCType]? {
do {

View File

@@ -39,7 +39,6 @@ public extension CoreStore {
- parameter object: the `NSManagedObject` to observe changes from
- returns: a `ObjectMonitor` that monitors changes to `object`
*/
@warn_unused_result
public static func monitorObject<T: NSManagedObject>(_ object: T) -> ObjectMonitor<T> {
return self.defaultStack.monitorObject(object)
@@ -52,7 +51,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public static func monitorList<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
return self.defaultStack.monitorList(from, fetchClauses)
@@ -65,7 +63,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public static func monitorList<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
return self.defaultStack.monitorList(from, fetchClauses)
@@ -103,7 +100,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public static func monitorSectionedList<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses)
@@ -117,7 +113,6 @@ public extension CoreStore {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public static func monitorSectionedList<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
return self.defaultStack.monitorSectionedList(from, sectionBy, fetchClauses)

View File

@@ -42,7 +42,6 @@ public extension DataStack {
- parameter object: the `NSManagedObject` to observe changes from
- returns: a `ObjectMonitor` that monitors changes to `object`
*/
@warn_unused_result
public func monitorObject<T: NSManagedObject>(_ object: T) -> ObjectMonitor<T> {
CoreStore.assert(
@@ -59,7 +58,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public func monitorList<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
return self.monitorList(from, fetchClauses)
@@ -72,7 +70,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public func monitorList<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
CoreStore.assert(
@@ -145,7 +142,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public func monitorSectionedList<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
return self.monitorSectionedList(from, sectionBy, fetchClauses)
@@ -159,7 +155,6 @@ public extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public func monitorSectionedList<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
CoreStore.assert(

View File

@@ -38,9 +38,9 @@ import CoreData
The `ListMonitor` monitors changes to a list of `NSManagedObject` instances. Observers that implement the `ListObserver` protocol may then register themselves to the `ListMonitor`'s `addObserver(_:)` method:
```
let monitor = CoreStore.monitorList(
From(MyPersonEntity),
From<MyPersonEntity>(),
Where("title", isEqualTo: "Engineer"),
OrderBy(.Ascending("lastName"))
OrderBy(.ascending("lastName"))
)
monitor.addObserver(self)
```
@@ -56,10 +56,10 @@ import CoreData
Creating a sectioned-list is also possible with the `monitorSectionedList(...)` method:
```
let monitor = CoreStore.monitorSectionedList(
From(MyPersonEntity),
From<MyPersonEntity>(),
SectionBy("age") { "Age \($0)" },
Where("title", isEqualTo: "Engineer"),
OrderBy(.Ascending("lastName"))
OrderBy(.ascending("lastName"))
)
monitor.addObserver(self)
```
@@ -168,7 +168,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- returns: `true` if at least one section exists, `false` otherwise
*/
@warn_unused_result
public func hasSections() -> Bool {
return self.sections().count > 0
@@ -179,7 +178,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- returns: `true` if at least one object in any section exists, `false` otherwise
*/
@warn_unused_result
public func hasObjects() -> Bool {
return self.numberOfObjects() > 0
@@ -191,7 +189,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- parameter section: the section index. Using an index outside the valid range will return `false`.
- returns: `true` if at least one object in the specified section exists, `false` otherwise
*/
@warn_unused_result
public func hasObjectsInSection(_ section: Int) -> Bool {
return self.numberOfObjectsInSection(safeSectionIndex: section) > 0
@@ -202,7 +199,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- returns: all objects in all sections
*/
@warn_unused_result
public func objectsInAllSections() -> [T] {
CoreStore.assert(
@@ -218,7 +214,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- parameter section: the section index. Using an index outside the valid range will raise an exception.
- returns: all objects in the specified section
*/
@warn_unused_result
public func objectsInSection(_ section: Int) -> [T] {
return (self.sectionInfoAtIndex(section).objects as? [T]) ?? []
@@ -230,7 +225,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- parameter section: the section index. Using an index outside the valid range will return `nil`.
- returns: all objects in the specified section
*/
@warn_unused_result
public func objectsInSection(safeSectionIndex section: Int) -> [T]? {
return (self.sectionInfoAtIndex(safeSectionIndex: section)?.objects as? [T]) ?? []
@@ -241,7 +235,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- returns: the number of sections
*/
@warn_unused_result
public func numberOfSections() -> Int {
CoreStore.assert(
@@ -256,7 +249,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- returns: the number of objects in all sections
*/
@warn_unused_result
public func numberOfObjects() -> Int {
CoreStore.assert(
@@ -272,7 +264,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- parameter section: the section index. Using an index outside the valid range will raise an exception.
- returns: the number of objects in the specified section
*/
@warn_unused_result
public func numberOfObjectsInSection(_ section: Int) -> Int {
return self.sectionInfoAtIndex(section).numberOfObjects
@@ -284,7 +275,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- parameter section: the section index. Using an index outside the valid range will return `nil`.
- returns: the number of objects in the specified section
*/
@warn_unused_result
public func numberOfObjectsInSection(safeSectionIndex section: Int) -> Int? {
return self.sectionInfoAtIndex(safeSectionIndex: section)?.numberOfObjects
@@ -296,7 +286,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- parameter section: the section index. Using an index outside the valid range will raise an exception.
- returns: the `NSFetchedResultsSectionInfo` for the specified section
*/
@warn_unused_result
public func sectionInfoAtIndex(_ section: Int) -> NSFetchedResultsSectionInfo {
CoreStore.assert(
@@ -312,7 +301,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- parameter section: the section index. Using an index outside the valid range will return `nil`.
- returns: the `NSFetchedResultsSectionInfo` for the specified section, or `nil` if the section index is out of bounds.
*/
@warn_unused_result
public func sectionInfoAtIndex(safeSectionIndex section: Int) -> NSFetchedResultsSectionInfo? {
CoreStore.assert(
@@ -336,7 +324,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- returns: the `NSFetchedResultsSectionInfo`s for all sections
*/
@warn_unused_result
public func sections() -> [NSFetchedResultsSectionInfo] {
CoreStore.assert(
@@ -353,7 +340,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- parameter index: the index of the Section Index
- returns: the target section for the specified "Section Index" title and index.
*/
@warn_unused_result
public func targetSectionForSectionIndex(title: String, index: Int) -> Int {
CoreStore.assert(
@@ -368,7 +354,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- returns: the section index titles for all sections
*/
@warn_unused_result
public func sectionIndexTitles() -> [String] {
CoreStore.assert(
@@ -384,7 +369,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- parameter object: the `NSManagedObject` to search the index of
- returns: the index of the `NSManagedObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found.
*/
@warn_unused_result
public func indexOf(_ object: T) -> Int? {
CoreStore.assert(
@@ -400,7 +384,6 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
- parameter object: the `NSManagedObject` to search the index of
- returns: the `NSIndexPath` of the `NSManagedObject` if it exists in the `ListMonitor`'s fetched objects, or `nil` if not found.
*/
@warn_unused_result
public func indexPathOf(_ object: T) -> IndexPath? {
CoreStore.assert(
@@ -678,7 +661,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
return unsafeBitCast(self, to: ListMonitor<NSManagedObject>.self)
}
internal func registerChangeNotification(_ notificationKey: UnsafePointer<Void>, name: String, toObserver observer: AnyObject, callback: (monitor: ListMonitor<T>) -> Void) {
internal func registerChangeNotification(_ notificationKey: UnsafePointer<Void>, name: Notification.Name, toObserver observer: AnyObject, callback: (monitor: ListMonitor<T>) -> Void) {
cs_setAssociatedRetainedObject(
NotificationObserver(
@@ -698,7 +681,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
}
internal func registerObjectNotification(_ notificationKey: UnsafePointer<Void>, name: String, toObserver observer: AnyObject, callback: (monitor: ListMonitor<T>, object: T, indexPath: IndexPath?, newIndexPath: IndexPath?) -> Void) {
internal func registerObjectNotification(_ notificationKey: UnsafePointer<Void>, name: Notification.Name, toObserver observer: AnyObject, callback: (monitor: ListMonitor<T>, object: T, indexPath: IndexPath?, newIndexPath: IndexPath?) -> Void) {
cs_setAssociatedRetainedObject(
NotificationObserver(
@@ -707,16 +690,16 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
closure: { [weak self] (note) -> Void in
guard let `self` = self,
let userInfo = (note as NSNotification).userInfo,
let object = userInfo[UserInfoKeyObject] as? T else {
let userInfo = note.userInfo,
let object = userInfo[String(NSManagedObject.self)] as? T else {
return
}
callback(
monitor: self,
object: object,
indexPath: userInfo[UserInfoKeyIndexPath] as? IndexPath,
newIndexPath: userInfo[UserInfoKeyNewIndexPath] as? IndexPath
indexPath: userInfo[String(IndexPath.self)] as? IndexPath,
newIndexPath: userInfo["\(String(IndexPath.self)).New"] as? IndexPath
)
}
),
@@ -725,7 +708,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
}
internal func registerSectionNotification(_ notificationKey: UnsafePointer<Void>, name: String, toObserver observer: AnyObject, callback: (monitor: ListMonitor<T>, sectionInfo: NSFetchedResultsSectionInfo, sectionIndex: Int) -> Void) {
internal func registerSectionNotification(_ notificationKey: UnsafePointer<Void>, name: Notification.Name, toObserver observer: AnyObject, callback: (monitor: ListMonitor<T>, sectionInfo: NSFetchedResultsSectionInfo, sectionIndex: Int) -> Void) {
cs_setAssociatedRetainedObject(
NotificationObserver(
@@ -734,9 +717,9 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
closure: { [weak self] (note) -> Void in
guard let `self` = self,
let userInfo = (note as NSNotification).userInfo,
let sectionInfo = userInfo[UserInfoKeySectionInfo] as? NSFetchedResultsSectionInfo,
let sectionIndex = (userInfo[UserInfoKeySectionIndex] as? NSNumber)?.intValue else {
let userInfo = note.userInfo,
let sectionInfo = userInfo[String(NSFetchedResultsSectionInfo.self)] as? NSFetchedResultsSectionInfo,
let sectionIndex = (userInfo[String(NSNumber.self)] as? NSNumber)?.intValue else {
return
}
@@ -760,7 +743,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
self.registerChangeNotification(
&self.willChangeListKey,
name: ListMonitorWillChangeListNotification,
name: Notification.Name.listMonitorWillChangeList,
toObserver: observer,
callback: { [weak observer] (monitor) -> Void in
@@ -773,7 +756,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
self.registerChangeNotification(
&self.didChangeListKey,
name: ListMonitorDidChangeListNotification,
name: Notification.Name.listMonitorDidChangeList,
toObserver: observer,
callback: { [weak observer] (monitor) -> Void in
@@ -786,7 +769,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
self.registerChangeNotification(
&self.willRefetchListKey,
name: ListMonitorWillRefetchListNotification,
name: Notification.Name.listMonitorWillRefetchList,
toObserver: observer,
callback: { [weak observer] (monitor) -> Void in
@@ -799,7 +782,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
self.registerChangeNotification(
&self.didRefetchListKey,
name: ListMonitorDidRefetchListNotification,
name: Notification.Name.listMonitorDidRefetchList,
toObserver: observer,
callback: { [weak observer] (monitor) -> Void in
@@ -821,7 +804,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
self.registerObjectNotification(
&self.didInsertObjectKey,
name: ListMonitorDidInsertObjectNotification,
name: Notification.Name.listMonitorDidInsertObject,
toObserver: observer,
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
@@ -839,7 +822,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
self.registerObjectNotification(
&self.didDeleteObjectKey,
name: ListMonitorDidDeleteObjectNotification,
name: Notification.Name.listMonitorDidDeleteObject,
toObserver: observer,
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
@@ -857,7 +840,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
self.registerObjectNotification(
&self.didUpdateObjectKey,
name: ListMonitorDidUpdateObjectNotification,
name: Notification.Name.listMonitorDidUpdateObject,
toObserver: observer,
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
@@ -875,7 +858,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
self.registerObjectNotification(
&self.didMoveObjectKey,
name: ListMonitorDidMoveObjectNotification,
name: Notification.Name.listMonitorDidMoveObject,
toObserver: observer,
callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in
@@ -903,7 +886,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
self.registerSectionNotification(
&self.didInsertSectionKey,
name: ListMonitorDidInsertSectionNotification,
name: Notification.Name.listMonitorDidInsertSection,
toObserver: observer,
callback: { [weak observer] (monitor, sectionInfo, sectionIndex) -> Void in
@@ -921,7 +904,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
self.registerSectionNotification(
&self.didDeleteSectionKey,
name: ListMonitorDidDeleteSectionNotification,
name: Notification.Name.listMonitorDidDeleteSection,
toObserver: observer,
callback: { [weak observer] (monitor, sectionInfo, sectionIndex) -> Void in
@@ -972,7 +955,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
self.isPendingRefetch = true
NotificationCenter.default.post(
name: Notification.Name(rawValue: ListMonitorWillRefetchListNotification),
name: Notification.Name.listMonitorWillRefetchList,
object: self
)
}
@@ -1008,7 +991,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
self.isPendingRefetch = false
NotificationCenter.default.post(
name: NSNotification.Name(rawValue: ListMonitorDidRefetchListNotification),
name: Notification.Name.listMonitorDidRefetchList,
object: self
)
}
@@ -1110,7 +1093,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
}
self.observerForWillChangePersistentStore = NotificationObserver(
notificationName: NSNotification.Name.NSPersistentStoreCoordinatorStoresWillChange.rawValue,
notificationName: NSNotification.Name.NSPersistentStoreCoordinatorStoresWillChange,
object: coordinator,
queue: OperationQueue.main,
closure: { [weak self] (note) -> Void in
@@ -1132,7 +1115,7 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
)
self.observerForDidChangePersistentStore = NotificationObserver(
notificationName: NSNotification.Name.NSPersistentStoreCoordinatorStoresDidChange.rawValue,
notificationName: NSNotification.Name.NSPersistentStoreCoordinatorStoresDidChange,
object: coordinator,
queue: OperationQueue.main,
closure: { [weak self] (note) -> Void in
@@ -1180,25 +1163,21 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
// MARK: - ListMonitor: Equatable
@warn_unused_result
public func == <T: NSManagedObject>(lhs: ListMonitor<T>, rhs: ListMonitor<T>) -> Bool {
return lhs === rhs
}
@warn_unused_result
public func == <T: NSManagedObject, U: NSManagedObject>(lhs: ListMonitor<T>, rhs: ListMonitor<U>) -> Bool {
return lhs.fetchedResultsController === rhs.fetchedResultsController
}
@warn_unused_result
public func ~= <T: NSManagedObject>(lhs: ListMonitor<T>, rhs: ListMonitor<T>) -> Bool {
return lhs === rhs
}
@warn_unused_result
public func ~= <T: NSManagedObject, U: NSManagedObject>(lhs: ListMonitor<T>, rhs: ListMonitor<U>) -> Bool {
return lhs.fetchedResultsController === rhs.fetchedResultsController
@@ -1219,42 +1198,42 @@ extension ListMonitor: FetchedResultsControllerHandler {
case .insert:
NotificationCenter.default.post(
name: Notification.Name(rawValue: ListMonitorDidInsertObjectNotification),
name: Notification.Name.listMonitorDidInsertObject,
object: self,
userInfo: [
UserInfoKeyObject: anObject,
UserInfoKeyNewIndexPath: newIndexPath!
String(NSManagedObject.self): anObject,
"\(String(IndexPath.self)).New": newIndexPath!
]
)
case .delete:
NotificationCenter.default.post(
name: Notification.Name(rawValue: ListMonitorDidDeleteObjectNotification),
name: Notification.Name.listMonitorDidDeleteObject,
object: self,
userInfo: [
UserInfoKeyObject: anObject,
UserInfoKeyIndexPath: indexPath!
String(NSManagedObject.self): anObject,
String(IndexPath.self): indexPath!
]
)
case .update:
NotificationCenter.default.post(
name: Notification.Name(rawValue: ListMonitorDidUpdateObjectNotification),
name: Notification.Name.listMonitorDidUpdateObject,
object: self,
userInfo: [
UserInfoKeyObject: anObject,
UserInfoKeyIndexPath: indexPath!
String(NSManagedObject.self): anObject,
String(IndexPath.self): indexPath!
]
)
case .move:
NotificationCenter.default.post(
name: Notification.Name(rawValue: ListMonitorDidMoveObjectNotification),
name: Notification.Name.listMonitorDidMoveObject,
object: self,
userInfo: [
UserInfoKeyObject: anObject,
UserInfoKeyIndexPath: indexPath!,
UserInfoKeyNewIndexPath: newIndexPath!
String(NSManagedObject.self): anObject,
String(IndexPath.self): indexPath!,
"\(String(IndexPath.self)).New": newIndexPath!
]
)
}
@@ -1266,21 +1245,21 @@ extension ListMonitor: FetchedResultsControllerHandler {
case .insert:
NotificationCenter.default.post(
name: Notification.Name(rawValue: ListMonitorDidInsertSectionNotification),
name: Notification.Name.listMonitorDidInsertSection,
object: self,
userInfo: [
UserInfoKeySectionInfo: sectionInfo,
UserInfoKeySectionIndex: NSNumber(value: sectionIndex)
String(NSFetchedResultsSectionInfo.self): sectionInfo,
String(NSNumber.self): NSNumber(value: sectionIndex)
]
)
case .delete:
NotificationCenter.default.post(
name: Notification.Name(rawValue: ListMonitorDidDeleteSectionNotification),
name: Notification.Name.listMonitorDidDeleteSection,
object: self,
userInfo: [
UserInfoKeySectionInfo: sectionInfo,
UserInfoKeySectionIndex: NSNumber(value: sectionIndex)
String(NSFetchedResultsSectionInfo.self): sectionInfo,
String(NSNumber.self): NSNumber(value: sectionIndex)
]
)
@@ -1293,7 +1272,7 @@ extension ListMonitor: FetchedResultsControllerHandler {
self.taskGroup.enter()
NotificationCenter.default.post(
name: Notification.Name(rawValue: ListMonitorWillChangeListNotification),
name: Notification.Name.listMonitorWillChangeList,
object: self
)
}
@@ -1301,7 +1280,7 @@ extension ListMonitor: FetchedResultsControllerHandler {
internal func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
NotificationCenter.default.post(
name: Notification.Name(rawValue: ListMonitorDidChangeListNotification),
name: Notification.Name.listMonitorDidChangeList,
object: self
)
self.taskGroup.leave()
@@ -1315,25 +1294,19 @@ extension ListMonitor: FetchedResultsControllerHandler {
// MARK: - Notification Keys
private let ListMonitorWillChangeListNotification = "ListMonitorWillChangeListNotification"
private let ListMonitorDidChangeListNotification = "ListMonitorDidChangeListNotification"
private let ListMonitorWillRefetchListNotification = "ListMonitorWillRefetchListNotification"
private let ListMonitorDidRefetchListNotification = "ListMonitorDidRefetchListNotification"
private let ListMonitorDidInsertObjectNotification = "ListMonitorDidInsertObjectNotification"
private let ListMonitorDidDeleteObjectNotification = "ListMonitorDidDeleteObjectNotification"
private let ListMonitorDidUpdateObjectNotification = "ListMonitorDidUpdateObjectNotification"
private let ListMonitorDidMoveObjectNotification = "ListMonitorDidMoveObjectNotification"
private let ListMonitorDidInsertSectionNotification = "ListMonitorDidInsertSectionNotification"
private let ListMonitorDidDeleteSectionNotification = "ListMonitorDidDeleteSectionNotification"
private let UserInfoKeyObject = "UserInfoKeyObject"
private let UserInfoKeyIndexPath = "UserInfoKeyIndexPath"
private let UserInfoKeyNewIndexPath = "UserInfoKeyNewIndexPath"
private let UserInfoKeySectionInfo = "UserInfoKeySectionInfo"
private let UserInfoKeySectionIndex = "UserInfoKeySectionIndex"
private extension Notification.Name {
private static let listMonitorWillChangeList = Notification.Name(rawValue: "listMonitorWillChangeList")
private static let listMonitorDidChangeList = Notification.Name(rawValue: "listMonitorDidChangeList")
private static let listMonitorWillRefetchList = Notification.Name(rawValue: "listMonitorWillRefetchList")
private static let listMonitorDidRefetchList = Notification.Name(rawValue: "listMonitorDidRefetchList")
private static let listMonitorDidInsertObject = Notification.Name(rawValue: "listMonitorDidInsertObject")
private static let listMonitorDidDeleteObject = Notification.Name(rawValue: "listMonitorDidDeleteObject")
private static let listMonitorDidUpdateObject = Notification.Name(rawValue: "listMonitorDidUpdateObject")
private static let listMonitorDidMoveObject = Notification.Name(rawValue: "listMonitorDidMoveObject")
private static let listMonitorDidInsertSection = Notification.Name(rawValue: "listMonitorDidInsertSection")
private static let listMonitorDidDeleteSection = Notification.Name(rawValue: "listMonitorDidDeleteSection")
}
#endif

View File

@@ -35,8 +35,8 @@ import CoreData
Implement the `ListObserver` protocol to observe changes to a list of `NSManagedObject`s. `ListObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
```
let monitor = CoreStore.monitorList(
From(MyPersonEntity),
OrderBy(.Ascending("lastName"))
From<MyPersonEntity>(),
OrderBy(.ascending("lastName"))
)
monitor.addObserver(self)
```
@@ -110,8 +110,8 @@ public extension ListObserver {
Implement the `ListObjectObserver` protocol to observe detailed changes to a list's object. `ListObjectObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
```
let monitor = CoreStore.monitorList(
From(MyPersonEntity),
OrderBy(.Ascending("lastName"))
From<MyPersonEntity>(),
OrderBy(.ascending("lastName"))
)
monitor.addObserver(self)
```
@@ -189,9 +189,9 @@ public extension ListObjectObserver {
Implement the `ListSectionObserver` protocol to observe changes to a list's section info. `ListSectionObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
```
let monitor = CoreStore.monitorSectionedList(
From(MyPersonEntity),
From<MyPersonEntity>(),
SectionBy("age") { "Age \($0)" },
OrderBy(.Ascending("lastName"))
OrderBy(.ascending("lastName"))
)
monitor.addObserver(self)
```

View File

@@ -134,7 +134,7 @@ public final class ObjectMonitor<EntityType: NSManagedObject> {
)
self.registerChangeNotification(
&self.willChangeObjectKey,
name: ObjectMonitorWillChangeObjectNotification,
name: Notification.Name.objectMonitorWillChangeObject,
toObserver: observer,
callback: { [weak observer] (monitor) -> Void in
@@ -147,7 +147,7 @@ public final class ObjectMonitor<EntityType: NSManagedObject> {
)
self.registerObjectNotification(
&self.didDeleteObjectKey,
name: ObjectMonitorDidDeleteObjectNotification,
name: Notification.Name.objectMonitorDidDeleteObject,
toObserver: observer,
callback: { [weak observer] (monitor, object) -> Void in
@@ -160,7 +160,7 @@ public final class ObjectMonitor<EntityType: NSManagedObject> {
)
self.registerObjectNotification(
&self.didUpdateObjectKey,
name: ObjectMonitorDidUpdateObjectNotification,
name: Notification.Name.objectMonitorDidUpdateObject,
toObserver: observer,
callback: { [weak self, weak observer] (monitor, object) -> Void in
@@ -255,7 +255,7 @@ public final class ObjectMonitor<EntityType: NSManagedObject> {
self.lastCommittedAttributes = (self.object?.committedValues(forKeys: nil) as? [String: NSObject]) ?? [:]
}
private func registerChangeNotification(_ notificationKey: UnsafePointer<Void>, name: String, toObserver observer: AnyObject, callback: (monitor: ObjectMonitor<EntityType>) -> Void) {
private func registerChangeNotification(_ notificationKey: UnsafePointer<Void>, name: Notification.Name, toObserver observer: AnyObject, callback: (monitor: ObjectMonitor<EntityType>) -> Void) {
cs_setAssociatedRetainedObject(
NotificationObserver(
@@ -275,7 +275,7 @@ public final class ObjectMonitor<EntityType: NSManagedObject> {
)
}
private func registerObjectNotification(_ notificationKey: UnsafePointer<Void>, name: String, toObserver observer: AnyObject, callback: (monitor: ObjectMonitor<EntityType>, object: EntityType) -> Void) {
private func registerObjectNotification(_ notificationKey: UnsafePointer<Void>, name: Notification.Name, toObserver observer: AnyObject, callback: (monitor: ObjectMonitor<EntityType>, object: EntityType) -> Void) {
cs_setAssociatedRetainedObject(
NotificationObserver(
@@ -284,8 +284,8 @@ public final class ObjectMonitor<EntityType: NSManagedObject> {
closure: { [weak self] (note) -> Void in
guard let `self` = self,
let userInfo = (note as NSNotification).userInfo,
let object = userInfo[UserInfoKeyObject] as? EntityType else {
let userInfo = note.userInfo,
let object = userInfo[String(NSManagedObject.self)] as? EntityType else {
return
}
@@ -323,7 +323,7 @@ extension ObjectMonitor: FetchedResultsControllerHandler {
internal func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
NotificationCenter.default.post(
name: Notification.Name(rawValue: ObjectMonitorWillChangeObjectNotification),
name: Notification.Name.objectMonitorWillChangeObject,
object: self
)
}
@@ -336,16 +336,16 @@ extension ObjectMonitor: FetchedResultsControllerHandler {
case .delete:
NotificationCenter.default.post(
name: Notification.Name(rawValue: ObjectMonitorDidDeleteObjectNotification),
name: Notification.Name.objectMonitorDidDeleteObject,
object: self,
userInfo: [UserInfoKeyObject: anObject]
userInfo: [String(NSManagedObject.self): anObject]
)
case .update:
NotificationCenter.default.post(
name: Notification.Name(rawValue: ObjectMonitorDidUpdateObjectNotification),
name: Notification.Name.objectMonitorDidUpdateObject,
object: self,
userInfo: [UserInfoKeyObject: anObject]
userInfo: [String(NSManagedObject.self): anObject]
)
default:
@@ -360,12 +360,15 @@ extension ObjectMonitor: FetchedResultsControllerHandler {
return sectionName
}
}
// MARK: - Notification.Name
private let ObjectMonitorWillChangeObjectNotification = "ObjectMonitorWillChangeObjectNotification"
private let ObjectMonitorDidDeleteObjectNotification = "ObjectMonitorDidDeleteObjectNotification"
private let ObjectMonitorDidUpdateObjectNotification = "ObjectMonitorDidUpdateObjectNotification"
private let UserInfoKeyObject = "UserInfoKeyObject"
private extension Notification.Name {
private static let objectMonitorWillChangeObject = Notification.Name(rawValue: "objectMonitorWillChangeObject")
private static let objectMonitorDidDeleteObject = Notification.Name(rawValue: "objectMonitorWillChangeObject")
private static let objectMonitorDidUpdateObject = Notification.Name(rawValue: "objectMonitorWillChangeObject")
}
#endif

View File

@@ -35,9 +35,9 @@ import CoreData
The `SectionBy` clause indicates the key path to use to group the `ListMonitor` objects into sections. An optional closure can also be provided to transform the value into an appropriate section name:
```
let monitor = CoreStore.monitorSectionedList(
From(MyPersonEntity),
From<MyPersonEntity>(),
SectionBy("age") { "Age \($0)" },
OrderBy(.Ascending("lastName"))
OrderBy(.ascending("lastName"))
)
```
*/

View File

@@ -42,7 +42,6 @@ public extension UnsafeDataTransaction {
- parameter object: the `NSManagedObject` to observe changes from
- returns: a `ObjectMonitor` that monitors changes to `object`
*/
@warn_unused_result
public func monitorObject<T: NSManagedObject>(_ object: T) -> ObjectMonitor<T> {
return ObjectMonitor(
@@ -58,7 +57,6 @@ public extension UnsafeDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public func monitorList<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
return self.monitorList(from, fetchClauses)
@@ -71,7 +69,6 @@ public extension UnsafeDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public func monitorList<T: NSManagedObject>(_ from: From<T>, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
CoreStore.assert(
@@ -136,7 +133,6 @@ public extension UnsafeDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public func monitorSectionedList<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: FetchClause...) -> ListMonitor<T> {
return self.monitorSectionedList(from, sectionBy, fetchClauses)
@@ -150,7 +146,6 @@ public extension UnsafeDataTransaction {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListMonitor` instance that monitors changes to the list
*/
@warn_unused_result
public func monitorSectionedList<T: NSManagedObject>(_ from: From<T>, _ sectionBy: SectionBy, _ fetchClauses: [FetchClause]) -> ListMonitor<T> {
CoreStore.assert(

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

View File

@@ -101,7 +101,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to create an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
"Attempted to create an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
)
return super.create(into)
@@ -113,7 +113,6 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter object: the `NSManagedObject` type to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@warn_unused_result
public override func edit<T: NSManagedObject>(_ object: T?) -> T? {
CoreStore.assert(
@@ -131,12 +130,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@warn_unused_result
public override func edit<T: NSManagedObject>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
CoreStore.assert(
!self.isCommitted,
"Attempted to update an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
"Attempted to update an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
)
return super.edit(into, objectID)

View File

@@ -57,7 +57,7 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.isRunningInAllowedQueue(),
"Attempted to create an entity of type \(cs_typeName(T)) outside its designated queue."
"Attempted to create an entity of type \(cs_typeName(T.self)) outside its designated queue."
)
let context = self.context
@@ -118,7 +118,6 @@ public /*abstract*/ class BaseDataTransaction {
- parameter object: the `NSManagedObject` type to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@warn_unused_result
public func edit<T: NSManagedObject>(_ object: T?) -> T? {
CoreStore.assert(
@@ -139,17 +138,16 @@ public /*abstract*/ class BaseDataTransaction {
- parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@warn_unused_result
public func edit<T: NSManagedObject>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
CoreStore.assert(
self.isRunningInAllowedQueue(),
"Attempted to update an entity of type \(cs_typeName(T)) outside its designated queue."
"Attempted to update an entity of type \(cs_typeName(T.self)) outside its designated queue."
)
CoreStore.assert(
into.inferStoreIfPossible
|| (into.configuration ?? Into.defaultConfigurationName) == objectID.persistentStore?.configurationName,
"Attempted to update an entity of type \(cs_typeName(T)) but the specified persistent store do not match the `NSManagedObjectID`."
"Attempted to update an entity of type \(cs_typeName(T.self)) but the specified persistent store do not match the `NSManagedObjectID`."
)
return self.fetchExisting(objectID) as? T
}
@@ -221,7 +219,6 @@ public /*abstract*/ class BaseDataTransaction {
- returns: a `Set` of pending `NSManagedObject`s that were inserted to the transaction.
*/
@warn_unused_result
public func insertedObjects() -> Set<NSManagedObject> {
CoreStore.assert(
@@ -242,7 +239,6 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `NSManagedObject` subclass to filter
- returns: a `Set` of pending `NSManagedObject`s of the specified type that were inserted to the transaction.
*/
@warn_unused_result
public func insertedObjects<T: NSManagedObject>(_ entity: T.Type) -> Set<T> {
CoreStore.assert(
@@ -262,7 +258,6 @@ public /*abstract*/ class BaseDataTransaction {
- returns: a `Set` of pending `NSManagedObjectID`s that were inserted to the transaction.
*/
@warn_unused_result
public func insertedObjectIDs() -> Set<NSManagedObjectID> {
CoreStore.assert(
@@ -283,7 +278,6 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `NSManagedObject` subclass to filter
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were inserted to the transaction.
*/
@warn_unused_result
public func insertedObjectIDs<T: NSManagedObject>(_ entity: T.Type) -> Set<NSManagedObjectID> {
CoreStore.assert(
@@ -303,7 +297,6 @@ public /*abstract*/ class BaseDataTransaction {
- returns: a `Set` of pending `NSManagedObject`s that were updated to the transaction.
*/
@warn_unused_result
public func updatedObjects() -> Set<NSManagedObject> {
CoreStore.assert(
@@ -324,7 +317,6 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `NSManagedObject` subclass to filter
- returns: a `Set` of pending `NSManagedObject`s of the specified type that were updated in the transaction.
*/
@warn_unused_result
public func updatedObjects<T: NSManagedObject>(_ entity: T.Type) -> Set<T> {
CoreStore.assert(
@@ -344,7 +336,6 @@ public /*abstract*/ class BaseDataTransaction {
- returns: a `Set` of pending `NSManagedObjectID`s that were updated in the transaction.
*/
@warn_unused_result
public func updatedObjectIDs() -> Set<NSManagedObjectID> {
CoreStore.assert(
@@ -365,7 +356,6 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `NSManagedObject` subclass to filter
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were updated in the transaction.
*/
@warn_unused_result
public func updatedObjectIDs<T: NSManagedObject>(_ entity: T.Type) -> Set<NSManagedObjectID> {
CoreStore.assert(
@@ -385,7 +375,6 @@ public /*abstract*/ class BaseDataTransaction {
- returns: a `Set` of pending `NSManagedObject`s that were deleted from the transaction.
*/
@warn_unused_result
public func deletedObjects() -> Set<NSManagedObject> {
CoreStore.assert(
@@ -406,7 +395,6 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `NSManagedObject` subclass to filter
- returns: a `Set` of pending `NSManagedObject`s of the specified type that were deleted from the transaction.
*/
@warn_unused_result
public func deletedObjects<T: NSManagedObject>(_ entity: T.Type) -> Set<T> {
CoreStore.assert(
@@ -427,7 +415,6 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `NSManagedObject` subclass to filter
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
*/
@warn_unused_result
public func deletedObjectIDs() -> Set<NSManagedObjectID> {
CoreStore.assert(
@@ -448,7 +435,6 @@ public /*abstract*/ class BaseDataTransaction {
- parameter entity: the `NSManagedObject` subclass to filter
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
*/
@warn_unused_result
public func deletedObjectIDs<T: NSManagedObject>(_ entity: T.Type) -> Set<NSManagedObjectID> {
CoreStore.assert(
@@ -468,7 +454,7 @@ public /*abstract*/ class BaseDataTransaction {
internal let context: NSManagedObjectContext
internal let transactionQueue: GCDQueue
internal let childTransactionQueue: GCDQueue = .createSerial("com.corestore.datastack.childtransactionqueue")
internal let childTransactionQueue = GCDQueue.createSerial("com.corestore.datastack.childtransactionqueue")
internal let supportsUndo: Bool
internal let bypassesQueueing: Bool

View File

@@ -57,7 +57,6 @@ public extension CoreStore {
- prameter supportsUndo: `undo()`, `redo()`, and `rollback()` methods are only available when this parameter is `true`, otherwise those method will raise an exception. Defaults to `false`. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited.
- returns: a `UnsafeDataTransaction` instance where creates, updates, and deletes can be made.
*/
@warn_unused_result
public static func beginUnsafe(supportsUndo: Bool = false) -> UnsafeDataTransaction {
return self.defaultStack.beginUnsafe(supportsUndo: supportsUndo)

View File

@@ -67,7 +67,6 @@ public extension DataStack {
- prameter supportsUndo: `undo()`, `redo()`, and `rollback()` methods are only available when this parameter is `true`, otherwise those method will raise an exception. Defaults to `false`. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited.
- returns: a `UnsafeDataTransaction` instance where creates, updates, and deletes can be made.
*/
@warn_unused_result
public func beginUnsafe(supportsUndo: Bool = false) -> UnsafeDataTransaction {
return UnsafeDataTransaction(

View File

@@ -32,7 +32,7 @@ import CoreData
/**
An `Into` clause contains the destination entity and destination persistent store for a `create(...)` method. A common usage is to just indicate the entity:
```
let person = transaction.create(Into(MyPersonEntity))
let person = transaction.create(Into<MyPersonEntity>())
```
For cases where multiple `NSPersistentStore`s contain the same entity, the destination configuration's name needs to be specified as well:
```
@@ -66,7 +66,7 @@ public struct Into<T: NSManagedObject>: Hashable {
/**
Initializes an `Into` clause with the specified entity type.
```
let person = transaction.create(Into(MyPersonEntity))
let person = transaction.create(Into(MyPersonEntity.self))
```
- parameter entity: the `NSManagedObject` type to be created
@@ -79,7 +79,7 @@ public struct Into<T: NSManagedObject>: Hashable {
/**
Initializes an `Into` clause with the specified entity class.
```
let person = transaction.create(Into(MyPersonEntity))
let person = transaction.create(Into(MyPersonEntity.self))
```
- parameter entityClass: the `NSManagedObject` class type to be created
@@ -88,7 +88,7 @@ public struct Into<T: NSManagedObject>: Hashable {
CoreStore.assert(
entityClass is T.Type,
"Attempted to create generic type \(cs_typeName(Into<T>)) with entity class \(cs_typeName(entityClass))"
"Attempted to create generic type \(cs_typeName(Into<T>.self)) with entity class \(cs_typeName(entityClass))"
)
self.init(entityClass: entityClass, configuration: nil, inferStoreIfPossible: true)
}
@@ -133,7 +133,7 @@ public struct Into<T: NSManagedObject>: Hashable {
CoreStore.assert(
entityClass is T.Type,
"Attempted to create generic type \(cs_typeName(Into<T>)) with entity class \(cs_typeName(entityClass))"
"Attempted to create generic type \(cs_typeName(Into<T>.self)) with entity class \(cs_typeName(entityClass))"
)
self.init(entityClass: entityClass, configuration: configuration, inferStoreIfPossible: false)
}
@@ -181,7 +181,6 @@ public struct Into<T: NSManagedObject>: Hashable {
// MARK: - Into: Equatable
@warn_unused_result
public func == <T: NSManagedObject, U: NSManagedObject>(lhs: Into<T>, rhs: Into<U>) -> Bool {
return lhs.entityClass == rhs.entityClass
@@ -189,7 +188,6 @@ public func == <T: NSManagedObject, U: NSManagedObject>(lhs: Into<T>, rhs: Into<
&& lhs.inferStoreIfPossible == rhs.inferStoreIfPossible
}
@warn_unused_result
public func != <T: NSManagedObject, U: NSManagedObject>(lhs: Into<T>, rhs: Into<U>) -> Bool {
return lhs.entityClass == rhs.entityClass

View File

@@ -49,9 +49,9 @@ import Foundation
// ...
let result = transaction.commit()
switch result {
case .Success(let hasChanges):
case .success(let hasChanges):
// hasChanges indicates if there were changes or not
case .Failure(let error):
case .failure(let error):
// error is a CoreStoreError enum value
}
}
@@ -60,12 +60,12 @@ import Foundation
public enum SaveResult: Hashable {
/**
`SaveResult.Success` indicates that the `commit()` for the transaction succeeded, either because the save succeeded or because there were no changes to save. The associated value `hasChanges` indicates if there were saved changes or not.
`SaveResult.success` indicates that the `commit()` for the transaction succeeded, either because the save succeeded or because there were no changes to save. The associated value `hasChanges` indicates if there were saved changes or not.
*/
case success(hasChanges: Bool)
/**
`SaveResult.Failure` indicates that the `commit()` for the transaction failed. The associated object for this value is a `CoreStoreError` enum value.
`SaveResult.failure` indicates that the `commit()` for the transaction failed. The associated object for this value is a `CoreStoreError` enum value.
*/
case failure(CoreStoreError)
@@ -116,7 +116,6 @@ extension SaveResult: Boolean {
// MARK: - SaveResult: Equatable
@warn_unused_result
public func == (lhs: SaveResult, rhs: SaveResult) -> Bool {
switch (lhs, rhs) {

View File

@@ -96,7 +96,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to create an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
"Attempted to create an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
)
return super.create(into)
@@ -108,7 +108,6 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
- parameter object: the `NSManagedObject` type to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@warn_unused_result
public override func edit<T: NSManagedObject>(_ object: T?) -> T? {
CoreStore.assert(
@@ -126,12 +125,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
- parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@warn_unused_result
public override func edit<T: NSManagedObject>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
CoreStore.assert(
!self.isCommitted,
"Attempted to update an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
"Attempted to update an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
)
return super.edit(into, objectID)

View File

@@ -129,7 +129,6 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
- prameter supportsUndo: `undo()`, `redo()`, and `rollback()` methods are only available when this parameter is `true`, otherwise those method will raise an exception. Defaults to `false`. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited.
- returns: an `UnsafeDataTransaction` instance where creates, updates, and deletes can be made.
*/
@warn_unused_result
public func beginUnsafe(supportsUndo: Bool = false) -> UnsafeDataTransaction {
return UnsafeDataTransaction(