goodbye ObjectiveC

This commit is contained in:
John Estropia
2021-09-22 20:04:58 +09:00
parent bf10f4668c
commit 9a026afe40
110 changed files with 1060 additions and 9816 deletions

View File

@@ -29,113 +29,55 @@ import CoreData
// MARK: - CSAsynchronousDataTransaction
/**
The `CSAsynchronousDataTransaction` serves as the Objective-C bridging type for `AsynchronousDataTransaction`.
- SeeAlso: `AsynchronousDataTransaction`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSAsynchronousDataTransaction: CSBaseDataTransaction, CoreStoreObjectiveCType {
/**
Saves the transaction changes. This method should not be used after the `-commitWithCompletion:` method was already called once.
- parameter success: the block executed if the save succeeds.
- parameter failure: the block executed if the save fails. A `CSError` is reported as the argument of the block.
*/
@objc
public func commitWithSuccess(_ success: (() -> Void)?, failure: ((CSError) -> Void)?) {
Internals.assert(
self.bridgeToSwift.transactionQueue.cs_isCurrentExecutionContext(),
"Attempted to commit a \(Internals.typeName(self)) outside its designated queue."
)
Internals.assert(
!self.bridgeToSwift.isCommitted,
"Attempted to commit a \(Internals.typeName(self)) more than once."
)
self.bridgeToSwift.autoCommit { (_, error) in
if let error = error {
failure?(error.bridgeToObjectiveC)
}
else {
success?()
}
}
fatalError()
}
// MARK: NSObject
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
// MARK: BaseDataTransaction
/**
Creates a new `NSManagedObject` with the specified entity type.
- parameter into: the `CSInto` clause indicating the destination `NSManagedObject` entity type and the destination configuration
- returns: a new `NSManagedObject` instance of the specified entity type.
*/
@objc
public override func createInto(_ into: CSInto) -> Any {
return self.bridgeToSwift.create(into.bridgeToSwift)
fatalError()
}
/**
Returns an editable proxy of a specified `NSManagedObject`. This method should not be used after the `-commitWithCompletion:` method was already called once.
- parameter object: the `NSManagedObject` type to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
public override func editObject(_ object: NSManagedObject?) -> Any? {
return self.bridgeToSwift.edit(object)
fatalError()
}
/**
Returns an editable proxy of the object with the specified `NSManagedObjectID`. This method should not be used after the `-commitWithCompletion:` method was already called once.
- parameter into: a `CSInto` clause specifying the entity type
- parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
public override func editInto(_ into: CSInto, objectID: NSManagedObjectID) -> Any? {
return self.bridgeToSwift.edit(into.bridgeToSwift, objectID)
fatalError()
}
/**
Deletes a specified `NSManagedObject`. This method should not be used after the `-commitWithCompletion:` method was already called once.
- parameter object: the `NSManagedObject` type to be deleted
*/
@objc
public override func deleteObject(_ object: NSManagedObject?) {
self.bridgeToSwift.delete(object)
fatalError()
}
/**
Deletes the specified `NSManagedObject`s.
- parameter objects: the `NSManagedObject`s type to be deleted
*/
@objc
public override func deleteObjects(_ objects: [NSManagedObject]) {
self.bridgeToSwift.delete(objects)
fatalError()
}
@@ -144,31 +86,26 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction, CoreSto
public typealias SwiftType = AsynchronousDataTransaction
public var bridgeToSwift: AsynchronousDataTransaction {
return super.swiftTransaction as! AsynchronousDataTransaction
fatalError()
}
public required init(_ swiftValue: AsynchronousDataTransaction) {
super.init(swiftValue as BaseDataTransaction)
}
public required override init(_ swiftValue: BaseDataTransaction) {
super.init(swiftValue)
fatalError()
}
}
// MARK: - AsynchronousDataTransaction
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension AsynchronousDataTransaction: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSAsynchronousDataTransaction {
return CSAsynchronousDataTransaction(self)
fatalError()
}
}

View File

@@ -29,167 +29,66 @@ import CoreData
// MARK: - CSBaseDataTransaction
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension CSBaseDataTransaction {
/**
Fetches the `NSManagedObject` instance in the transaction's context from a reference created from a transaction or from a different managed object context.
- 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.
*/
@objc
public func fetchExistingObject(_ object: NSManagedObject) -> Any? {
return self.swiftTransaction.context.fetchExisting(object) as NSManagedObject?
fatalError()
}
/**
Fetches the `NSManagedObject` instance in the transaction's context from an `NSManagedObjectID`.
- parameter objectID: the `NSManagedObjectID` for the object
- returns: the `NSManagedObject` instance if the object exists in the transaction, or `nil` if not found.
*/
@objc
public func fetchExistingObjectWithID(_ objectID: NSManagedObjectID) -> Any? {
return self.swiftTransaction.context.fetchExisting(objectID) as NSManagedObject?
fatalError()
}
/**
Fetches the `NSManagedObject` instances in the transaction's context from references created from a transaction or from a different managed object context.
- parameter objects: an array of `NSManagedObject`s created/fetched outside the transaction
- returns: the `NSManagedObject` array for objects that exists in the transaction
*/
@objc
public func fetchExistingObjects(_ objects: [NSManagedObject]) -> [Any] {
return self.swiftTransaction.context.fetchExisting(objects) as [NSManagedObject]
fatalError()
}
/**
Fetches the `NSManagedObject` instances in the transaction's context from a list of `NSManagedObjectID`.
- parameter objectIDs: the `NSManagedObjectID` array for the objects
- returns: the `NSManagedObject` array for objects that exists in the transaction
*/
@objc
public func fetchExistingObjectsWithIDs(_ objectIDs: [NSManagedObjectID]) -> [Any] {
return self.swiftTransaction.context.fetchExisting(objectIDs) as [NSManagedObject]
fatalError()
}
/**
Fetches the first `NSManagedObject` instance that satisfies the specified `CSFetchClause`s. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `CSFetchClause` instances for the fetch request. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: the first `NSManagedObject` instance that satisfies the specified `CSFetchClause`s
*/
@objc
public func fetchOneFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> Any? {
Internals.assert(
self.swiftTransaction.isRunningInAllowedQueue(),
"Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue."
)
return (try? self.swiftTransaction.context.fetchOne(from, fetchClauses))?
.flatMap({ $0 })
fatalError()
}
/**
Fetches all `NSManagedObject` instances that satisfy the specified `CSFetchClause`s. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter fetchClauses: a series of `CSFetchClause` instances for the fetch request. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: all `NSManagedObject` instances that satisfy the specified `CSFetchClause`s
*/
@objc
public func fetchAllFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> [Any]? {
Internals.assert(
self.swiftTransaction.isRunningInAllowedQueue(),
"Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue."
)
return (try? self.swiftTransaction.context.fetchAll(from, fetchClauses))
.flatMap({ $0 })
fatalError()
}
/**
Fetches the number of `NSManagedObject`s that satisfy the specified `CSFetchClause`s. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter fetchClauses: a series of `CSFetchClause` instances for the fetch request. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: the number `NSManagedObject`s that satisfy the specified `CSFetchClause`s
*/
@objc
public func fetchCountFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> NSNumber? {
Internals.assert(
self.swiftTransaction.isRunningInAllowedQueue(),
"Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue."
)
return (try? self.swiftTransaction.context.fetchCount(from, fetchClauses))
.flatMap({ NSNumber(value: $0) })
fatalError()
}
/**
Fetches the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `CSFetchClause`s. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter fetchClauses: a series of `CSFetchClause` instances for the fetch request. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `CSFetchClause`s
*/
@objc
public func fetchObjectIDFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> NSManagedObjectID? {
Internals.assert(
self.swiftTransaction.isRunningInAllowedQueue(),
"Attempted to fetch from a \(Internals.typeName(self)) outside its designated queue."
)
return (try? self.swiftTransaction.context.fetchObjectID(from, fetchClauses))
.flatMap({ $0 })
fatalError()
}
/**
Queries aggregate values as specified by the `CSQueryClause`s. Requires at least a `CSSelect` clause, and optional `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter selectClause: a `CSSelect` clause indicating the properties to fetch, and with the generic type indicating the return type.
- parameter queryClauses: a series of `CSQueryClause` instances for the query request. Accepts `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `CSSelect` parameter.
*/
@objc
public func queryValueFrom(_ from: CSFrom, selectClause: CSSelect, queryClauses: [CSQueryClause]) -> Any? {
Internals.assert(
self.swiftTransaction.isRunningInAllowedQueue(),
"Attempted to query from a \(Internals.typeName(self)) outside its designated queue."
)
return (try? self.swiftTransaction.context.queryValue(from, selectClause, queryClauses))
.flatMap({ $0 })
fatalError()
}
/**
Queries a dictionary of attribute values as specified by the `CSQueryClause`s. Requires at least a `CSSelect` clause, and optional `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter selectClause: a `CSSelect` clause indicating the properties to fetch, and with the generic type indicating the return type.
- parameter queryClauses: a series of `CSQueryClause` instances for the query request. Accepts `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `CSSelect` parameter.
*/
@objc
public func queryAttributesFrom(_ from: CSFrom, selectClause: CSSelect, queryClauses: [CSQueryClause]) -> [[String: Any]]? {
Internals.assert(
self.swiftTransaction.isRunningInAllowedQueue(),
"Attempted to query from a \(Internals.typeName(self)) outside its designated queue."
)
return (try? self.swiftTransaction.context.queryAttributes(from, selectClause, queryClauses))
.flatMap({ $0 })
fatalError()
}
}

View File

@@ -29,226 +29,121 @@ import CoreData
// MARK: - CSBaseDataTransaction
/**
The `CSBaseDataTransaction` serves as the Objective-C bridging type for `BaseDataTransaction`.
- SeeAlso: `BaseDataTransaction`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public class CSBaseDataTransaction: NSObject {
// MARK: Object management
/**
Indicates if the transaction has pending changes
*/
@objc
public var hasChanges: Bool {
return self.swiftTransaction.hasChanges
}
/**
Creates a new `NSManagedObject` with the specified entity type.
- parameter into: the `CSInto` clause indicating the destination `NSManagedObject` entity type and the destination configuration
- returns: a new `NSManagedObject` instance of the specified entity type.
*/
@objc
public func createInto(_ into: CSInto) -> Any {
return self.swiftTransaction.create(into.bridgeToSwift)
}
/**
Returns an editable proxy of a specified `NSManagedObject`.
- parameter object: the `NSManagedObject` type to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
public func editObject(_ object: NSManagedObject?) -> Any? {
return self.swiftTransaction.edit(object)
}
/**
Returns an editable proxy of the object with the specified `NSManagedObjectID`.
- parameter into: a `CSInto` clause specifying the entity type
- parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
public func editInto(_ into: CSInto, objectID: NSManagedObjectID) -> Any? {
return self.swiftTransaction.edit(into.bridgeToSwift, objectID)
fatalError()
}
@objc
public func createInto(_ into: CSInto) -> Any {
fatalError()
}
@objc
public func editObject(_ object: NSManagedObject?) -> Any? {
fatalError()
}
@objc
public func editInto(_ into: CSInto, objectID: NSManagedObjectID) -> Any? {
fatalError()
}
/**
Deletes a specified `NSManagedObject`.
- parameter object: the `NSManagedObject` to be deleted
*/
@objc
public func deleteObject(_ object: NSManagedObject?) {
self.swiftTransaction.delete(object)
fatalError()
}
/**
Deletes the specified `NSManagedObject`s.
- parameter objects: the `NSManagedObject`s to be deleted
*/
@objc
public func deleteObjects(_ objects: [NSManagedObject]) {
self.swiftTransaction.delete(objects)
fatalError()
}
/**
Refreshes all registered objects `NSManagedObject`s in the transaction.
*/
@objc
public func refreshAndMergeAllObjects() {
self.swiftTransaction.refreshAndMergeAllObjects()
fatalError()
}
// MARK: Inspecting Pending Objects
/**
Returns all pending `NSManagedObject`s of the specified type that were inserted to the transaction. This method should not be called after the `-commit*:` method was called.
- parameter entity: the `NSManagedObject` subclass to filter
- returns: an `NSSet` of pending `NSManagedObject`s of the specified type that were inserted to the transaction.
*/
@objc
public func insertedObjectsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObject> {
return self.swiftTransaction.insertedObjects(entity)
}
/**
Returns all pending `NSManagedObjectID`s that were inserted to the transaction. This method should not be called after the `-commit*:` method was called.
- returns: an `NSSet` of pending `NSManagedObjectID`s that were inserted to the transaction.
*/
@objc
public func insertedObjectIDs() -> Set<NSManagedObjectID> {
return self.swiftTransaction.insertedObjectIDs()
}
/**
Returns all pending `NSManagedObjectID`s of the specified type that were inserted to the transaction. This method should not be called after the `-commit*:` method was called.
- parameter entity: the `NSManagedObject` subclass to filter
- returns: an `NSSet` of pending `NSManagedObjectID`s of the specified type that were inserted to the transaction.
*/
@objc
public func insertedObjectIDsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
return self.swiftTransaction.insertedObjectIDs(entity)
}
/**
Returns all pending `NSManagedObject`s of the specified type that were updated in the transaction. This method should not be called after the `-commit*:` method was called.
- parameter entity: the `NSManagedObject` subclass to filter
- returns: an `NSSet` of pending `NSManagedObject`s of the specified type that were updated in the transaction.
*/
@objc
public func updatedObjectsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObject> {
return self.swiftTransaction.updatedObjects(entity)
}
/**
Returns all pending `NSManagedObjectID`s that were updated in the transaction. This method should not be called after the `-commit*:` method was called.
- returns: an `NSSet` of pending `NSManagedObjectID`s that were updated in the transaction.
*/
@objc
public func updatedObjectIDs() -> Set<NSManagedObjectID> {
return self.swiftTransaction.updatedObjectIDs()
}
/**
Returns all pending `NSManagedObjectID`s of the specified type that were updated in the transaction. This method should not be called after the `-commit*:` method was called.
- parameter entity: the `NSManagedObject` subclass to filter
- returns: an `NSSet` of pending `NSManagedObjectID`s of the specified type that were updated in the transaction.
*/
@objc
public func updatedObjectIDsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
return self.swiftTransaction.updatedObjectIDs(entity)
}
/**
Returns all pending `NSManagedObject`s of the specified type that were deleted from the transaction. This method should not be called after the `-commit*:` method was called.
- parameter entity: the `NSManagedObject` subclass to filter
- returns: an `NSSet` of pending `NSManagedObject`s of the specified type that were deleted from the transaction.
*/
@objc
public func deletedObjectsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObject> {
return self.swiftTransaction.deletedObjects(entity)
}
/**
Returns all pending `NSManagedObjectID`s of the specified type that were deleted from the transaction. This method should not be called after the `-commit*:` method was called.
- returns: an `NSSet` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
*/
@objc
public func deletedObjectIDs() -> Set<NSManagedObjectID> {
return self.swiftTransaction.deletedObjectIDs()
fatalError()
}
@objc
public func insertedObjectIDs() -> Set<NSManagedObjectID> {
fatalError()
}
@objc
public func insertedObjectIDsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
fatalError()
}
@objc
public func updatedObjectsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObject> {
fatalError()
}
@objc
public func updatedObjectIDs() -> Set<NSManagedObjectID> {
fatalError()
}
@objc
public func updatedObjectIDsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
fatalError()
}
@objc
public func deletedObjectsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObject> {
fatalError()
}
@objc
public func deletedObjectIDs() -> Set<NSManagedObjectID> {
fatalError()
}
/**
Returns all pending `NSManagedObjectID`s of the specified type that were deleted from the transaction. This method should not be called after the `-commit*:` method was called.
- parameter entity: the `NSManagedObject` subclass to filter
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
*/
@objc
public func deletedObjectIDsOfType(_ entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
return self.swiftTransaction.deletedObjectIDs(entity)
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return ObjectIdentifier(self.swiftTransaction).hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSBaseDataTransaction else {
return false
}
return self.swiftTransaction === object.swiftTransaction
}
// MARK: Internal
internal let swiftTransaction: BaseDataTransaction
internal init(_ swiftValue: BaseDataTransaction) {
self.swiftTransaction = swiftValue
super.init()
fatalError()
}
}

View File

@@ -29,11 +29,7 @@ import CoreData
// MARK: - CSFetchClause
/**
The `CSFetchClause` implement clauses used to configure `NSFetchRequest`s.
- SeeAlso: `FetchClause`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public protocol CSFetchClause {
@@ -44,11 +40,7 @@ public protocol CSFetchClause {
// MARK: - CSQueryClause
/**
The `CSQueryClause` implement clauses used to configure `NSFetchRequest`s.
- SeeAlso: `QueryClause`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public protocol CSQueryClause {
@@ -59,11 +51,7 @@ public protocol CSQueryClause {
// MARK: - CSDeleteClause
/**
The `CSDeleteClause` implement clauses used to configure `NSFetchRequest`s.
- SeeAlso: `DeleteClause`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public protocol CSDeleteClause {

View File

@@ -28,33 +28,14 @@ import Foundation
// MARK: - CSCoreStore
/**
The `CSCoreStore` serves as the Objective-C bridging type for `CoreStore`.
- SeeAlso: `CoreStore`
*/
@available(*, deprecated, message: "Call methods directly from the CSDataStack instead")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSCoreStore: NSObject {
/**
The default `CSDataStack` instance to be used. If `defaultStack` is not set before the first time accessed, a default-configured `CSDataStack` will be created.
- SeeAlso: `CSDataStack`
- Note: Changing the `defaultStack` is thread safe, but it is recommended to setup `CSDataStacks` on a common queue (e.g. the main queue).
*/
@objc
public static var defaultStack: CSDataStack {
get { return CoreStoreDefaults.dataStack.bridgeToObjectiveC }
set { CoreStoreDefaults.dataStack = newValue.bridgeToSwift }
}
// MARK: Private
private override init() {
fatalError()
get { fatalError() }
set { fatalError() }
}
}

View File

@@ -29,99 +29,30 @@ import CoreData
// MARK: - CSDataStack
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension CSDataStack {
/**
Asynchronously adds a `CSInMemoryStore` to the stack. Migrations are also initiated by default.
```
NSError *error;
NSProgress *migrationProgress = [dataStack
addInMemoryStorage:[CSInMemoryStore new]
completion:^(CSSetupResult *result) {
if (result.isSuccess) {
// ...
}
}
error: &error];
```
- parameter storage: the `CSInMemoryStore` instance
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `CSSetupResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a failure `CSSetupResult` result if an error occurs asynchronously.
*/
@objc
public func addInMemoryStorage(_ storage: CSInMemoryStore, completion: @escaping (CSSetupResult) -> Void) {
self.bridgeToSwift.addStorage(
storage.bridgeToSwift,
completion: { completion($0.bridgeToObjectiveC) }
)
fatalError()
}
/**
Asynchronously adds a `CSSQLiteStore` to the stack. Migrations are also initiated by default.
```
NSError *error;
NSProgress *migrationProgress = [dataStack
addInMemoryStorage:[[CSSQLiteStore alloc]
initWithFileName:@"core_data.sqlite"
configuration:@"Config1"]
completion:^(CSSetupResult *result) {
if (result.isSuccess) {
// ...
}
}
error: &error];
```
- parameter storage: the `CSSQLiteStore` instance
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `CSSetupResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a failure `CSSetupResult` result if an error occurs asynchronously. Note that the `CSLocalStorage` associated to the `-[CSSetupResult storage]` may not always be the same instance as the parameter argument if a previous `CSLocalStorage` was already added at the same URL and with the same configuration.
- parameter error: the `NSError` pointer that indicates the reason in case of an failure
- returns: an `NSProgress` instance if a migration has started. `nil` if no migrations are required or if `error` was set.
*/
@objc
public func addSQLiteStorage(_ storage: CSSQLiteStore, completion: @escaping (CSSetupResult) -> Void, error: NSErrorPointer) -> Progress? {
return bridge(error) {
self.bridgeToSwift.addStorage(
storage.bridgeToSwift,
completion: { completion($0.bridgeToObjectiveC) }
)
}
fatalError()
}
/**
Migrates a `CSSQLiteStore` to match the `CSDataStack`'s managed object model version. This method does NOT add the migrated store to the data stack.
- parameter storage: the `CSSQLiteStore` instance
- parameter completion: the closure to be executed on the main queue when the migration completes, either due to success or failure. The closure's `CSMigrationResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a failure `CSSetupResult` result if an error occurs asynchronously.
- parameter error: the `NSError` pointer that indicates the reason in case of an failure
- returns: an `NSProgress` instance if a migration has started. `nil` if no migrations are required or if `error` was set.
*/
@objc
public func upgradeStorageIfNeeded(_ storage: CSSQLiteStore, completion: @escaping (CSMigrationResult) -> Void, error: NSErrorPointer) -> Progress? {
return bridge(error) {
try self.bridgeToSwift.upgradeStorageIfNeeded(
storage.bridgeToSwift,
completion: { completion($0.bridgeToObjectiveC) }
)
}
fatalError()
}
/**
Checks the migration steps required for the `CSSQLiteStore` to match the `CSDataStack`'s managed object model version.
- parameter storage: the `CSSQLiteStore` instance
- parameter error: the `NSError` pointer that indicates the reason in case of an failure
- returns: a `CSMigrationType` array indicating the migration steps required for the store, or an empty array if the file does not exist yet. Otherwise, `nil` is returned and the `error` argument is set if either inspection of the store failed, or if no mapping model was found/inferred.
*/
@objc
public func requiredMigrationsForSQLiteStore(_ storage: CSSQLiteStore, error: NSErrorPointer) -> [CSMigrationType]? {
return bridge(error) {
try self.bridgeToSwift.requiredMigrationsForStorage(storage.bridgeToSwift)
}
fatalError()
}
}

View File

@@ -29,143 +29,35 @@ import CoreData
// MARK: - CSDataStack
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension CSDataStack {
/**
Creates a `CSObjectMonitor` for the specified `NSManagedObject`. Multiple `ObjectObserver`s may then register themselves to be notified when changes are made to the `NSManagedObject`.
- parameter object: the `NSManagedObject` to observe changes from
- returns: an `ObjectMonitor` that monitors changes to `object`
*/
@objc
public func monitorObject(_ object: NSManagedObject) -> CSObjectMonitor {
return self.bridgeToSwift.monitorObject(object).bridgeToObjectiveC
fatalError()
}
/**
Creates a `CSListMonitor` for a list of `NSManagedObject`s that satisfy the specified fetch clauses. Multiple `CSListObserver`s may then register themselves to be notified when changes are made to the list.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: a `CSListMonitor` instance that monitors changes to the list
*/
@objc
public func monitorListFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> CSListMonitor {
Internals.assert(
Thread.isMainThread,
"Attempted to observe objects from \(Internals.typeName(self)) outside the main thread."
)
Internals.assert(
fetchClauses.contains { $0 is CSOrderBy },
"A CSListMonitor requires a CSOrderBy clause."
)
return ListMonitor(
dataStack: self.bridgeToSwift,
from: from.bridgeToSwift,
sectionBy: nil,
applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
}
).bridgeToObjectiveC
fatalError()
}
/**
Asynchronously creates a `CSListMonitor` for a list of `NSManagedObject`s that satisfy the specified fetch clauses. Multiple `CSListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
- parameter createAsynchronously: the closure that receives the created `CSListMonitor` instance
- parameter from: a `CSFrom` clause indicating the entity type
- parameter fetchClauses: a series of `CSFetchClause` instances for fetching the object list. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
*/
@objc
public func monitorListByCreatingAsynchronously(_ createAsynchronously: @escaping (CSListMonitor) -> Void, from: CSFrom, fetchClauses: [CSFetchClause]) {
Internals.assert(
Thread.isMainThread,
"Attempted to observe objects from \(Internals.typeName(self)) outside the main thread."
)
Internals.assert(
fetchClauses.contains { $0 is CSOrderBy },
"A CSListMonitor requires an CSOrderBy clause."
)
_ = ListMonitor(
dataStack: self.bridgeToSwift,
from: from.bridgeToSwift,
sectionBy: nil,
applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
},
createAsynchronously: {
createAsynchronously($0.bridgeToObjectiveC)
}
)
fatalError()
}
/**
Creates a `CSListMonitor` for a sectioned list of `NSManagedObject`s that satisfy the specified fetch clauses. Multiple `ListObserver`s may then register themselves to be notified when changes are made to the list.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter sectionBy: a `CSSectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: a `CSListMonitor` instance that monitors changes to the list
*/
@objc
public func monitorSectionedListFrom(_ from: CSFrom, sectionBy: CSSectionBy, fetchClauses: [CSFetchClause]) -> CSListMonitor {
Internals.assert(
Thread.isMainThread,
"Attempted to observe objects from \(Internals.typeName(self)) outside the main thread."
)
Internals.assert(
fetchClauses.contains { $0 is CSOrderBy },
"A CSListMonitor requires an CSOrderBy clause."
)
return ListMonitor(
dataStack: self.bridgeToSwift,
from: from.bridgeToSwift,
sectionBy: sectionBy.bridgeToSwift,
applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
}
).bridgeToObjectiveC
fatalError()
}
/**
Asynchronously creates a `CSListMonitor` for a sectioned list of `NSManagedObject`s that satisfy the specified fetch clauses. Multiple `CSListObserver`s may then register themselves to be notified when changes are made to the list. Since `NSFetchedResultsController` greedily locks the persistent store on initial fetch, you may prefer this method instead of the synchronous counterpart to avoid deadlocks while background updates/saves are being executed.
- parameter createAsynchronously: the closure that receives the created `CSListMonitor` instance
- parameter from: a `CSFrom` clause indicating the entity type
- parameter sectionBy: a `CSSectionBy` clause indicating the keyPath for the attribute to use when sorting the list into sections.
- parameter fetchClauses: a series of `CSFetchClause` instances for fetching the object list. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
*/
public func monitorSectionedListByCreatingAsynchronously(_ createAsynchronously: @escaping (CSListMonitor) -> Void, from: CSFrom, sectionBy: CSSectionBy, fetchClauses: [CSFetchClause]) {
Internals.assert(
Thread.isMainThread,
"Attempted to observe objects from \(Internals.typeName(self)) outside the main thread."
)
Internals.assert(
fetchClauses.contains { $0 is CSOrderBy },
"A CSListMonitor requires an CSOrderBy clause."
)
_ = ListMonitor(
dataStack: self.bridgeToSwift,
from: from.bridgeToSwift,
sectionBy: sectionBy.bridgeToSwift,
applyFetchClauses: { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
},
createAsynchronously: {
createAsynchronously($0.bridgeToObjectiveC)
}
)
fatalError()
}
}

View File

@@ -29,186 +29,72 @@ import CoreData
// MARK: - CSDataStack
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension CSDataStack {
/**
Fetches the `NSManagedObject` instance in the transaction's context from a reference created from a transaction or from a different managed object context.
- 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.
*/
@objc
public func fetchExistingObject(_ object: NSManagedObject) -> Any? {
return self.bridgeToSwift.mainContext.fetchExisting(object) as NSManagedObject?
fatalError()
}
/**
Fetches the `NSManagedObject` instance in the transaction's context from an `NSManagedObjectID`.
- parameter objectID: the `NSManagedObjectID` for the object
- returns: the `NSManagedObject` instance if the object exists in the transaction, or `nil` if not found.
*/
@objc
public func fetchExistingObjectWithID(_ objectID: NSManagedObjectID) -> Any? {
return self.bridgeToSwift.mainContext.fetchExisting(objectID) as NSManagedObject?
fatalError()
}
/**
Fetches the `NSManagedObject` instances in the transaction's context from references created from a transaction or from a different managed object context.
- parameter objects: an array of `NSManagedObject`s created/fetched outside the transaction
- returns: the `NSManagedObject` array for objects that exists in the transaction
*/
@objc
public func fetchExistingObjects(_ objects: [NSManagedObject]) -> [Any] {
return self.bridgeToSwift.mainContext.fetchExisting(objects) as [NSManagedObject]
fatalError()
}
/**
Fetches the `NSManagedObject` instances in the transaction's context from a list of `NSManagedObjectID`.
- parameter objectIDs: the `NSManagedObjectID` array for the objects
- returns: the `NSManagedObject` array for objects that exists in the transaction
*/
@objc
public func fetchExistingObjectsWithIDs(_ objectIDs: [NSManagedObjectID]) -> [Any] {
return self.bridgeToSwift.mainContext.fetchExisting(objectIDs) as [NSManagedObject]
fatalError()
}
/**
Fetches the first `NSManagedObject` instance that satisfies the specified `CSFetchClause`s. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- parameter from: a `From` clause indicating the entity type
- parameter fetchClauses: a series of `CSFetchClause` instances for the fetch request. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: the first `NSManagedObject` instance that satisfies the specified `CSFetchClause`s
*/
@objc
public func fetchOneFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> Any? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
)
return (try? self.bridgeToSwift.mainContext.fetchOne(from, fetchClauses))?
.flatMap({ $0 })
fatalError()
}
/**
Fetches all `NSManagedObject` instances that satisfy the specified `CSFetchClause`s. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter fetchClauses: a series of `CSFetchClause` instances for the fetch request. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: all `NSManagedObject` instances that satisfy the specified `CSFetchClause`s
*/
@objc
public func fetchAllFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> [Any]? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
)
return (try? self.bridgeToSwift.mainContext.fetchAll(from, fetchClauses))
.flatMap({ $0 })
fatalError()
}
/**
Fetches the number of `NSManagedObject`s that satisfy the specified `CSFetchClause`s. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter fetchClauses: a series of `CSFetchClause` instances for the fetch request. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: the number `NSManagedObject`s that satisfy the specified `CSFetchClause`s
*/
@objc
public func fetchCountFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> NSNumber? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
)
return (try? self.bridgeToSwift.mainContext.fetchCount(from, fetchClauses))
.flatMap({ NSNumber(value: $0) })
fatalError()
}
/**
Fetches the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `CSFetchClause`s. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter fetchClauses: a series of `CSFetchClause` instances for the fetch request. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: the `NSManagedObjectID` for the first `NSManagedObject` that satisfies the specified `CSFetchClause`s
*/
@objc
public func fetchObjectIDFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> NSManagedObjectID? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
)
return (try? self.bridgeToSwift.mainContext.fetchObjectID(from, fetchClauses))?
.flatMap({ $0 })
fatalError()
}
/**
Fetches the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `CSFetchClause`s. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter fetchClauses: a series of `FetchClause` instances for the fetch request. Accepts `CSWhere`, `CSOrderBy`, and `CSTweak` clauses.
- returns: the `NSManagedObjectID` for all `NSManagedObject`s that satisfy the specified `CSFetchClause`s
*/
@objc
public func fetchObjectIDsFrom(_ from: CSFrom, fetchClauses: [CSFetchClause]) -> [NSManagedObjectID]? {
Internals.assert(
Thread.isMainThread,
"Attempted to fetch from a \(Internals.typeName(self)) outside the main thread."
)
return (try? self.bridgeToSwift.mainContext.fetchObjectIDs(from, fetchClauses))
.flatMap({ $0 })
fatalError()
}
/**
Queries aggregate values as specified by the `CSQueryClause`s. Requires at least a `CSSelect` clause, and optional `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter selectClause: a `CSSelect` clause indicating the properties to fetch, and with the generic type indicating the return type.
- parameter queryClauses: a series of `CSQueryClause` instances for the query request. Accepts `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `CSSelect` parameter.
*/
@objc
public func queryValueFrom(_ from: CSFrom, selectClause: CSSelect, queryClauses: [CSQueryClause]) -> Any? {
Internals.assert(
Thread.isMainThread,
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
)
return (try? self.bridgeToSwift.mainContext.queryValue(from, selectClause, queryClauses))
.flatMap({ $0 })
fatalError()
}
/**
Queries a dictionary of attribute values as specified by the `CSQueryClause`s. Requires at least a `CSSelect` clause, and optional `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter selectClause: a `CSSelect` clause indicating the properties to fetch, and with the generic type indicating the return type.
- parameter queryClauses: a series of `CSQueryClause` instances for the query request. Accepts `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `CSSelect` parameter.
*/
@objc
public func queryAttributesFrom(_ from: CSFrom, selectClause: CSSelect, queryClauses: [CSQueryClause]) -> [[String: Any]]? {
Internals.assert(
Thread.isMainThread,
"Attempted to query from a \(Internals.typeName(self)) outside the main thread."
)
return (try? self.bridgeToSwift.mainContext.queryAttributes(from, selectClause, queryClauses))
.flatMap({ $0 })
fatalError()
}
}

View File

@@ -28,108 +28,36 @@ import Foundation
// MARK: - CSDataStack
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension CSDataStack {
/**
Begins a transaction asynchronously where `NSManagedObject` creates, updates, and deletes can be made.
- parameter closure: the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`.
*/
@objc
public func beginAsynchronous(_ closure: @escaping (_ transaction: CSAsynchronousDataTransaction) -> Void) {
self.bridgeToSwift.perform(
asynchronous: { (transaction) in
let csTransaction = transaction.bridgeToObjectiveC
closure(csTransaction)
if !transaction.isCommitted && transaction.hasChanges {
Internals.log(
.warning,
message: "The closure for the \(Internals.typeName(csTransaction)) completed without being committed. All changes made within the transaction were discarded."
)
}
try transaction.cancel()
},
completion: { _ in }
)
fatalError()
}
/**
Begins a transaction synchronously where `NSManagedObject` creates, updates, and deletes can be made.
- parameter closure: the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`.
- parameter error: the `CSError` pointer that indicates the reason in case of an failure
- returns: `YES` if the commit succeeded, `NO` if the commit failed. If `NO`, the `error` argument will hold error information.
*/
@objc
public func beginSynchronous(_ closure: @escaping (_ transaction: CSSynchronousDataTransaction) -> Void, error: NSErrorPointer) -> Bool {
return bridge(error) {
do {
try self.bridgeToSwift.perform(
synchronous: { (transaction) in
let csTransaction = transaction.bridgeToObjectiveC
closure(csTransaction)
if !transaction.isCommitted && transaction.hasChanges {
Internals.log(
.warning,
message: "The closure for the \(Internals.typeName(csTransaction)) completed without being committed. All changes made within the transaction were discarded."
)
}
try transaction.cancel()
}
)
}
catch CoreStoreError.userCancelled {
return
}
}
fatalError()
}
/**
Begins a child transaction where `NSManagedObject` creates, updates, and deletes can be made. This is useful for making temporary changes, such as partially filled forms.
To support "undo" methods such as `-undo`, `-redo`, and `-rollback`, use the `-beginSafeWithSupportsUndo:` method passing `YES` to the argument. Without "undo" support, calling those methods will raise an exception.
- returns: a `CSUnsafeDataTransaction` instance where creates, updates, and deletes can be made.
*/
@objc
public func beginUnsafe() -> CSUnsafeDataTransaction {
return bridge {
self.bridgeToSwift.beginUnsafe()
}
fatalError()
}
/**
Begins a child transaction where `NSManagedObject` creates, updates, and deletes can be made. This is useful for making temporary changes, such as partially filled forms.
- prameter supportsUndo: `-undo`, `-redo`, and `-rollback` methods are only available when this parameter is `YES`, otherwise those method will raise an exception. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited.
- returns: a `CSUnsafeDataTransaction` instance where creates, updates, and deletes can be made.
*/
@objc
public func beginUnsafeWithSupportsUndo(_ supportsUndo: Bool) -> CSUnsafeDataTransaction {
return bridge {
self.bridgeToSwift.beginUnsafe(supportsUndo: supportsUndo)
}
fatalError()
}
/**
Refreshes all registered objects `NSManagedObject`s in the `DataStack`.
*/
@objc
public func refreshAndMergeAllObjects() {
self.bridgeToSwift.refreshAndMergeAllObjects()
fatalError()
}
}

View File

@@ -29,170 +29,84 @@ import CoreData
// MARK: - CSDataStack
/**
The `CSDataStack` serves as the Objective-C bridging type for `DataStack`.
- SeeAlso: `DataStack`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
/**
Initializes a `CSDataStack` with default settings. CoreStore searches for <CFBundleName>.xcdatamodeld from the main `NSBundle` and loads an `NSManagedObjectModel` from it. An assertion is raised if the model could not be found.
*/
@objc
public convenience override init() {
self.init(DataStack())
fatalError()
}
/**
Initializes a `CSDataStack` from the model with the specified `modelName` in the specified `bundle`.
- parameter xcodeModelName: the name of the (.xcdatamodeld) model file. If not specified, the application name (CFBundleName) will be used if it exists, or "CoreData" if it the bundle name was not set.
- parameter bundle: an optional bundle to load .xcdatamodeld models from. If not specified, the main bundle will be used.
- parameter versionChain: the version strings that indicate the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
*/
@objc
public convenience init(xcodeModelName: XcodeDataModelFileName?, bundle: Bundle?, versionChain: [String]?) {
self.init(
DataStack(
xcodeModelName: xcodeModelName ?? DataStack.applicationName,
bundle: bundle ?? Bundle.main,
migrationChain: versionChain.flatMap { MigrationChain($0) } ?? nil
)
)
fatalError()
}
/**
Returns the stack's model version. The version string is the same as the name of the version-specific .xcdatamodeld file.
*/
@objc
public var modelVersion: String {
return self.bridgeToSwift.modelVersion
fatalError()
}
/**
Returns the entity name-to-class type mapping from the `CSDataStack`'s model.
*/
@objc
public func entityTypesByNameForType(_ type: NSManagedObject.Type) -> [EntityName: NSManagedObject.Type] {
return self.bridgeToSwift.entityTypesByName(for: type)
fatalError()
}
/**
Returns the `NSEntityDescription` for the specified `NSManagedObject` subclass from stack's model.
*/
@objc
public func entityDescriptionForClass(_ type: NSManagedObject.Type) -> NSEntityDescription? {
return self.bridgeToSwift.entityDescription(for: type)
fatalError()
}
/**
Creates an `CSInMemoryStore` with default parameters and adds it to the stack. This method blocks until completion.
```
CSSQLiteStore *storage = [dataStack addInMemoryStorageAndWaitAndReturnError:&error];
```
- parameter error: the `NSError` pointer that indicates the reason in case of an failure
- returns: the `CSInMemoryStore` added to the stack
*/
@objc
@discardableResult
public func addInMemoryStorageAndWaitAndReturnError(_ error: NSErrorPointer) -> CSInMemoryStore? {
return bridge(error) {
try self.bridgeToSwift.addStorageAndWait(InMemoryStore())
}
fatalError()
}
/**
Creates an `CSSQLiteStore` with default parameters and adds it to the stack. This method blocks until completion.
```
CSSQLiteStore *storage = [dataStack addSQLiteStorageAndWaitAndReturnError:&error];
```
- parameter error: the `NSError` pointer that indicates the reason in case of an failure
- returns: the `CSSQLiteStore` added to the stack
*/
@objc
@discardableResult
public func addSQLiteStorageAndWaitAndReturnError(_ error: NSErrorPointer) -> CSSQLiteStore? {
return bridge(error) {
try self.bridgeToSwift.addStorageAndWait(SQLiteStore())
}
fatalError()
}
/**
Adds a `CSInMemoryStore` to the stack and blocks until completion.
```
NSError *error;
CSInMemoryStore *storage = [dataStack
addStorageAndWait: [[CSInMemoryStore alloc] initWithConfiguration: @"Config1"]
error: &error];
```
- parameter storage: the `CSInMemoryStore`
- parameter error: the `NSError` pointer that indicates the reason in case of an failure
- returns: the `CSInMemoryStore` added to the stack
*/
@objc
@discardableResult
public func addInMemoryStorageAndWait(_ storage: CSInMemoryStore, error: NSErrorPointer) -> CSInMemoryStore? {
return bridge(error) {
try self.bridgeToSwift.addStorageAndWait(storage.bridgeToSwift)
}
fatalError()
}
/**
Adds a `CSSQLiteStore` to the stack and blocks until completion.
```
NSError *error;
CSSQLiteStore *storage = [dataStack
addStorageAndWait: [[CSSQLiteStore alloc] initWithConfiguration: @"Config1"]
error: &error];
```
- parameter storage: the `CSSQLiteStore`
- parameter error: the `NSError` pointer that indicates the reason in case of an failure
- returns: the `CSSQLiteStore` added to the stack
*/
@objc
@discardableResult
public func addSQLiteStorageAndWait(_ storage: CSSQLiteStore, error: NSErrorPointer) -> CSSQLiteStore? {
return bridge(error) {
try self.bridgeToSwift.addStorageAndWait(storage.bridgeToSwift)
}
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return ObjectIdentifier(self.bridgeToSwift).hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSDataStack else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -201,22 +115,21 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
public let bridgeToSwift: DataStack
public init(_ swiftValue: DataStack) {
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
}
// MARK: - DataStack
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension DataStack: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSDataStack {
return CSDataStack(self)
fatalError()
}
}

View File

@@ -29,23 +29,13 @@ import Foundation
// MARK: - CSDynamicSchema
/**
The `CSDynamicSchema` serves as the Objective-C bridging type for `DynamicSchema`.
- SeeAlso: `DynamicSchema`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public protocol CSDynamicSchema {
/**
The version string for this model schema.
*/
@objc
var modelVersion: ModelVersion { get }
/**
Do not call this directly. The `NSManagedObjectModel` for this schema may be created lazily and using this method directly may affect the integrity of the model.
*/
@objc
func rawModel() -> NSManagedObjectModel
}

View File

@@ -29,281 +29,75 @@ import CoreData
// MARK: - CSError
/**
All errors thrown from CoreStore are expressed in `CSError`s.
- SeeAlso: `CoreStoreError`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSError: NSError {
/**
The `NSError` error domain for `CSError`.
- SeeAlso: `CoreStoreErrorErrorDomain`
*/
// MARK: Public
@objc
public static let errorDomain = CoreStoreErrorDomain
public var bridgeToSwift: CoreStoreError {
if let swift = self.swiftError {
return swift
}
let swift = CoreStoreError(_bridgedNSError: self) ?? .unknown
self.swiftError = swift
return swift
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return self.bridgeToSwift.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSError else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
/**
Do not call directly!
*/
public init(_ swiftValue: CoreStoreError) {
self.swiftError = swiftValue
super.init(domain: CoreStoreError.errorDomain, code: swiftValue.errorCode, userInfo: swiftValue.errorUserInfo)
fatalError()
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
// MARK: Private
private var swiftError: CoreStoreError?
}
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
extension CSError: CoreStoreObjectiveCType {}
fatalError()
}
}
// MARK: - CSErrorCode
/**
The `NSError` error codes for `CSError.Domain`.
- SeeAlso: `CSError`
- SeeAlso: `CoreStoreError`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public enum CSErrorCode: Int {
/**
A failure occured because of an unknown error.
*/
case unknownError
/**
The `NSPersistentStore` could note be initialized because another store existed at the specified `NSURL`.
*/
case differentStorageExistsAtURL
/**
An `NSMappingModel` could not be found for a specific source and destination model versions.
*/
case mappingModelNotFound
/**
Progressive migrations are disabled for a store, but an `NSMappingModel` could not be found for a specific source and destination model versions.
*/
case progressiveMigrationRequired
/**
An internal SDK call failed with the specified "NSError" userInfo key.
*/
case internalError
/**
The transaction was terminated by a user-thrown error with the specified "Error" userInfo key.
*/
case userError
/**
The transaction was cancelled by the user.
*/
case userCancelled
}
// MARK: - CoreStoreError
extension CoreStoreError: _ObjectiveCBridgeableError {
// MARK: _ObjectiveCBridgeableError
public init?(_bridgedNSError error: NSError) {
guard error.domain == CoreStoreErrorDomain else {
if error is CSError {
self = .internalError(NSError: error)
return
}
return nil
}
guard let code = CoreStoreErrorCode(rawValue: error.code) else {
if error is CSError {
self = .unknown
return
}
return nil
}
let info = error.userInfo
switch code {
case .unknownError:
self = .unknown
case .differentStorageExistsAtURL:
guard case let existingPersistentStoreURL as URL = info["existingPersistentStoreURL"] else {
self = .unknown
return
}
self = .differentStorageExistsAtURL(existingPersistentStoreURL: existingPersistentStoreURL)
case .mappingModelNotFound:
guard let localStoreURL = info["localStoreURL"] as? URL,
let targetModel = info["targetModel"] as? NSManagedObjectModel,
let targetModelVersion = info["targetModelVersion"] as? String else {
self = .unknown
return
}
self = .mappingModelNotFound(localStoreURL: localStoreURL, targetModel: targetModel, targetModelVersion: targetModelVersion)
case .progressiveMigrationRequired:
guard let localStoreURL = info["localStoreURL"] as? URL else {
self = .unknown
return
}
self = .progressiveMigrationRequired(localStoreURL: localStoreURL)
case .asynchronousMigrationRequired:
guard
let localStoreURL = info["localStoreURL"] as? URL,
case let nsError as NSError = info["NSError"]
else {
self = .unknown
return
}
self = .asynchronousMigrationRequired(localStoreURL: localStoreURL, NSError: nsError)
case .internalError:
guard case let nsError as NSError = info["NSError"] else {
self = .unknown
return
}
self = .internalError(NSError: nsError)
case .userError:
guard case let error as Error = info["Error"] else {
self = .unknown
return
}
self = .userError(error: error)
case .userCancelled:
self = .userCancelled
case .persistentStoreNotFound:
guard let entity = info["entity"] as? DynamicObject.Type else {
self = .unknown
return
}
self = .persistentStoreNotFound(entity: entity)
}
}
}
// MARK: - Error
extension Error {
// MARK: Internal
internal var bridgeToSwift: CoreStoreError {
switch self {
case let error as CoreStoreError:
return error
case let error as CSError:
return error.bridgeToSwift
case let error as NSError where Self.self is NSError.Type:
return .internalError(NSError: error)
default:
return .unknown
}
}
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
internal var bridgeToObjectiveC: NSError {
switch self {
case let error as CoreStoreError:
return error.bridgeToObjectiveC
case let error as CSError:
return error
default:
return self as NSError
}
}
}
// MARK: - CoreStoreError
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension CoreStoreError: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSError {
return CSError(self)
fatalError()
}
}

View File

@@ -29,115 +29,46 @@ import CoreData
// MARK: - CSFrom
/**
The `CSFrom` serves as the Objective-C bridging type for `From`.
- SeeAlso: `From`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSFrom: NSObject {
/**
The associated `NSManagedObject` entity class
*/
@objc
public var entityClass: AnyClass {
return self.bridgeToSwift.entityClass
fatalError()
}
/**
The `NSPersistentStore` configuration names to associate objects from.
May contain `NSString` instances to pertain to named configurations, or `NSNull` to pertain to the default configuration
*/
@objc
public var configurations: [Any]? {
return self.bridgeToSwift.configurations?.map {
switch $0 {
case nil: return NSNull()
case let string as NSString: return string
}
}
fatalError()
}
/**
Initializes a `CSFrom` clause with the specified entity class.
```
MyPersonEntity *people = [transaction fetchAllFrom:CSFromClass([MyPersonEntity class])];
```
- parameter entityClass: the `NSManagedObject` class type to be created
*/
@objc
public convenience init(entityClass: NSManagedObject.Type) {
self.init(From(entityClass))
fatalError()
}
/**
Initializes a `CSFrom` clause with the specified configurations.
```
MyPersonEntity *people = [transaction fetchAllFrom:
CSFromClass([MyPersonEntity class], @"Config1")];
```
- parameter entityClass: the associated `NSManagedObject` entity class
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `[NSNull null]` to use the default configuration.
*/
@objc
public convenience init(entityClass: NSManagedObject.Type, configuration: Any) {
switch configuration {
case let string as String:
self.init(From(entityClass, string))
case is NSNull:
self.init(From(entityClass, nil))
default:
Internals.abort("The configuration argument only accepts NSString and NSNull values")
}
fatalError()
}
/**
Initializes a `CSFrom` clause with the specified configurations.
```
MyPersonEntity *people = [transaction fetchAllFrom:
CSFromClass([MyPersonEntity class],
@[[NSNull null], @"Config1"])];
```
- parameter entityClass: the associated `NSManagedObject` entity class
- parameter configurations: an array of the `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `[NSNull null]` to use the default configuration.
*/
@objc
public convenience init(entityClass: NSManagedObject.Type, configurations: [Any]) {
var arguments = [ModelConfiguration]()
for configuration in configurations {
switch configuration {
case let string as String:
arguments.append(string)
case is NSNull:
arguments.append(nil)
default:
Internals.abort("The configurations argument only accepts NSString and NSNull values")
}
}
self.init(From(entityClass, arguments))
fatalError()
}
// MARK: NSObject
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -146,33 +77,21 @@ public final class CSFrom: NSObject {
public let bridgeToSwift: From<NSManagedObject>
public init<O: NSManagedObject>(_ swiftValue: From<O>) {
self.bridgeToSwift = swiftValue.downcast()
super.init()
fatalError()
}
}
// MARK: - From
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension From where O: NSManagedObject {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSFrom {
return CSFrom(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> From<NSManagedObject> {
return From<NSManagedObject>(
entityClass: self.entityClass,
configurations: self.configurations,
findPersistentStores: self.findPersistentStores
)
fatalError()
}
}

View File

@@ -29,65 +29,44 @@ import CoreData
// MARK: - CSGroupBy
/**
The `CSGroupBy` serves as the Objective-C bridging type for `GroupBy`.
- SeeAlso: `GroupBy`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSGroupBy: NSObject, CSQueryClause {
/**
The list of key path strings to group results with
*/
@objc
public var keyPaths: [KeyPathString] {
return self.bridgeToSwift.keyPaths
fatalError()
}
/**
Initializes a `CSGroupBy` clause with a key path string
- parameter keyPath: a key path string to group results with
*/
@objc
public convenience init(keyPath: KeyPathString) {
self.init(GroupBy(keyPath))
fatalError()
}
/**
Initializes a `CSGroupBy` clause with a list of key path strings
- parameter keyPaths: a list of key path strings to group results with
*/
@objc
public convenience init(keyPaths: [KeyPathString]) {
self.init(GroupBy(keyPaths))
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return self.bridgeToSwift.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSGroupBy else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -95,8 +74,8 @@ public final class CSGroupBy: NSObject, CSQueryClause {
@objc
public func applyToFetchRequest(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) {
self.bridgeToSwift.applyToFetchRequest(fetchRequest)
fatalError()
}
@@ -105,29 +84,21 @@ public final class CSGroupBy: NSObject, CSQueryClause {
public let bridgeToSwift: GroupBy<NSManagedObject>
public init<O: NSManagedObject>(_ swiftValue: GroupBy<O>) {
self.bridgeToSwift = swiftValue.downcast()
super.init()
fatalError()
}
}
// MARK: - GroupBy
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension GroupBy where O: NSManagedObject {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSGroupBy {
return CSGroupBy(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> GroupBy<NSManagedObject> {
return GroupBy<NSManagedObject>(self.keyPaths)
fatalError()
}
}

View File

@@ -29,82 +29,56 @@ import CoreData
// MARK: - CSInMemoryStore
/**
The `CSInMemoryStore` serves as the Objective-C bridging type for `InMemoryStore`.
- SeeAlso: `InMemoryStore`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreObjectiveCType {
/**
Initializes a `CSInMemoryStore` for the specified configuration
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`, the "Default" configuration.
*/
@objc
public convenience init(configuration: ModelConfiguration) {
self.init(InMemoryStore(configuration: configuration))
fatalError()
}
/**
Initializes a `CSInMemoryStore` with the "Default" configuration
*/
@objc
public convenience override init() {
self.init(InMemoryStore())
fatalError()
}
// MARK: StorageInterface
/**
The string identifier for the `NSPersistentStore`'s `type` property. For `CSInMemoryStore`s, this is always set to `NSInMemoryStoreType`.
*/
@objc
public static let storeType = NSInMemoryStoreType
/**
The configuration name in the model file
*/
@objc
public var configuration: ModelConfiguration {
return self.bridgeToSwift.configuration
fatalError()
}
/**
The options dictionary for the `NSPersistentStore`. For `CSInMemoryStore`s, this is always set to `nil`.
*/
@objc
public var storeOptions: [AnyHashable: Any]? {
return self.bridgeToSwift.storeOptions
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return ObjectIdentifier(self.bridgeToSwift).hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSInMemoryStore else {
return false
}
return self.bridgeToSwift === object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -113,22 +87,21 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreObjec
public let bridgeToSwift: InMemoryStore
public required init(_ swiftValue: InMemoryStore) {
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
}
// MARK: - InMemoryStore
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension InMemoryStore: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSInMemoryStore {
return CSInMemoryStore(self)
fatalError()
}
}

View File

@@ -29,82 +29,50 @@ import CoreData
// MARK: - CSInto
/**
The `CSInto` serves as the Objective-C bridging type for `Into<T>`.
- SeeAlso: `Into`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSInto: NSObject {
/**
The associated `NSManagedObject` entity class
*/
@objc
public var entityClass: NSManagedObject.Type {
return self.bridgeToSwift.entityClass
fatalError()
}
/**
The `NSPersistentStore` configuration name to associate objects from.
May contain a `String` to pertain to a named configuration, or `nil` to pertain to the default configuration
*/
@objc
public var configuration: ModelConfiguration {
return self.bridgeToSwift.configuration
fatalError()
}
/**
Initializes a `CSInto` clause with the specified entity class.
```
MyPersonEntity *person = [transaction createInto:
CSIntoClass([MyPersonEntity class])];
```
- parameter entityClass: the `NSManagedObject` class type to be created
*/
@objc
public convenience init(entityClass: NSManagedObject.Type) {
self.init(Into(entityClass))
fatalError()
}
/**
Initializes a `CSInto` clause with the specified configuration.
```
MyPersonEntity *person = [transaction createInto:
CSIntoClass([MyPersonEntity class])];
```
- parameter entityClass: the `NSManagedObject` class type to be created
- parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
*/
@objc
public convenience init(entityClass: NSManagedObject.Type, configuration: ModelConfiguration) {
self.init(Into(entityClass, configuration))
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return self.bridgeToSwift.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSInto else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -113,9 +81,8 @@ public final class CSInto: NSObject {
public let bridgeToSwift: Into<NSManagedObject>
public required init<O: NSManagedObject>(_ swiftValue: Into<O>) {
self.bridgeToSwift = swiftValue.downcast()
super.init()
fatalError()
}
}
@@ -125,21 +92,10 @@ public final class CSInto: NSObject {
extension Into where O: NSManagedObject {
// MARK: CoreStoreSwiftType
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
public var bridgeToObjectiveC: CSInto {
return CSInto(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> Into<NSManagedObject> {
return Into<NSManagedObject>(
entityClass: self.entityClass,
configuration: self.configuration,
inferStoreIfPossible: self.inferStoreIfPossible
)
fatalError()
}
}

View File

@@ -29,503 +29,201 @@ import CoreData
// MARK: - CSListMonitor
/**
The `CSListMonitor` serves as the Objective-C bridging type for `ListMonitor<T>`.
- SeeAlso: `ListMonitor`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSListMonitor: NSObject {
// MARK: Public (Accessors)
/**
Returns the object at the given index within the first section. This subscript indexer is typically used for `CSListMonitor`s created without section groupings.
- parameter index: the index of the object. Using an index above the valid range will raise an exception.
- returns: the `NSManagedObject` at the specified index
*/
@objc
public subscript(index: Int) -> Any {
return self.bridgeToSwift[index]
fatalError()
}
/**
Returns the object at the given index, or `nil` if out of bounds. This indexer is typically used for `CSListMonitor`s created without section groupings.
- parameter index: the index for the object. Using an index above the valid range will return `nil`.
- returns: the `NSManagedObject` at the specified index, or `nil` if out of bounds
*/
@objc
public func objectAtSafeIndex(_ index: Int) -> Any? {
return self.bridgeToSwift[safeIndex: index]
fatalError()
}
/**
Returns the object at the given `sectionIndex` and `itemIndex`. This indexer is typically used for `CSListMonitor`s created as sectioned lists.
- parameter sectionIndex: the section index for the object. Using a `sectionIndex` with an invalid range will raise an exception.
- parameter itemIndex: the index for the object within the section. Using an `itemIndex` with an invalid range will raise an exception.
- returns: the `NSManagedObject` at the specified section and item index
*/
@objc
public func objectAtSectionIndex(_ sectionIndex: Int, itemIndex: Int) -> Any {
return self.bridgeToSwift[sectionIndex, itemIndex]
} /**
Returns the object at the given section and item index, or `nil` if out of bounds. This indexer is typically used for `CSListMonitor`s created as sectioned lists.
- parameter sectionIndex: the section index for the object. Using a `sectionIndex` with an invalid range will return `nil`.
- parameter itemIndex: the index for the object within the section. Using an `itemIndex` with an invalid range will return `nil`.
- returns: the `NSManagedObject` at the specified section and item index, or `nil` if out of bounds
*/
fatalError()
}
@objc
public func objectAtSafeSectionIndex(_ sectionIndex: Int, safeItemIndex itemIndex: Int) -> Any? {
return self.bridgeToSwift[safeSectionIndex: sectionIndex, safeItemIndex: itemIndex]
fatalError()
}
/**
Returns the object at the given `NSIndexPath`. This subscript indexer is typically used for `CSListMonitor`s created as sectioned lists.
- parameter indexPath: the `NSIndexPath` for the object. Using an `indexPath` with an invalid range will raise an exception.
- returns: the `NSManagedObject` at the specified index path
*/
@objc
public func objectAtIndexPath(_ indexPath: IndexPath) -> Any {
return self.bridgeToSwift[indexPath]
fatalError()
}
/**
Returns the object at the given `NSIndexPath`, or `nil` if out of bounds. This subscript indexer is typically used for `CSListMonitor`s created as sectioned lists.
- parameter indexPath: the `NSIndexPath` for the object. Using an `indexPath` with an invalid range will return `nil`.
- returns: the `NSManagedObject` at the specified index path, or `nil` if out of bounds
*/
@objc
public func objectAtSafeIndexPath(_ indexPath: IndexPath) -> Any? {
return self.bridgeToSwift[safeIndexPath: indexPath]
fatalError()
}
/**
Checks if the `CSListMonitor` has at least one object in any section.
- returns: `YES` if at least one object in any section exists, `NO` otherwise
*/
@objc
public func hasObjects() -> Bool {
return self.bridgeToSwift.hasObjects()
fatalError()
}
/**
Checks if the `CSListMonitor` has at least one object the specified section.
- parameter section: the section index. Using an index outside the valid range will return `NO`.
- returns: `YES` if at least one object in the specified section exists, `NO` otherwise
*/
@objc
public func hasObjectsInSection(_ section: Int) -> Bool {
return self.bridgeToSwift.hasObjects(in: section)
fatalError()
}
/**
Returns all objects in all sections
- returns: all objects in all sections
*/
@objc
public func objectsInAllSections() -> [NSManagedObject] {
return self.bridgeToSwift.objectsInAllSections()
fatalError()
}
/**
Returns all objects in the specified section
- parameter section: the section index. Using an index outside the valid range will raise an exception.
- returns: all objects in the specified section
*/
@objc
public func objectsInSection(_ section: Int) -> [NSManagedObject] {
return self.bridgeToSwift.objects(in: section)
fatalError()
}
/**
Returns all objects in the specified section, or `nil` if out of bounds.
- parameter section: the section index. Using an index outside the valid range will return `nil`.
- returns: all objects in the specified section, or `nil` if out of bounds
*/
@objc
public func objectsInSafeSection(safeSectionIndex section: Int) -> [NSManagedObject]? {
return self.bridgeToSwift.objects(safelyIn: section)
fatalError()
}
/**
Returns the number of sections
- returns: the number of sections
*/
@objc
public func numberOfSections() -> Int {
return self.bridgeToSwift.numberOfSections()
}
/**
Returns the number of objects in all sections
- returns: the number of objects in all sections
*/
@objc
public func numberOfObjects() -> Int {
return self.bridgeToSwift.numberOfObjects()
fatalError()
}
@objc
public func numberOfObjects() -> Int {
fatalError()
}
/**
Returns the number of objects in the specified section
- 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
*/
@objc
public func numberOfObjectsInSection(_ section: Int) -> Int {
return self.bridgeToSwift.numberOfObjects(in: section)
fatalError()
}
/**
Returns the number of objects in the specified section, or `nil` if out of bounds.
- parameter section: the section index. Using an index outside the valid range will return `nil`.
- returns: the number of objects in the specified section, or `nil` if out of bounds
*/
@objc
public func numberOfObjectsInSafeSection(safeSectionIndex section: Int) -> NSNumber? {
return self.bridgeToSwift
.numberOfObjects(safelyIn: section)
.flatMap { NSNumber(value: $0) }
fatalError()
}
/**
Returns the `NSFetchedResultsSectionInfo` for the specified section
- parameter section: the section index. Using an index outside the valid range will raise an exception.
- returns: the `NSFetchedResultsSectionInfo` for the specified section
*/
@objc
public func sectionInfoAtIndex(_ section: Int) -> NSFetchedResultsSectionInfo {
return self.bridgeToSwift.sectionInfo(at: section)
fatalError()
}
/**
Returns the `NSFetchedResultsSectionInfo` for the specified section, or `nil` if out of bounds.
- 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.
*/
@objc
public func sectionInfoAtSafeSectionIndex(safeSectionIndex section: Int) -> NSFetchedResultsSectionInfo? {
return self.bridgeToSwift.sectionInfo(safelyAt: section)
fatalError()
}
/**
Returns the `NSFetchedResultsSectionInfo`s for all sections
- returns: the `NSFetchedResultsSectionInfo`s for all sections
*/
@objc
public func sections() -> [NSFetchedResultsSectionInfo] {
return self.bridgeToSwift.sections()
fatalError()
}
/**
Returns the target section for a specified "Section Index" title and index.
- parameter title: the title of the Section Index
- parameter index: the index of the Section Index
- returns: the target section for the specified "Section Index" title and index.
*/
@objc
public func targetSectionForSectionIndexTitle(title: String, index: Int) -> Int {
return self.bridgeToSwift.targetSection(forSectionIndexTitle: title, at: index)
fatalError()
}
/**
Returns the section index titles for all sections
- returns: the section index titles for all sections
*/
@objc
public func sectionIndexTitles() -> [String] {
return self.bridgeToSwift.sectionIndexTitles()
fatalError()
}
/**
Returns the index of the `NSManagedObject` if it exists in the `CSListMonitor`'s fetched objects, or `nil` if not found.
- parameter object: the `NSManagedObject` to search the index of
- returns: the index of the `NSManagedObject` if it exists in the `CSListMonitor`'s fetched objects, or `nil` if not found.
*/
@objc
public func indexOf(_ object: NSManagedObject) -> NSNumber? {
return self.bridgeToSwift
.index(of: object)
.flatMap { NSNumber(value: $0) }
fatalError()
}
/**
Returns the `NSIndexPath` of the `NSManagedObject` if it exists in the `CSListMonitor`'s fetched objects, or `nil` if not found.
- 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.
*/
@objc
public func indexPathOf(_ object: NSManagedObject) -> IndexPath? {
return self.bridgeToSwift.indexPath(of: object)
fatalError()
}
// MARK: Public (Observers)
/**
Registers a `CSListObserver` to be notified when changes to the receiver's list occur.
To prevent retain-cycles, `CSListMonitor` only keeps `weak` references to its observers.
For thread safety, this method needs to be called from the main thread. An assertion failure will occur (on debug builds only) if called from any thread other than the main thread.
Calling `-addListObserver:` multiple times on the same observer is safe, as `CSListMonitor` unregisters previous notifications to the observer before re-registering them.
- parameter observer: a `CSListObserver` to send change notifications to
*/
@objc
public func addListObserver(_ observer: CSListObserver) {
let swift = self.bridgeToSwift
swift.unregisterObserver(observer)
swift.registerObserver(
observer,
willChange: { (observer, monitor) in
observer.listMonitorWillChange?(monitor.bridgeToObjectiveC)
},
didChange: { (observer, monitor) in
observer.listMonitorDidChange?(monitor.bridgeToObjectiveC)
},
willRefetch: { (observer, monitor) in
observer.listMonitorWillRefetch?(monitor.bridgeToObjectiveC)
},
didRefetch: { (observer, monitor) in
observer.listMonitorDidRefetch?(monitor.bridgeToObjectiveC)
}
)
fatalError()
}
/**
Registers a `CSListObjectObserver` to be notified when changes to the receiver's list occur.
To prevent retain-cycles, `CSListMonitor` only keeps `weak` references to its observers.
For thread safety, this method needs to be called from the main thread. An assertion failure will occur (on debug builds only) if called from any thread other than the main thread.
Calling `-addListObjectObserver:` multiple times on the same observer is safe, as `ListMonitor` unregisters previous notifications to the observer before re-registering them.
- parameter observer: a `CSListObjectObserver` to send change notifications to
*/
public func addListObjectObserver(_ observer: CSListObjectObserver) {
let swift = self.bridgeToSwift
swift.unregisterObserver(observer)
swift.registerObserver(
observer,
willChange: { (observer, monitor) in
observer.listMonitorWillChange?(monitor.bridgeToObjectiveC)
},
didChange: { (observer, monitor) in
observer.listMonitorDidChange?(monitor.bridgeToObjectiveC)
},
willRefetch: { (observer, monitor) in
observer.listMonitorWillRefetch?(monitor.bridgeToObjectiveC)
},
didRefetch: { (observer, monitor) in
observer.listMonitorDidRefetch?(monitor.bridgeToObjectiveC)
}
)
swift.registerObserver(
observer,
didInsertObject: { (observer, monitor, object, toIndexPath) in
observer.listMonitor?(monitor.bridgeToObjectiveC, didInsertObject: object, toIndexPath: toIndexPath)
},
didDeleteObject: { (observer, monitor, object, fromIndexPath) in
observer.listMonitor?(monitor.bridgeToObjectiveC, didDeleteObject: object, fromIndexPath: fromIndexPath)
},
didUpdateObject: { (observer, monitor, object, atIndexPath) in
observer.listMonitor?(monitor.bridgeToObjectiveC, didUpdateObject: object, atIndexPath: atIndexPath)
},
didMoveObject: { (observer, monitor, object, fromIndexPath, toIndexPath) in
observer.listMonitor?(monitor.bridgeToObjectiveC, didMoveObject: object, fromIndexPath: fromIndexPath, toIndexPath: toIndexPath)
}
)
fatalError()
}
/**
Registers a `CSListSectionObserver` to be notified when changes to the receiver's list occur.
To prevent retain-cycles, `CSListMonitor` only keeps `weak` references to its observers.
For thread safety, this method needs to be called from the main thread. An assertion failure will occur (on debug builds only) if called from any thread other than the main thread.
Calling `-addListSectionObserver:` multiple times on the same observer is safe, as `ListMonitor` unregisters previous notifications to the observer before re-registering them.
- parameter observer: a `CSListSectionObserver` to send change notifications to
*/
@objc
public func addListSectionObserver(_ observer: CSListSectionObserver) {
let swift = self.bridgeToSwift
swift.unregisterObserver(observer)
swift.registerObserver(
observer,
willChange: { (observer, monitor) in
observer.listMonitorWillChange?(monitor.bridgeToObjectiveC)
},
didChange: { (observer, monitor) in
observer.listMonitorDidChange?(monitor.bridgeToObjectiveC)
},
willRefetch: { (observer, monitor) in
observer.listMonitorWillRefetch?(monitor.bridgeToObjectiveC)
},
didRefetch: { (observer, monitor) in
observer.listMonitorDidRefetch?(monitor.bridgeToObjectiveC)
}
)
swift.registerObserver(
observer,
didInsertObject: { (observer, monitor, object, toIndexPath) in
observer.listMonitor?(monitor.bridgeToObjectiveC, didInsertObject: object, toIndexPath: toIndexPath)
},
didDeleteObject: { (observer, monitor, object, fromIndexPath) in
observer.listMonitor?(monitor.bridgeToObjectiveC, didDeleteObject: object, fromIndexPath: fromIndexPath)
},
didUpdateObject: { (observer, monitor, object, atIndexPath) in
observer.listMonitor?(monitor.bridgeToObjectiveC, didUpdateObject: object, atIndexPath: atIndexPath)
},
didMoveObject: { (observer, monitor, object, fromIndexPath, toIndexPath) in
observer.listMonitor?(monitor.bridgeToObjectiveC, didMoveObject: object, fromIndexPath: fromIndexPath, toIndexPath: toIndexPath)
}
)
swift.registerObserver(
observer,
didInsertSection: { (observer, monitor, sectionInfo, toIndex) in
observer.listMonitor?(monitor.bridgeToObjectiveC, didInsertSection: sectionInfo, toSectionIndex: toIndex)
},
didDeleteSection: { (observer, monitor, sectionInfo, fromIndex) in
observer.listMonitor?(monitor.bridgeToObjectiveC, didDeleteSection: sectionInfo, fromSectionIndex: fromIndex)
}
)
fatalError()
}
/**
Unregisters a `CSListObserver` from receiving notifications for changes to the receiver's list.
For thread safety, this method needs to be called from the main thread. An assertion failure will occur (on debug builds only) if called from any thread other than the main thread.
- parameter observer: a `CSListObserver` to unregister notifications to
*/
@objc
public func removeListObserver(_ observer: CSListObserver) {
self.bridgeToSwift.unregisterObserver(observer)
fatalError()
}
// MARK: Public (Refetching)
/**
Returns `YES` if a call to `-refetch:` was made to the `CSListMonitor` and is currently waiting for the fetching to complete. Returns `NO` otherwise.
*/
@objc
public var isPendingRefetch: Bool {
return self.bridgeToSwift.isPendingRefetch
fatalError()
}
/**
Asks the `CSListMonitor` to refetch its objects using the specified series of `CSFetchClause`s. Note that this method does not execute the fetch immediately; the actual fetching will happen after the `NSFetchedResultsController`'s last `controllerDidChangeContent(_:)` notification completes.
`refetch(...)` broadcasts `listMonitorWillRefetch(...)` to its observers immediately, and then `listMonitorDidRefetch(...)` after the new fetch request completes.
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- Important: Starting CoreStore 4.0, all `CSFetchClause`s required by the `CSListMonitor` should be provided in the arguments list of `refetch(...)`.
*/
@objc
public func refetch(_ fetchClauses: [CSFetchClause]) {
self.bridgeToSwift.refetch { (fetchRequest) in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
}
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return self.bridgeToSwift.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSListMonitor else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -536,33 +234,21 @@ public final class CSListMonitor: NSObject {
@nonobjc
public required init<T: NSManagedObject>(_ swiftValue: ListMonitor<T>) {
self.bridgeToSwift = swiftValue.downcast()
super.init()
fatalError()
}
}
// MARK: - ListMonitor
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension ListMonitor where ListMonitor.ObjectType: NSManagedObject {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSListMonitor {
return CSListMonitor(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> ListMonitor<NSManagedObject> {
func noWarnUnsafeBitCast<T, U>(_ x: T, to type: U.Type) -> U {
return unsafeBitCast(x, to: type)
}
return noWarnUnsafeBitCast(self, to: ListMonitor<NSManagedObject>.self)
fatalError()
}
}

View File

@@ -29,49 +29,19 @@ import CoreData
// MARK: - CSListObserver
/**
Implement the `CSListObserver` protocol to observe changes to a list of `NSManagedObject`s. `CSListObserver`s may register themselves to a `CSListMonitor`'s `-addListObserver:` method:
```
CSListMonitor *monitor = [CSCoreStore
monitorListFrom:[CSFrom entityClass:[MyPersonEntity class]]
fetchClauses:@[[CSOrderBy sortDescriptor:[CSSortKey withKeyPath:@"lastName" ascending:YES]]]];
[monitor addListObserver:self];
```
- SeeAlso: `ListObserver`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public protocol CSListObserver: AnyObject {
/**
Handles processing just before a change to the observed list occurs
- parameter monitor: the `CSListMonitor` monitoring the list being observed
*/
@objc
optional func listMonitorWillChange(_ monitor: CSListMonitor)
/**
Handles processing right after a change to the observed list occurs
- parameter monitor: the `CSListMonitor` monitoring the object being observed
*/
@objc
optional func listMonitorDidChange(_ monitor: CSListMonitor)
/**
This method is broadcast from within the `CSListMonitor`'s `-refetchWithFetchClauses:` method to let observers prepare for the internal `NSFetchedResultsController`'s pending change to its predicate, sort descriptors, etc. Note that the actual refetch will happen after the `NSFetchedResultsController`'s last `-controllerDidChangeContent:` notification completes.
- parameter monitor: the `CSListMonitor` monitoring the object being observed
*/
@objc
optional func listMonitorWillRefetch(_ monitor: CSListMonitor)
/**
After the `CSListMonitor`'s `-refetchWithFetchClauses:` method is called, this method is broadcast after the `NSFetchedResultsController`'s last `-controllerDidChangeContent:` notification completes.
- parameter monitor: the `CSListMonitor` monitoring the object being observed
*/
@objc
optional func listMonitorDidRefetch(_ monitor: CSListMonitor)
}
@@ -79,58 +49,19 @@ public protocol CSListObserver: AnyObject {
// MARK: - ListObjectObserver
/**
Implement the `CSListObjectObserver` protocol to observe detailed changes to a list's object. `CSListObjectObserver`s may register themselves to a `CSListMonitor`'s `-addListObjectObserver(_:)` method:
```
CSListMonitor *monitor = [CSCoreStore
monitorListFrom:[CSFrom entityClass:[MyPersonEntity class]]
fetchClauses:@[[CSOrderBy sortDescriptor:[CSSortKey withKeyPath:@"lastName" ascending:YES]]]];
[monitor addListObjectObserver:self];
```
- SeeAlso: `ListObjectObserver`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public protocol CSListObjectObserver: CSListObserver {
/**
Notifies that an object was inserted to the specified `NSIndexPath` in the list
- parameter monitor: the `CSListMonitor` monitoring the list being observed
- parameter object: the entity type for the inserted object
- parameter indexPath: the new `NSIndexPath` for the inserted object
*/
@objc
optional func listMonitor(_ monitor: CSListMonitor, didInsertObject object: Any, toIndexPath indexPath: IndexPath)
/**
Notifies that an object was deleted from the specified `NSIndexPath` in the list
- parameter monitor: the `CSListMonitor` monitoring the list being observed
- parameter object: the entity type for the deleted object
- parameter indexPath: the `NSIndexPath` for the deleted object
*/
@objc
optional func listMonitor(_ monitor: CSListMonitor, didDeleteObject object: Any, fromIndexPath indexPath: IndexPath)
/**
Notifies that an object at the specified `NSIndexPath` was updated
- parameter monitor: the `CSListMonitor` monitoring the list being observed
- parameter object: the entity type for the updated object
- parameter indexPath: the `NSIndexPath` for the updated object
*/
@objc
optional func listMonitor(_ monitor: CSListMonitor, didUpdateObject object: Any, atIndexPath indexPath: IndexPath)
/**
Notifies that an object's index changed
- parameter monitor: the `CSListMonitor` monitoring the list being observed
- parameter object: the entity type for the moved object
- parameter fromIndexPath: the previous `NSIndexPath` for the moved object
- parameter toIndexPath: the new `NSIndexPath` for the moved object
*/
@objc
optional func listMonitor(_ monitor: CSListMonitor, didMoveObject object: Any, fromIndexPath: IndexPath, toIndexPath: IndexPath)
}
@@ -138,38 +69,13 @@ public protocol CSListObjectObserver: CSListObserver {
// MARK: - CSListSectionObserver
/**
Implement the `CSListSectionObserver` protocol to observe changes to a list's section info. `CSListSectionObserver`s may register themselves to a `CSListMonitor`'s `-addListSectionObserver:` method:
```
CSListMonitor *monitor = [CSCoreStore
monitorSectionedListFrom:[CSFrom entityClass:[MyPersonEntity class]]
sectionBy:[CSSectionBy keyPath:@"age"]
fetchClauses:@[[CSOrderBy sortDescriptor:[CSSortKey withKeyPath:@"lastName" ascending:YES]]]];
[monitor addListSectionObserver:self];
```
- SeeAlso: `ListSectionObserver`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public protocol CSListSectionObserver: CSListObjectObserver {
/**
Notifies that a section was inserted at the specified index
- parameter monitor: the `CSListMonitor` monitoring the list being observed
- parameter sectionInfo: the `NSFetchedResultsSectionInfo` for the inserted section
- parameter sectionIndex: the new section index for the new section
*/
@objc
optional func listMonitor(_ monitor: CSListMonitor, didInsertSection sectionInfo: NSFetchedResultsSectionInfo, toSectionIndex sectionIndex: Int)
/**
Notifies that a section was inserted at the specified index
- parameter monitor: the `CSListMonitor` monitoring the list being observed
- parameter sectionInfo: the `NSFetchedResultsSectionInfo` for the deleted section
- parameter sectionIndex: the previous section index for the deleted section
*/
@objc
optional func listMonitor(_ monitor: CSListMonitor, didDeleteSection sectionInfo: NSFetchedResultsSectionInfo, fromSectionIndex sectionIndex: Int)
}

View File

@@ -29,134 +29,68 @@ import CoreData
// MARK: - CSMigrationResult
/**
The `CSMigrationResult` serves as the Objective-C bridging type for `MigrationResult`.
- SeeAlso: `MigrationResult`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSMigrationResult: NSObject, CoreStoreObjectiveCType {
/**
`YES` if the migration succeeded, `NO` otherwise
*/
@objc
public var isSuccess: Bool {
return (try? self.bridgeToSwift.get()) != nil
fatalError()
}
/**
`YES` if the migration failed, `NO` otherwise
*/
@objc
public var isFailure: Bool {
return !self.isSuccess
}
/**
`YES` if the migration succeeded, `NO` otherwise
*/
@objc
public var migrationTypes: [CSMigrationType]? {
guard case .success(let migrationTypes) = self.bridgeToSwift else {
return nil
}
return migrationTypes.map { $0.bridgeToObjectiveC }
fatalError()
}
/**
The `NSError` for a failed migration, or `nil` if the migration succeeded
*/
@objc
public var error: NSError? {
guard case .failure(let error) = self.bridgeToSwift else {
return nil
}
return error.bridgeToObjectiveC
fatalError()
}
/**
If the result was a success, the `success` block is executed with an array of `CSMigrationType`s that indicates the migration steps completed. If the result was a failure, the `failure` block is executed with an `NSError` argument pertaining to the actual error.
The blocks are executed immediately as `@noescape` and will not be retained.
- parameter success: the block to execute on success. The block passes an array of `CSMigrationType`s that indicates the migration steps completed.
- parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error.
*/
@objc
public func handleSuccess(_ success: (_ migrationTypes: [CSMigrationType]) -> Void, failure: (_ error: NSError) -> Void) {
switch self.bridgeToSwift {
case .success(let migrationTypes):
success(migrationTypes.map { $0.bridgeToObjectiveC })
case .failure(let error):
failure(error.bridgeToObjectiveC)
}
fatalError()
}
/**
If the result was a success, the `success` block is executed with an array of `CSMigrationType`s that indicates the migration steps completed. If the result was a failure, this method does nothing.
The block is executed immediately as `@noescape` and will not be retained.
- parameter success: the block to execute on success. The block passes an array of `CSMigrationType`s that indicates the migration steps completed.
*/
@objc
public func handleSuccess(_ success: (_ migrationTypes: [CSMigrationType]) -> Void) {
guard case .success(let migrationTypes) = self.bridgeToSwift else {
return
}
success(migrationTypes.map { $0.bridgeToObjectiveC })
fatalError()
}
/**
If the result was a failure, the `failure` block is executed with an `NSError` argument pertaining to the actual error. If the result was a success, this method does nothing.
The block is executed immediately as `@noescape` and will not be retained.
- parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error.
*/
@objc
public func handleFailure(_ failure: (_ error: NSError) -> Void) {
guard case .failure(let error) = self.bridgeToSwift else {
return
}
failure(error.bridgeToObjectiveC)
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return self.bridgeToSwift.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSMigrationResult else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -165,22 +99,21 @@ public final class CSMigrationResult: NSObject, CoreStoreObjectiveCType {
public let bridgeToSwift: MigrationResult
public required init(_ swiftValue: MigrationResult) {
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
}
// MARK: - MigrationResult
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension MigrationResult {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSMigrationResult {
return CSMigrationResult(self)
fatalError()
}
}

View File

@@ -29,80 +29,56 @@ import CoreData
// MARK: - CSMigrationType
/**
The `CSMigrationType` serves as the Objective-C bridging type for `MigrationType`.
- SeeAlso: `MigrationType`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSMigrationType: NSObject, CoreStoreObjectiveCType {
/**
Returns `YES` if the `CSMigrationType`'s `sourceVersion` and `destinationVersion` do not match. Returns `NO` otherwise.
*/
@objc
public var needsMigration: Bool {
return self.bridgeToSwift.hasMigration
fatalError()
}
/**
Returns the source model version for the migration type. If no migration is required, `sourceVersion` will be equal to the `destinationVersion`.
*/
@objc
public var sourceVersion: String {
return self.bridgeToSwift.sourceVersion
fatalError()
}
/**
Returns the destination model version for the migration type. If no migration is required, `destinationVersion` will be equal to the `sourceVersion`.
*/
@objc
public var destinationVersion: String {
return self.bridgeToSwift.destinationVersion
fatalError()
}
/**
Returns `YES` if the `CSMigrationType` is a lightweight migration. Used as syntactic sugar.
*/
@objc
public var isLightweightMigration: Bool {
return self.bridgeToSwift.isLightweightMigration
fatalError()
}
/**
Returns `YES` if the `CSMigrationType` is a heavyweight migration. Used as syntactic sugar.
*/
@objc
public var isHeavyweightMigration: Bool {
return self.bridgeToSwift.isHeavyweightMigration
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return self.bridgeToSwift.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSMigrationType else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -111,22 +87,21 @@ public final class CSMigrationType: NSObject, CoreStoreObjectiveCType {
public let bridgeToSwift: MigrationType
public required init(_ swiftValue: MigrationType) {
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
}
// MARK: - MigrationType
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension MigrationType: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSMigrationType {
return CSMigrationType(self)
fatalError()
}
}

View File

@@ -29,72 +29,28 @@ import CoreData
// MARK: - CSObjectMonitor
/**
The `CSObjectMonitor` serves as the Objective-C bridging type for `ObjectMonitor<T>`.
- SeeAlso: `ObjectMonitor`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSObjectMonitor: NSObject {
/**
Returns the `NSManagedObject` instance being observed, or `nil` if the object was already deleted.
*/
public var object: Any? {
return self.bridgeToSwift.object
fatalError()
}
/**
Returns `YES` if the `NSManagedObject` instance being observed still exists, or `NO` if the object was already deleted.
*/
public var isObjectDeleted: Bool {
return self.bridgeToSwift.isObjectDeleted
fatalError()
}
/**
Registers a `CSObjectObserver` to be notified when changes to the receiver's `object` are made.
To prevent retain-cycles, `CSObjectMonitor` only keeps `weak` references to its observers.
For thread safety, this method needs to be called from the main thread. An assertion failure will occur (on debug builds only) if called from any thread other than the main thread.
Calling `-addObjectObserver:` multiple times on the same observer is safe, as `CSObjectMonitor` unregisters previous notifications to the observer before re-registering them.
- parameter observer: an `CSObjectObserver` to send change notifications to
*/
public func addObjectObserver(_ observer: CSObjectObserver) {
let swift = self.bridgeToSwift
swift.unregisterObserver(observer)
swift.registerObserver(
observer,
willChangeObject: { (observer, monitor, object) in
observer.objectMonitor?(monitor.bridgeToObjectiveC, willUpdateObject: object)
},
didDeleteObject: { (observer, monitor, object) in
observer.objectMonitor?(monitor.bridgeToObjectiveC, didDeleteObject: object)
},
didUpdateObject: { (observer, monitor, object, changedPersistentKeys) in
observer.objectMonitor?(monitor.bridgeToObjectiveC, didUpdateObject: object, changedPersistentKeys: changedPersistentKeys)
}
)
fatalError()
}
/**
Unregisters an `CSObjectObserver` from receiving notifications for changes to the receiver's `object`.
For thread safety, this method needs to be called from the main thread. An assertion failure will occur (on debug builds only) if called from any thread other than the main thread.
- parameter observer: an `CSObjectObserver` to unregister notifications to
*/
public func removeObjectObserver(_ observer: CSObjectObserver) {
self.bridgeToSwift.unregisterObserver(observer)
fatalError()
}
@@ -102,23 +58,17 @@ public final class CSObjectMonitor: NSObject {
public override var hash: Int {
var hasher = Hasher()
self.bridgeToSwift.hash(into: &hasher)
return hasher.finalize()
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSObjectMonitor else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -129,33 +79,21 @@ public final class CSObjectMonitor: NSObject {
@nonobjc
public required init<T: NSManagedObject>(_ swiftValue: ObjectMonitor<T>) {
self.bridgeToSwift = swiftValue.downcast()
super.init()
fatalError()
}
}
// MARK: - ObjectMonitor
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension ObjectMonitor where ObjectMonitor.ObjectType: NSManagedObject {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSObjectMonitor {
return CSObjectMonitor(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> ObjectMonitor<NSManagedObject> {
func noWarnUnsafeBitCast<T, U>(_ x: T, to type: U.Type) -> U {
return unsafeBitCast(x, to: type)
}
return noWarnUnsafeBitCast(self, to: ObjectMonitor<NSManagedObject>.self)
fatalError()
}
}

View File

@@ -29,43 +29,16 @@ import CoreData
// MARK: - CSObjectObserver
/**
Implement the `CSObjectObserver` protocol to observe changes to a single `NSManagedObject` instance. `CSObjectObserver`s may register themselves to a `CSObjectMonitor`'s `-addObjectObserver:` method:
```
CSObjectMonitor *monitor = [CSCoreStore monitorObject:myObject];
[monitor addObjectObserver:self];
```
- SeeAlso: `ObjectObserver`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public protocol CSObjectObserver: AnyObject {
/**
Handles processing just before a change to the observed `object` occurs
- parameter monitor: the `CSObjectMonitor` monitoring the object being observed
- parameter object: the `NSManagedObject` instance being observed
*/
@objc
optional func objectMonitor(_ monitor: CSObjectMonitor, willUpdateObject object: Any)
/**
Handles processing right after a change to the observed `object` occurs
- parameter monitor: the `CSObjectMonitor` monitoring the object being observed
- parameter object: the `NSManagedObject` instance being observed
- parameter changedPersistentKeys: an `NSSet` of key paths for the attributes that were changed. Note that `changedPersistentKeys` only contains keys for attributes/relationships present in the persistent store, thus transient properties will not be reported.
*/
@objc
optional func objectMonitor(_ monitor: CSObjectMonitor, didUpdateObject object: Any, changedPersistentKeys: Set<String>)
/**
Handles processing right after `object` is deleted
- parameter monitor: the `CSObjectMonitor` monitoring the object being observed
- parameter object: the `NSManagedObject` instance being observed
*/
@objc
optional func objectMonitor(_ monitor: CSObjectMonitor, didDeleteObject object: Any)
}

View File

@@ -29,73 +29,44 @@ import CoreData
// MARK: - CSOrderBy
/**
The `CSOrderBy` serves as the Objective-C bridging type for `OrderBy`.
- SeeAlso: `OrderBy`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause {
/**
The list of sort descriptors
*/
@objc
public var sortDescriptors: [NSSortDescriptor] {
return self.bridgeToSwift.sortDescriptors
fatalError()
}
/**
Initializes a `CSOrderBy` clause with a single sort descriptor
```
MyPersonEntity *people = [transaction
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSOrderByKey(CSSortAscending(@"fullname"))]]];
```
- parameter sortDescriptor: a `NSSortDescriptor`
*/
@objc
public convenience init(sortDescriptor: NSSortDescriptor) {
self.init(OrderBy(sortDescriptor))
fatalError()
}
/**
Initializes a `CSOrderBy` clause with a list of sort descriptors
```
MyPersonEntity *people = [transaction
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSOrderByKeys(CSSortAscending(@"fullname"), CSSortDescending(@"age"), nil))]]];
```
- parameter sortDescriptors: an array of `NSSortDescriptor`s
*/
@objc
public convenience init(sortDescriptors: [NSSortDescriptor]) {
self.init(OrderBy(sortDescriptors))
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return self.bridgeToSwift.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSOrderBy else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -103,8 +74,8 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl
@objc
public func applyToFetchRequest(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) {
self.bridgeToSwift.applyToFetchRequest(fetchRequest)
fatalError()
}
@@ -113,29 +84,21 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl
public let bridgeToSwift: OrderBy<NSManagedObject>
public init<O: NSManagedObject>(_ swiftValue: OrderBy<O>) {
self.bridgeToSwift = swiftValue.downcast()
super.init()
fatalError()
}
}
// MARK: - OrderBy
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension OrderBy where O: NSManagedObject {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSOrderBy {
return CSOrderBy(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> OrderBy<NSManagedObject> {
return OrderBy<NSManagedObject>(self.sortDescriptors)
fatalError()
}
}

View File

@@ -29,157 +29,88 @@ import CoreData
// MARK: - CSSQLiteStore
/**
The `CSSQLiteStore` serves as the Objective-C bridging type for `SQLiteStore`.
- SeeAlso: `SQLiteStore`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCType {
/**
Initializes an SQLite store interface from the given SQLite file URL. When this instance is passed to the `CSDataStack`'s `-addStorage*:` methods, a new SQLite file will be created if it does not exist.
- Important: Initializing `CSSQLiteStore`s with custom migration mapping models is currently not supported. Create an `SQLiteStore` instance from Swift code and bridge the instance to Objective-C using its `SQLiteStore.bridgeToObjectiveC` property.
- parameter fileURL: the local file URL for the target SQLite persistent store. Note that if you have multiple configurations, you will need to specify a different `fileURL` explicitly for each of them.
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`, the "Default" configuration. Note that if you have multiple configurations, you will need to specify a different `fileURL` explicitly for each of them.
- parameter localStorageOptions: When the `CSSQLiteStore` is passed to the `CSDataStack`'s `addStorage()` methods, tells the `CSDataStack` how to setup the persistent store. Defaults to `CSLocalStorageOptionsNone`.
*/
@objc
public convenience init(fileURL: URL, configuration: ModelConfiguration, localStorageOptions: Int) {
self.init(
SQLiteStore(
fileURL: fileURL,
configuration: configuration,
localStorageOptions: LocalStorageOptions(rawValue: localStorageOptions)
)
)
fatalError()
}
/**
Initializes an SQLite store interface from the given SQLite file name. When this instance is passed to the `CSDataStack`'s `-addStorage*:` methods, a new SQLite file will be created if it does not exist.
- Important: Initializing `CSSQLiteStore`s with custom migration mapping models is currently not supported. Create an `SQLiteStore` instance from Swift code and bridge the instance to Objective-C using its `SQLiteStore.bridgeToObjectiveC` property.
- parameter fileName: the local filename for the SQLite persistent store in the "Application Support/<bundle id>" directory (or the "Caches/<bundle id>" directory on tvOS). Note that if you have multiple configurations, you will need to specify a different `fileName` explicitly for each of them.
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`, the "Default" configuration. Note that if you have multiple configurations, you will need to specify a different `fileName` explicitly for each of them.
- parameter localStorageOptions: When the `CSSQLiteStore` is passed to the `CSDataStack`'s `addStorage()` methods, tells the `CSDataStack` how to setup the persistent store. Defaults to `[CSLocalStorageOptions none]`.
*/
@objc
public convenience init(fileName: String, configuration: ModelConfiguration, localStorageOptions: Int) {
self.init(
SQLiteStore(
fileName: fileName,
configuration: configuration,
localStorageOptions: LocalStorageOptions(rawValue: localStorageOptions)
)
)
fatalError()
}
/**
Initializes an `CSSQLiteStore` with an all-default settings: a `fileURL` pointing to a "<Application name>.sqlite" file in the "Application Support/<bundle id>" directory (or the "Caches/<bundle id>" directory on tvOS), a `nil` `configuration` pertaining to the "Default" configuration, and `localStorageOptions` set to `[CSLocalStorageOptions none]`.
- Important: Initializing `CSSQLiteStore`s with custom migration mapping models is currently not supported. Create an `SQLiteStore` instance from Swift code and bridge the instance to Objective-C using its `SQLiteStore.bridgeToObjectiveC` property.
*/
@objc
public convenience override init() {
self.init(SQLiteStore())
fatalError()
}
// MAKR: CSLocalStorage
/**
The `NSURL` that points to the SQLite file
*/
@objc
public var fileURL: URL {
return self.bridgeToSwift.fileURL as URL
fatalError()
}
/**
An array of `SchemaMappingProvider`s that provides the complete mapping models for custom migrations. This is currently only supported for Swift code.
*/
@objc
public var migrationMappingProviders: [Any] {
return self.bridgeToSwift.migrationMappingProviders
fatalError()
}
/**
Options that tell the `CSDataStack` how to setup the persistent store
*/
@objc
public var localStorageOptions: Int {
return self.bridgeToSwift.localStorageOptions.rawValue
fatalError()
}
// MARK: CSStorageInterface
/**
The string identifier for the `NSPersistentStore`'s `type` property. For `CSSQLiteStore`s, this is always set to `NSSQLiteStoreType`.
*/
@objc
public static let storeType = NSSQLiteStoreType
/**
The configuration name in the model file
*/
public var configuration: ModelConfiguration {
return self.bridgeToSwift.configuration
fatalError()
}
/**
The options dictionary for the `NSPersistentStore`. For `CSSQLiteStore`s, this is always set to
```
[NSSQLitePragmasOption: ["journal_mode": "WAL"]]
```
*/
@objc
public var storeOptions: [AnyHashable: Any]? {
return self.bridgeToSwift.storeOptions
fatalError()
}
/**
Called by the `CSDataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. For `CSSQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
*/
@objc
public func cs_eraseStorageAndWait(metadata: NSDictionary, soureModelHint: NSManagedObjectModel?, error: NSErrorPointer) -> Bool {
return bridge(error) {
try self.bridgeToSwift.cs_eraseStorageAndWait(metadata: metadata as! [String: Any], soureModelHint: soureModelHint)
}
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return ObjectIdentifier(self.bridgeToSwift).hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSSQLiteStore else {
return false
}
return self.bridgeToSwift === object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -188,22 +119,21 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCT
public let bridgeToSwift: SQLiteStore
public required init(_ swiftValue: SQLiteStore) {
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
}
// MARK: - SQLiteStore
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension SQLiteStore: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSSQLiteStore {
return CSSQLiteStore(self)
fatalError()
}
}

View File

@@ -29,50 +29,28 @@ import CoreData
// MARK: - CSSectionBy
/**
The `CSSectionBy` serves as the Objective-C bridging type for `SectionBy`.
- SeeAlso: `SectionBy`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSSectionBy: NSObject {
/**
Initializes a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections
- parameter sectionKeyPath: the key path to use to group the objects into sections
- returns: a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections
*/
@objc
public static func keyPath(_ sectionKeyPath: KeyPathString) -> CSSectionBy {
return self.init(SectionBy<NSManagedObject>(sectionKeyPath))
fatalError()
}
/**
Initializes a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections, and a closure to transform the value for the key path to an appropriate section index title
- parameter sectionKeyPath: the key path to use to group the objects into sections
- parameter sectionIndexTransformer: a closure to transform the value for the key path to an appropriate section index title
- returns: a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections
*/
@objc
public static func keyPath(_ sectionKeyPath: KeyPathString, sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> CSSectionBy {
return self.init(
SectionBy<NSManagedObject>(
sectionKeyPath,
sectionIndexTransformer: sectionIndexTransformer
)
)
fatalError()
}
// MARK: NSObject
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -81,32 +59,21 @@ public final class CSSectionBy: NSObject {
public let bridgeToSwift: SectionBy<NSManagedObject>
public init<O>(_ swiftValue: SectionBy<O>) {
self.bridgeToSwift = swiftValue.downcast()
super.init()
fatalError()
}
}
// MARK: - SectionBy
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension SectionBy {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSSectionBy {
return CSSectionBy(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> SectionBy<NSManagedObject> {
return SectionBy<NSManagedObject>(
self.sectionKeyPath,
sectionIndexTransformer: self.sectionIndexTransformer
)
fatalError()
}
}

View File

@@ -29,147 +29,63 @@ import CoreData
// MARK: - CSSelectTerm
/**
The `CSSelectTerm` serves as the Objective-C bridging type for `SelectTerm`.
- SeeAlso: `SelectTerm`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSSelectTerm: NSObject {
/**
Provides a `CSSelectTerm` to a `CSSelect` clause for querying an entity attribute.
```
NSString *fullName = [CSCoreStore
queryValueFrom:[CSFrom entityClass:[MyPersonEntity class]]
select:CSSelectString(CSAttribute(@"fullname"))
fetchClauses:@[[CSWhere keyPath:@"employeeID" isEqualTo: @1111]]];
```
- parameter keyPath: the attribute name
*/
@objc
public convenience init(keyPath: KeyPathString) {
self.init(.attribute(keyPath))
fatalError()
}
/**
Provides a `CSSelectTerm` to a `CSSelect` clause for querying the average value of an attribute.
```
NSNumber *averageAge = [CSCoreStore
queryValueFrom:[CSFrom entityClass:[MyPersonEntity class]]
select:[CSSelect numberForTerm:[CSSelectTerm average:@"age" as:nil]]];
```
- parameter keyPath: the attribute name
- parameter `as`: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the average value of an attribute
*/
@objc
public static func average(_ keyPath: KeyPathString, as alias: KeyPathString?) -> CSSelectTerm {
return self.init(.average(keyPath, as: alias))
fatalError()
}
/**
Provides a `CSSelectTerm` to a `CSSelect` clause for a count query.
```
NSNumber *numberOfEmployees = [CSCoreStore
queryValueFrom:[CSFrom entityClass:[MyPersonEntity class]]
select:[CSSelect numberForTerm:[CSSelectTerm count:@"employeeID" as:nil]]];
```
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for a count query
*/
@objc
public static func count(_ keyPath: KeyPathString, as alias: KeyPathString?) -> CSSelectTerm {
return self.init(.count(keyPath, as: alias))
fatalError()
}
/**
Provides a `CSSelectTerm` to a `CSSelect` clause for querying the maximum value for an attribute.
```
NSNumber *maximumAge = [CSCoreStore
queryValueFrom:[CSFrom entityClass:[MyPersonEntity class]]
select:[CSSelect numberForTerm:[CSSelectTerm maximum:@"age" as:nil]]];
```
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the maximum value for an attribute
*/
@objc
public static func maximum(_ keyPath: KeyPathString, as alias: KeyPathString?) -> CSSelectTerm {
return self.init(.maximum(keyPath, as: alias))
fatalError()
}
/**
Provides a `CSSelectTerm` to a `CSSelect` clause for querying the minimum value for an attribute.
```
NSNumber *minimumAge = [CSCoreStore
queryValueFrom:[CSFrom entityClass:[MyPersonEntity class]]
select:[CSSelect numberForTerm:[CSSelectTerm minimum:@"age" as:nil]]];
```
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the minimum value for an attribute
*/
@objc
public static func minimum(_ keyPath: KeyPathString, as alias: KeyPathString?) -> CSSelectTerm {
return self.init(.minimum(keyPath, as: alias))
fatalError()
}
/**
Provides a `CSSelectTerm` to a `CSSelect` clause for querying the sum value for an attribute.
```
NSNumber *totalAge = [CSCoreStore
queryValueFrom:[CSFrom entityClass:[MyPersonEntity class]]
select:[CSSelect numberForTerm:[CSSelectTerm sum:@"age" as:nil]]];
```
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
- returns: a `CSSelectTerm` to a `CSSelect` clause for querying the sum value for an attribute
*/
@objc
public static func sum(_ keyPath: KeyPathString, as alias: KeyPathString?) -> CSSelectTerm {
return self.init(.sum(keyPath, as: alias))
fatalError()
}
/**
Provides a `CSSelectTerm` to a `CSSelect` clause for querying the `NSManagedObjectID`.
```
NSManagedObjectID *objectID = [CSCoreStore
queryValueFrom:[CSFrom entityClass:[MyPersonEntity class]]
select:[CSSelect objectIDForTerm:[CSSelectTerm objectIDAs:nil]]
fetchClauses:@[[CSWhere keyPath:@"employeeID" isEqualTo: @1111]]];
```
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "objecID" is used
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/
@objc
public static func objectIDAs(_ alias: KeyPathString? = nil) -> CSSelectTerm {
return self.init(.objectID(as: alias))
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return self.bridgeToSwift.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSSelectTerm else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
@@ -178,344 +94,122 @@ public final class CSSelectTerm: NSObject {
public let bridgeToSwift: SelectTerm<NSManagedObject>
public init<O: NSManagedObject>(_ swiftValue: SelectTerm<O>) {
self.bridgeToSwift = swiftValue.downcast()
super.init()
fatalError()
}
}
// MARK: - SelectTerm
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension SelectTerm where O: NSManagedObject {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSSelectTerm {
return CSSelectTerm(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> SelectTerm<NSManagedObject> {
switch self {
case ._attribute(let keyPath):
return SelectTerm<NSManagedObject>._attribute(keyPath)
case ._aggregate(let function, let keyPath, let alias, let nativeType):
return SelectTerm<NSManagedObject>._aggregate(function: function, keyPath: keyPath, alias: alias, nativeType: nativeType)
case ._identity(let alias, let nativeType):
return SelectTerm<NSManagedObject>._identity(alias: alias, nativeType: nativeType)
}
fatalError()
}
}
// MARK: - CSSelect
/**
The `CSSelect` serves as the Objective-C bridging type for `Select`.
- SeeAlso: `Select`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSSelect: NSObject {
/**
Creates a `CSSelect` clause for querying `NSNumber` values.
```
NSNumber *maxAge = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectNumber(CSAggregateMax(@"age"))
// ...
```
- parameter numberTerm: the `CSSelectTerm` specifying the attribute/aggregate value to query
*/
@objc
public convenience init(numberTerm: CSSelectTerm) {
self.init(Select<NSManagedObject, NSNumber>(numberTerm.bridgeToSwift))
fatalError()
}
/**
Creates a `CSSelect` clause for querying `NSDecimalNumber` values.
```
NSDecimalNumber *averagePrice = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectDecimal(CSAggregateAverage(@"price"))
// ...
```
- parameter decimalTerm: the `CSSelectTerm` specifying the attribute/aggregate value to query
*/
@objc
public convenience init(decimalTerm: CSSelectTerm) {
self.init(Select<NSManagedObject, NSDecimalNumber>(decimalTerm.bridgeToSwift))
fatalError()
}
/**
Creates a `CSSelect` clause for querying `NSString` values.
```
NSString *fullname = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectString(CSAttribute(@"fullname"))
// ...
```
- parameter stringTerm: the `CSSelectTerm` specifying the attribute/aggregate value to query
*/
@objc
public convenience init(stringTerm: CSSelectTerm) {
self.init(Select<NSManagedObject, NSString>(stringTerm.bridgeToSwift))
fatalError()
}
/**
Creates a `CSSelect` clause for querying `NSDate` values.
```
NSDate *lastUpdate = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectDate(CSAggregateMax(@"updatedDate"))
// ...
```
- parameter dateTerm: the `CSSelectTerm` specifying the attribute/aggregate value to query
*/
@objc
public convenience init(dateTerm: CSSelectTerm) {
self.init(Select<NSManagedObject, Date>(dateTerm.bridgeToSwift))
fatalError()
}
/**
Creates a `CSSelect` clause for querying `NSData` values.
```
NSData *imageData = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectData(CSAttribute(@"imageData"))
// ...
```
- parameter dataTerm: the `CSSelectTerm` specifying the attribute/aggregate value to query
*/
@objc
public convenience init(dataTerm: CSSelectTerm) {
self.init(Select<NSManagedObject, Data>(dataTerm.bridgeToSwift))
fatalError()
}
/**
Creates a `CSSelect` clause for querying `NSManagedObjectID` values.
```
NSManagedObjectID *objectID = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectObjectID()
// ...
```
*/
@objc
public convenience init(objectIDTerm: ()) {
self.init(Select<NSManagedObject, NSManagedObjectID>(.objectID()))
fatalError()
}
/**
Creates a `CSSelect` clause for querying `NSDictionary` of an entity's attribute keys and values.
```
NSDictionary *keyValues = [CSCoreStore
queryValueFrom:[CSFrom entityClass:[MyPersonEntity class]]
select:[CSSelect dictionaryForTerm:[CSSelectTerm maximum:@"age" as:nil]]];
```
- parameter term: the `CSSelectTerm` specifying the attribute/aggregate value to query
- returns: a `CSSelect` clause for querying an entity attribute
*/
@objc
public static func dictionaryForTerm(_ term: CSSelectTerm) -> CSSelect {
return self.init(Select<NSManagedObject, NSDictionary>(term.bridgeToSwift))
fatalError()
}
/**
Creates a `CSSelect` clause for querying `NSDictionary` of an entity's attribute keys and values.
```
NSDictionary *keyValues = [CSCoreStore
queryValueFrom:[CSFrom entityClass:[MyPersonEntity class]]
select:[CSSelect dictionaryForTerms:@[
[CSSelectTerm attribute:@"name" as:nil],
[CSSelectTerm attribute:@"age" as:nil]
]]];
```
- parameter terms: the `CSSelectTerm`s specifying the attribute/aggregate values to query
- returns: a `CSSelect` clause for querying an entity attribute
*/
@objc
public static func dictionaryForTerms(_ terms: [CSSelectTerm]) -> CSSelect {
return self.init(Select<NSManagedObject, NSDictionary>(terms.map { $0.bridgeToSwift }))
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return self.attributeType.hashValue
^ self.selectTerms.map { $0.hashValue }.reduce(0, ^)
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSSelect else {
return false
}
return self.attributeType == object.attributeType
&& self.selectTerms == object.selectTerms
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
// MARK: CoreStoreObjectiveCType
public init<O: NSManagedObject, T: QueryableAttributeType>(_ swiftValue: Select<O, T>) {
self.attributeType = T.cs_rawAttributeType
self.selectTerms = swiftValue.selectTerms.map({ $0.downcast() })
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
public init<O: NSManagedObject, T>(_ swiftValue: Select<O, T>) {
self.attributeType = .undefinedAttributeType
self.selectTerms = swiftValue.selectTerms.map({ $0.downcast() })
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
// MARK: Internal
internal let attributeType: NSAttributeType
internal let selectTerms: [SelectTerm<NSManagedObject>]
// MARK: Internal
internal func applyToFetchRequest(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) {
fetchRequest.includesPendingChanges = false
fetchRequest.resultType = .dictionaryResultType
func attributeDescription(for keyPath: String, in entity: NSEntityDescription) -> NSAttributeDescription? {
let components = keyPath.components(separatedBy: ".")
switch components.count {
case 0:
return nil
case 1:
return entity.attributesByName[components[0]]
default:
guard let relationship = entity.relationshipsByName[components[0]],
let destinationEntity = relationship.destinationEntity else {
return nil
}
return attributeDescription(
for: components.dropFirst().joined(separator: "."),
in: destinationEntity
)
}
}
var propertiesToFetch = [Any]()
for term in self.selectTerms {
switch term {
case ._attribute(let keyPath):
propertiesToFetch.append(keyPath)
case ._aggregate(let function, let keyPath, let alias, let nativeType):
let entityDescription = fetchRequest.entity!
if let attributeDescription = attributeDescription(for: keyPath, in: entityDescription) {
let expressionDescription = NSExpressionDescription()
expressionDescription.name = alias
if nativeType == .undefinedAttributeType {
expressionDescription.expressionResultType = attributeDescription.attributeType
}
else {
expressionDescription.expressionResultType = nativeType
}
expressionDescription.expression = NSExpression(
forFunction: function,
arguments: [NSExpression(forKeyPath: keyPath)]
)
propertiesToFetch.append(expressionDescription)
}
else {
Internals.log(
.warning,
message: "The key path \"\(keyPath)\" could not be resolved in entity \(Internals.typeName(entityDescription.managedObjectClassName)) as an attribute and will be ignored by \(Internals.typeName(self)) query clause."
)
}
case ._identity(let alias, let nativeType):
let expressionDescription = NSExpressionDescription()
expressionDescription.name = alias
if nativeType == .undefinedAttributeType {
expressionDescription.expressionResultType = .objectIDAttributeType
}
else {
expressionDescription.expressionResultType = nativeType
}
expressionDescription.expression = NSExpression.expressionForEvaluatedObject()
propertiesToFetch.append(expressionDescription)
}
}
fetchRequest.propertiesToFetch = propertiesToFetch
}
// MARK: Private
private let bridgeToSwift: CoreStoreDebugStringConvertible
}
// MARK: - Select
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension Select where O: NSManagedObject {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSSelect {
return CSSelect(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> Select<NSManagedObject, T> {
return Select<NSManagedObject, T>(self.selectTerms.map({ $0.downcast() }))
fatalError()
}
}

View File

@@ -29,162 +29,83 @@ import CoreData
// MARK: - CSSetupResult
/**
The `CSSetupResult` serves as the Objective-C bridging type for `SetupResult`.
- SeeAlso: `SetupResult`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSSetupResult: NSObject {
/**
`YES` if adding the `CSStorageInterface` to the `CSDataStack` succeeded, `NO` otherwise.
*/
@objc
public var isSuccess: Bool {
return self.storage != nil
fatalError()
}
/**
`YES` if adding the `CSStorageInterface` to the `CSDataStack` failed, `NO` otherwise. When `YES`, the `error` property returns the actual `NSError` for the failure.
*/
@objc
public var isFailure: Bool {
return self.storage == nil
fatalError()
}
/**
A `CSStorageInterface` instance if the `commit` operation for the transaction succeeded. Returns `nil` otherwise.
*/
@objc
public let storage: CSStorageInterface?
/**
The `NSError` for a failed `commit` operation, or `nil` if the `commit` succeeded
*/
@objc
public let error: NSError?
/**
If the result was a success, the `success` block is executed with the `CSStorageInterface` instance that was added to the `CSDataStack`. If the result was a failure, the `failure` block is executed with an `NSError` argument pertaining to the actual error.
The blocks are executed immediately as `@noescape` and will not be retained.
- parameter success: the block to execute on success. The block passes a `CSStorageInterface` instance that was added to the `CSDataStack`.
- parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error.
*/
@objc
public func handleSuccess(_ success: (_ storage: CSStorageInterface) -> Void, failure: (_ error: NSError) -> Void) {
if let storage = self.storage {
success(storage)
}
else {
failure(self.error!)
}
fatalError()
}
/**
If the result was a success, the `success` block is executed with a `BOOL` argument that indicates if there were any changes made. If the result was a failure, this method does nothing.
The block is executed immediately as `@noescape` and will not be retained.
- parameter success: the block to execute on success. The block passes a `BOOL` argument that indicates if there were any changes made.
*/
@objc
public func handleSuccess(_ success: (_ storage: CSStorageInterface) -> Void) {
guard let storage = self.storage else {
return
}
success(storage)
fatalError()
}
/**
If the result was a failure, the `failure` block is executed with an `NSError` argument pertaining to the actual error. If the result was a success, this method does nothing.
The block is executed immediately as `@noescape` and will not be retained.
- parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error.
*/
@objc
public func handleFailure(_ failure: (_ error: NSError) -> Void) {
guard let error = self.error else {
return
}
failure(error)
fatalError()
}
// MARK: NSObject
public override var hash: Int {
if let storage = self.storage {
return self.isSuccess.hashValue ^ ObjectIdentifier(storage).hashValue
}
return self.isSuccess.hashValue ^ self.error!.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSSetupResult else {
return false
}
return self.storage === object.storage
&& self.error == object.error
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
// MARK: CoreStoreObjectiveCType
public required init<T>(_ swiftValue: SetupResult<T>) where T: CoreStoreSwiftType, T.ObjectiveCType: CSStorageInterface {
switch swiftValue {
case .success(let storage):
self.storage = storage.bridgeToObjectiveC
self.error = nil
case .failure(let error):
self.storage = nil
self.error = error.bridgeToObjectiveC
}
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
// MARK: Private
private let bridgeToSwift: CoreStoreDebugStringConvertible
}
// MARK: - SetupResult
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension SetupResult where Success: StorageInterface, Success: CoreStoreSwiftType, Success.ObjectiveCType: CSStorageInterface, Failure == CoreStoreError {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSSetupResult {
return CSSetupResult(self)
fatalError()
}
}

View File

@@ -29,29 +29,16 @@ import CoreData
// MARK: - CSStorageInterface
/**
The `CSStorageInterface` serves as the Objective-C bridging type for `StorageInterface`.
- SeeAlso: `StorageInterface`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public protocol CSStorageInterface {
/**
The string identifier for the `NSPersistentStore`'s `type` property. This is the same string CoreStore will use to create the `NSPersistentStore` from the `NSPersistentStoreCoordinator`'s `addPersistentStoreWithType(...)` method.
*/
@objc
static var storeType: String { get }
/**
The configuration name in the model file
*/
@objc
var configuration: ModelConfiguration { get }
/**
The options dictionary for the `NSPersistentStore`
*/
@objc
var storeOptions: [AnyHashable: Any]? { get }
}
@@ -59,67 +46,32 @@ public protocol CSStorageInterface {
// MARK: - CSLocalStorageOptions
/**
The `CSLocalStorageOptions` provides settings that tells the `CSDataStack` how to setup the persistent store for `CSLocalStorage` implementers.
- SeeAlso: `LocalStorageOptions`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public enum CSLocalStorageOptions: Int {
/**
Tells the `DataStack` that the store should not be migrated or recreated, and should simply fail on model mismatch
*/
case none = 0
/**
Tells the `DataStack` to delete and recreate the store on model mismatch, otherwise exceptions will be thrown on failure instead
*/
case recreateStoreOnModelMismatch = 1
/**
Tells the `DataStack` to prevent progressive migrations for the store
*/
case preventProgressiveMigration = 2
/**
Tells the `DataStack` to allow lightweight migration for the store when added synchronously
*/
case allowSynchronousLightweightMigration = 4
}
// MARK: - CSLocalStorage
/**
The `CSLocalStorage` serves as the Objective-C bridging type for `LocalStorage`.
- SeeAlso: `LocalStorage`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public protocol CSLocalStorage: CSStorageInterface {
/**
The `NSURL` that points to the store file
*/
@objc
var fileURL: URL { get }
/**
An array of `SchemaMappingProvider`s that provides the complete mapping models for custom migrations. This is currently only supported for Swift code.
*/
@objc
var migrationMappingProviders: [Any] { get }
/**
Options that tell the `CSDataStack` how to setup the persistent store
*/
@objc
var localStorageOptions: Int { get }
/**
Called by the `CSDataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. Implementers can use the `sourceModel` to perform necessary store operations. (SQLite stores for example, can convert WAL journaling mode to DELETE before deleting)
*/
@objc
func cs_eraseStorageAndWait(metadata: NSDictionary, soureModelHint: NSManagedObjectModel?, error: NSErrorPointer) -> Bool
}

View File

@@ -29,103 +29,54 @@ import CoreData
// MARK: - CSSynchronousDataTransaction
/**
The `CSSynchronousDataTransaction` serves as the Objective-C bridging type for `SynchronousDataTransaction`.
- SeeAlso: `SynchronousDataTransaction`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSSynchronousDataTransaction: CSBaseDataTransaction, CoreStoreObjectiveCType {
/**
Saves the transaction changes and waits for completion synchronously. This method should not be used after the `-commitAndWaitWithError:` method was already called once.
- parameter error: the `CSError` pointer that indicates the reason in case of an failure
- returns: `YES` if the commit succeeded, `NO` if the commit failed. If `NO`, the `error` argument will hold error information.
*/
@objc
public func commitAndWait(error: NSErrorPointer) -> Bool {
return bridge(error) {
if case (_, let error?) = self.bridgeToSwift.context.saveSynchronously(
waitForMerge: true,
sourceIdentifier: nil
) {
throw error
}
}
fatalError()
}
// MARK: NSObject
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
// MARK: BaseDataTransaction
/**
Creates a new `NSManagedObject` with the specified entity type.
- parameter into: the `CSInto` clause indicating the destination `NSManagedObject` entity type and the destination configuration
- returns: a new `NSManagedObject` instance of the specified entity type.
*/
@objc
public override func createInto(_ into: CSInto) -> Any {
return self.bridgeToSwift.create(into.bridgeToSwift)
fatalError()
}
/**
Returns an editable proxy of a specified `NSManagedObject`. This method should not be used after the `-commitAndWait` method was already called once.
- parameter object: the `NSManagedObject` type to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
public override func editObject(_ object: NSManagedObject?) -> Any? {
return self.bridgeToSwift.edit(object)
fatalError()
}
/**
Returns an editable proxy of the object with the specified `NSManagedObjectID`. This method should not be used after the `-commitAndWait` method was already called once.
- parameter into: a `CSInto` clause specifying the entity type
- parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
*/
@objc
public override func editInto(_ into: CSInto, objectID: NSManagedObjectID) -> Any? {
return self.bridgeToSwift.edit(into.bridgeToSwift, objectID)
fatalError()
}
/**
Deletes a specified `NSManagedObject`. This method should not be used after the `-commitAndWait` method was already called once.
- parameter object: the `NSManagedObject` type to be deleted
*/
@objc
public override func deleteObject(_ object: NSManagedObject?) {
return self.bridgeToSwift.delete(object)
fatalError()
}
/**
Deletes the specified `NSManagedObject`s.
- parameter objects: the `NSManagedObject`s to be deleted
*/
public override func deleteObjects(_ objects: [NSManagedObject]) {
self.bridgeToSwift.delete(objects)
fatalError()
}
@@ -134,31 +85,26 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction, CoreStor
public typealias SwiftType = SynchronousDataTransaction
public var bridgeToSwift: SynchronousDataTransaction {
return super.swiftTransaction as! SynchronousDataTransaction
fatalError()
}
public required init(_ swiftValue: SynchronousDataTransaction) {
super.init(swiftValue as BaseDataTransaction)
}
public required override init(_ swiftValue: BaseDataTransaction) {
super.init(swiftValue)
fatalError()
}
}
// MARK: - SynchronousDataTransaction
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension SynchronousDataTransaction: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSSynchronousDataTransaction {
return CSSynchronousDataTransaction(self)
fatalError()
}
}

View File

@@ -29,42 +29,28 @@ import CoreData
// MARK: - CSTweak
/**
The `CSTweak` serves as the Objective-C bridging type for `Tweak`.
- SeeAlso: `Tweak`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreObjectiveCType {
/**
The block to customize the `NSFetchRequest`
*/
@objc
public var block: (_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> Void {
return self.bridgeToSwift.closure
fatalError()
}
/**
Initializes a `CSTweak` clause with a closure where the `NSFetchRequest` may be configured.
- Important: `CSTweak`'s closure is executed only just before the fetch occurs, so make sure that any values captured by the closure is not prone to race conditions. Also, some utilities (such as `CSListMonitor`s) may keep `CSFetchClause`s in memory and may thus introduce retain cycles if reference captures are not handled properly.
- parameter block: the block to customize the `NSFetchRequest`
*/
@objc
public convenience init(block: @escaping (_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> Void) {
self.init(Tweak(block))
fatalError()
}
// MARK: NSObject
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -72,8 +58,8 @@ public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
@objc
public func applyToFetchRequest(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) {
self.bridgeToSwift.applyToFetchRequest(fetchRequest)
fatalError()
}
@@ -82,22 +68,21 @@ public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
public let bridgeToSwift: Tweak
public init(_ swiftValue: Tweak) {
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
}
// MARK: - Tweak
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension Tweak: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSTweak {
return CSTweak(self)
fatalError()
}
}

View File

@@ -29,50 +29,32 @@ import Foundation
// MARK: - CSUnsafeDataModelSchema
/**
The `CSUnsafeDataModelSchema` serves as the Objective-C bridging type for `UnsafeDataModelSchema`.
- SeeAlso: `UnsafeDataModelSchema`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSUnsafeDataModelSchema: NSObject, CSDynamicSchema, CoreStoreObjectiveCType {
/**
Initializes a `CSUnsafeDataModelSchema` from an `NSManagedObjectModel`.
- parameter modelName: the model version, typically the file name of an *.xcdatamodeld file (without the file extension)
- parameter model: the `NSManagedObjectModel`
*/
@objc
public required init(modelName: ModelVersion, model: NSManagedObjectModel) {
self.bridgeToSwift = UnsafeDataModelSchema(
modelName: modelName,
model: model
)
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return ObjectIdentifier(self.bridgeToSwift).hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSUnsafeDataModelSchema else {
return false
}
return self.bridgeToSwift === object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -80,14 +62,14 @@ public final class CSUnsafeDataModelSchema: NSObject, CSDynamicSchema, CoreStore
@objc
public var modelVersion: ModelVersion {
return self.bridgeToSwift.modelVersion
fatalError()
}
@objc
public func rawModel() -> NSManagedObjectModel {
return self.bridgeToSwift.rawModel()
fatalError()
}
@@ -96,22 +78,21 @@ public final class CSUnsafeDataModelSchema: NSObject, CSDynamicSchema, CoreStore
public let bridgeToSwift: UnsafeDataModelSchema
public required init(_ swiftValue: UnsafeDataModelSchema) {
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
}
// MARK: - UnsafeDataModelSchema
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension UnsafeDataModelSchema: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSUnsafeDataModelSchema {
return CSUnsafeDataModelSchema(self)
fatalError()
}
}

View File

@@ -29,166 +29,76 @@ import CoreData
// MARK: - CSUnsafeDataTransaction
/**
The `CSUnsafeDataTransaction` serves as the Objective-C bridging type for `UnsafeDataTransaction`.
- SeeAlso: `UnsafeDataTransaction`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSUnsafeDataTransaction: CSBaseDataTransaction, CoreStoreObjectiveCType {
/**
Saves the transaction changes asynchronously. For a `CSUnsafeDataTransaction`, multiple commits are allowed, although it is the developer's responsibility to ensure a reasonable leeway to prevent blocking the main thread.
- parameter success: the block executed if the save succeeds.
- parameter failure: the block executed if the save fails. A `CSError` is reported as the argument of the block.
*/
@objc
public func commitWithSuccess(_ success: (() -> Void)?, _ failure: ((CSError) -> Void)?) {
self.bridgeToSwift.context.saveAsynchronously(
sourceIdentifier: nil,
completion: { (_, error) in
defer {
withExtendedLifetime(self, {})
}
if let error = error {
failure?(error.bridgeToObjectiveC)
}
else {
success?()
}
}
)
fatalError()
}
/**
Saves the transaction changes and waits for completion synchronously. For a `CSUnsafeDataTransaction`, multiple commits are allowed, although it is the developer's responsibility to ensure a reasonable leeway to prevent blocking the main thread.
- parameter error: the `CSError` pointer that indicates the reason in case of an failure
- returns: `YES` if the commit succeeded, `NO` if the commit failed. If `NO`, the `error` argument will hold error information.
*/
@objc
public func commitAndWait(error: NSErrorPointer) -> Bool {
return bridge(error) {
if case (_, let error?) = self.bridgeToSwift.context.saveSynchronously(
waitForMerge: true,
sourceIdentifier: nil
) {
throw error
}
}
fatalError()
}
/**
Rolls back the transaction.
*/
@objc
public func rollback() {
self.bridgeToSwift.rollback()
fatalError()
}
/**
Undo's the last change made to the transaction.
*/
@objc
public func undo() {
self.bridgeToSwift.undo()
fatalError()
}
/**
Redo's the last undone change to the transaction.
*/
@objc
public func redo() {
self.bridgeToSwift.redo()
fatalError()
}
/**
Immediately flushes all pending changes to the transaction's observers. This is useful in conjunction with `ListMonitor`s and `ObjectMonitor`s created from `UnsafeDataTransaction`s used to manage temporary "scratch" data.
- Important: Note that unlike `commit()`, `flush()` does not propagate/save updates to the `DataStack` and the persistent store. However, the flushed changes will be seen by children transactions created further from the current transaction (i.e. through `transaction.beginUnsafe()`)
*/
@objc
public func flush() {
self.bridgeToSwift.flush()
fatalError()
}
/**
Flushes all pending changes to the transaction's observers at the end of the `closure`'s execution. This is useful in conjunction with `ListMonitor`s and `ObjectMonitor`s created from `UnsafeDataTransaction`s used to manage temporary "scratch" data.
- Important: Note that unlike `commit()`, `flush()` does not propagate/save updates to the `DataStack` and the persistent store. However, the flushed changes will be seen by children transactions created further from the current transaction (i.e. through `transaction.beginUnsafe()`)
- parameter block: the block where changes can be made prior to the flush
*/
@objc
public func flush(_ block: () -> Void) {
self.bridgeToSwift.flush {
block()
}
fatalError()
}
/**
Begins a child transaction where `NSManagedObject` creates, updates, and deletes can be made. This is useful for making temporary changes, such as partially filled forms.
To support "undo" methods such as `-undo`, `-redo`, and `-rollback`, use the `-beginSafeWithSupportsUndo:` method passing `YES` to the argument. Without "undo" support, calling those methods will raise an exception.
- returns: a `CSUnsafeDataTransaction` instance where creates, updates, and deletes can be made.
*/
@objc
public func beginUnsafe() -> CSUnsafeDataTransaction {
return bridge {
self.bridgeToSwift.beginUnsafe()
}
fatalError()
}
/**
Begins a child transaction where `NSManagedObject` creates, updates, and deletes can be made. This is useful for making temporary changes, such as partially filled forms.
- prameter supportsUndo: `-undo`, `-redo`, and `-rollback` methods are only available when this parameter is `YES`, otherwise those method will raise an exception. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited.
- returns: a `CSUnsafeDataTransaction` instance where creates, updates, and deletes can be made.
*/
@objc
public func beginUnsafeWithSupportsUndo(_ supportsUndo: Bool) -> CSUnsafeDataTransaction {
return bridge {
self.bridgeToSwift.beginUnsafe(supportsUndo: supportsUndo)
}
fatalError()
}
/**
Returns the `NSManagedObjectContext` for this unsafe transaction. Use only for cases where external frameworks need an `NSManagedObjectContext` instance to work with.
Note that it is the developer's responsibility to ensure the following:
- that the `CSUnsafeDataTransaction` that owns this context should be strongly referenced and prevented from being deallocated during the context's lifetime
- that all saves will be done either through the `CSUnsafeDataTransaction`'s `-commit:` or `-commitAndWait` method, or by calling `-save:` manually on the context, its parent, and all other ancestor contexts if there are any.
*/
@objc
public func unsafeContext() -> NSManagedObjectContext {
return self.bridgeToSwift.context
fatalError()
}
// MARK: NSObject
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -197,31 +107,26 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction, CoreStoreObje
public typealias SwiftType = UnsafeDataTransaction
public var bridgeToSwift: UnsafeDataTransaction {
return super.swiftTransaction as! UnsafeDataTransaction
fatalError()
}
public required init(_ swiftValue: UnsafeDataTransaction) {
super.init(swiftValue as BaseDataTransaction)
}
public required override init(_ swiftValue: BaseDataTransaction) {
super.init(swiftValue)
fatalError()
}
}
// MARK: - UnsafeDataTransaction
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension UnsafeDataTransaction: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSUnsafeDataTransaction {
return CSUnsafeDataTransaction(self)
fatalError()
}
}

View File

@@ -29,112 +29,62 @@ import CoreData
// MARK: - CSWhere
/**
The `CSWhere` serves as the Objective-C bridging type for `Where`.
- SeeAlso: `Where`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause {
/**
The internal `NSPredicate` instance for the `Where` clause
*/
@objc
public var predicate: NSPredicate {
return self.bridgeToSwift.predicate
fatalError()
}
/**
Initializes a `CSWhere` clause with a predicate that always evaluates to the specified boolean value
```
MyPersonEntity *people = [transaction
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSWhereValue(YES)]]];
```
- parameter value: the boolean value for the predicate
*/
@objc
public convenience init(value: Bool) {
self.init(Where(value))
fatalError()
}
/**
Initializes a `CSWhere` clause with a predicate using the specified string format and arguments
```
NSPredicate *predicate = // ...
MyPersonEntity *people = [transaction
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSWherePredicate(predicate)]];
```
- parameter format: the format string for the predicate
- parameter argumentArray: the arguments for `format`
*/
@objc
public convenience init(format: String, argumentArray: [NSObject]?) {
self.init(Where(format, argumentArray: argumentArray))
fatalError()
}
/**
Initializes a `CSWhere` clause that compares equality
- parameter keyPath: the keyPath to compare with
- parameter value: the arguments for the `==` operator
*/
@objc
public convenience init(keyPath: KeyPathString, isEqualTo value: CoreDataNativeType?) {
self.init(value == nil || value is NSNull
? Where("\(keyPath) == nil")
: Where("\(keyPath) == %@", value!))
fatalError()
}
/**
Initializes a `CSWhere` clause that compares membership
- parameter keyPath: the keyPath to compare with
- parameter list: the array to check membership of
*/
@objc
public convenience init(keyPath: KeyPathString, isMemberOf list: [CoreDataNativeType]) {
self.init(Where("\(keyPath) IN %@", list as NSArray))
fatalError()
}
/**
Initializes a `CSWhere` clause with an `NSPredicate`
- parameter predicate: the `NSPredicate` for the fetch or query
*/
@objc
public convenience init(predicate: NSPredicate) {
self.init(Where(predicate))
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return self.bridgeToSwift.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSWhere else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -142,8 +92,8 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
@objc
public func applyToFetchRequest(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) {
self.bridgeToSwift.applyToFetchRequest(fetchRequest)
fatalError()
}
@@ -152,29 +102,21 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
public let bridgeToSwift: Where<NSManagedObject>
public init<O: NSManagedObject>(_ swiftValue: Where<O>) {
self.bridgeToSwift = swiftValue.downcast()
super.init()
fatalError()
}
}
// MARK: - Where
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension Where where O: NSManagedObject {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSWhere {
return CSWhere(self)
}
// MARK: FilePrivate
fileprivate func downcast() -> Where<NSManagedObject> {
return Where<NSManagedObject>(self.predicate)
fatalError()
}
}

View File

@@ -29,50 +29,32 @@ import Foundation
// MARK: - CSXcodeDataModelSchema
/**
The `CSXcodeDataModelSchema` serves as the Objective-C bridging type for `XcodeDataModelSchema`.
- SeeAlso: `XcodeDataModelSchema`
*/
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
public final class CSXcodeDataModelSchema: NSObject, CSDynamicSchema, CoreStoreObjectiveCType {
/**
Initializes an `CSXcodeDataModelSchema` from an *.xcdatamodeld file URL.
- parameter modelName: the model version, typically the file name of an *.xcdatamodeld file (without the file extension)
- parameter modelVersionFileURL: the file URL that points to the .xcdatamodeld's "momd" file.
*/
@objc
public required init(modelName: ModelVersion, modelVersionFileURL: URL) {
self.bridgeToSwift = XcodeDataModelSchema(
modelName: modelName,
modelVersionFileURL: modelVersionFileURL
)
fatalError()
}
// MARK: NSObject
public override var hash: Int {
return ObjectIdentifier(self.bridgeToSwift).hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSXcodeDataModelSchema else {
return false
}
return self.bridgeToSwift === object.bridgeToSwift
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
@@ -80,14 +62,14 @@ public final class CSXcodeDataModelSchema: NSObject, CSDynamicSchema, CoreStoreO
@objc
public var modelVersion: ModelVersion {
return self.bridgeToSwift.modelVersion
fatalError()
}
@objc
public func rawModel() -> NSManagedObjectModel {
return self.bridgeToSwift.rawModel()
fatalError()
}
@@ -96,22 +78,21 @@ public final class CSXcodeDataModelSchema: NSObject, CSDynamicSchema, CoreStoreO
public let bridgeToSwift: XcodeDataModelSchema
public required init(_ swiftValue: XcodeDataModelSchema) {
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
}
// MARK: - XcodeDataModelSchema
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension XcodeDataModelSchema: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSXcodeDataModelSchema {
return CSXcodeDataModelSchema(self)
fatalError()
}
}

View File

@@ -37,7 +37,7 @@
#error CoreStore Objective-C utilities can only be used on platforms that support C function overloading
#endif
#define CORESTORE_EXTERN extern __deprecated_msg("CoreStore Objective-C API will be removed soon.")
#define CORESTORE_EXTERN extern __deprecated_msg("CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
#define CORESTORE_OVERLOADABLE __attribute__((__overloadable__))
#define CORESTORE_REQUIRES_NIL_TERMINATION __attribute__((sentinel(0, 1)))
#define CORESTORE_RETURNS_RETAINED __attribute__((ns_returns_retained))
@@ -46,12 +46,14 @@
#pragma mark - KeyPathString Utilities
#define CSKeyPath(type, property) ({ \
CORESTORE_OBJC_OBSOLETE; \
type *_je_keypath_dummy __attribute__((unused)); \
typeof(_je_keypath_dummy.property) _je_keypath_dummy_property __attribute__((unused)); \
@#property; \
})
#define CSKeyPathOperator(operator, type, property) ({ \
CORESTORE_OBJC_OBSOLETE; \
type *_je_keypath_dummy __attribute__((unused)); \
typeof(_je_keypath_dummy.property) _je_keypath_dummy_property __attribute__((unused)); \
@"@" #operator "." #property; \
@@ -65,85 +67,19 @@
@class CSFrom;
/**
@abstract
Initializes a <tt>CSFrom</tt> clause with the specified entity class.
@code
MyPersonEntity *people = [transaction fetchAllFrom:
CSFromClass([MyPersonEntity class])];
@endcode
@param entityClass
the <tt>NSManagedObject</tt> class type to be created
@result
a <tt>CSFrom</tt> clause with the specified entity class
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN CORESTORE_OVERLOADABLE
CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSFrom</tt> clause with the specified configuration.
@code
MyPersonEntity *people = [transaction fetchAllFrom:
CSFromClass([MyPersonEntity class], @"Configuration1")];
@endcode
@param entityClass
the <tt>NSManagedObject</tt> class type to be created
@param configuration
an <tt>NSPersistentStore</tt> configuration name to associate objects from. This parameter is required if multiple configurations contain the created <tt>NSManagedObject</tt>'s entity type. Set to <tt>[NSNull null]</tt> to use the default configuration.
@result
a <tt>CSFrom</tt> clause with the specified configuration
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN CORESTORE_OVERLOADABLE
CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass, NSNull *_Nonnull configuration) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSFrom</tt> clause with the specified configuration.
@code
MyPersonEntity *people = [transaction fetchAllFrom:
CSFromClass([MyPersonEntity class], @"Configuration1")];
@endcode
@param entityClass
the <tt>NSManagedObject</tt> class type to be created
@param configuration
an <tt>NSPersistentStore</tt> configuration name to associate objects from. This parameter is required if multiple configurations contain the created <tt>NSManagedObject</tt>'s entity type. Set to <tt>[NSNull null]</tt> to use the default configuration.
@result
a <tt>CSFrom</tt> clause with the specified configuration
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN CORESTORE_OVERLOADABLE
CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass, NSString *_Nonnull configuration) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSFrom</tt> clause with the specified configurations.
@code
MyPersonEntity *people = [transaction fetchAllFrom:
CSFromClass([MyPersonEntity class],
@[[NSNull null], @"Configuration1"])];
@endcode
@param entityClass
the <tt>NSManagedObject</tt> class type to be created
@param configurations
an array of the <tt>NSPersistentStore</tt> configuration names to associate objects from. This parameter is required if multiple configurations contain the created <tt>NSManagedObject</tt>'s entity type. Set to <tt>[NSNull null]</tt> to use the default configuration.
@result
a <tt>CSFrom</tt> clause with the specified configurations
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN CORESTORE_OVERLOADABLE
CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass, NSArray<id> *_Nonnull configurations) CORESTORE_RETURNS_RETAINED;
@@ -152,42 +88,15 @@ CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass, NSArray<id> *_Nonnull c
@class CSGroupBy;
/**
@abstract
Initializes a <tt>CSGroupBy</tt> clause with a key path string
@param keyPath
a key path string to group results with
@result
a <tt>CSGroupBy</tt> clause with a key path string
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSGroupBy *_Nonnull CSGroupByKeyPath(NSString *_Nonnull keyPath) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSGroupBy</tt> clause with a list of key path strings
@param keyPath
a nil-terminated list of key path strings to group results with
@result
a <tt>CSGroupBy</tt> clause with a list of key path strings
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN CORESTORE_OVERLOADABLE
CSGroupBy *_Nonnull CSGroupByKeyPaths(NSString *_Nonnull keyPath, ...) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSGroupBy</tt> clause with a list of key path strings
@param keyPaths
a list of key path strings to group results with
@result
a <tt>CSGroupBy</tt> clause with a list of key path strings
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN CORESTORE_OVERLOADABLE
CSGroupBy *_Nonnull CSGroupByKeyPaths(NSArray<NSString *> *_Nonnull keyPaths) CORESTORE_RETURNS_RETAINED;
@@ -196,63 +105,15 @@ CSGroupBy *_Nonnull CSGroupByKeyPaths(NSArray<NSString *> *_Nonnull keyPaths) CO
@class CSInto;
/**
@abstract
Initializes a <tt>CSInto</tt> clause with the specified entity class.
@code
MyPersonEntity *people = [transaction createInto:
CSIntoClass([MyPersonEntity class])];
@endcode
@param entityClass
the <tt>NSManagedObject</tt> class type to be created
@result
a <tt>CSInto</tt> clause with the specified entity class
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN CORESTORE_OVERLOADABLE
CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSInto</tt> clause with the specified entity class.
@code
MyPersonEntity *people = [transaction createInto:
CSIntoClass([MyPersonEntity class], [NSNull null])];
@endcode
@param entityClass
the <tt>NSManagedObject</tt> class type to be created
@param configuration
an <tt>NSPersistentStore</tt> configuration name to associate objects from. This parameter is required if multiple configurations contain the created <tt>NSManagedObject</tt>'s entity type. Set to <tt>[NSNull null]</tt> to use the default configuration.
@result
a <tt>CSInto</tt> clause with the specified entity class
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass, NSNull *_Nonnull configuration) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSInto</tt> clause with the specified entity class.
@code
MyPersonEntity *people = [transaction createInto:
CSIntoClass([MyPersonEntity class], @"Configuration1")];
@endcode
@param entityClass
the <tt>NSManagedObject</tt> class type to be created
@param configuration
an <tt>NSPersistentStore</tt> configuration name to associate objects from. This parameter is required if multiple configurations contain the created <tt>NSManagedObject</tt>'s entity type. Set to <tt>[NSNull null]</tt> to use the default configuration.
@result
a <tt>CSInto</tt> clause with the specified entity class
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass, NSString *_Nonnull configuration) CORESTORE_RETURNS_RETAINED;
@@ -261,98 +122,23 @@ CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass, NSString *_Nonnull conf
@class CSOrderBy;
/**
@abstract
Syntax sugar for initializing an ascending <tt>NSSortDescriptor</tt> for use with <tt>CSOrderBy</tt>
@code
MyPersonEntity *people = [CSCoreStore
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSOrderByKey(CSSortAscending(@"fullname"))]]];
@endcode
@param key
the attribute key to sort with
@result
an <tt>NSSortDescriptor</tt> for use with <tt>CSOrderBy</tt>
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
NSSortDescriptor *_Nonnull CSSortAscending(NSString *_Nonnull key) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Syntax sugar for initializing a descending <tt>NSSortDescriptor</tt> for use with <tt>CSOrderBy</tt>
@code
MyPersonEntity *people = [CSCoreStore
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSOrderByKey(CSSortDescending(@"fullname"))]]];
@endcode
@param key
the attribute key to sort with
@result
an <tt>NSSortDescriptor</tt> for use with <tt>CSOrderBy</tt>
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
NSSortDescriptor *_Nonnull CSSortDescending(NSString *_Nonnull key) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSOrderBy</tt> clause with a single sort descriptor
@code
MyPersonEntity *people = [transaction
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSOrderByKey(CSSortAscending(@"fullname"))]]];
@endcode
@param sortDescriptor
an <tt>NSSortDescriptor</tt>
@result
a <tt>CSOrderBy</tt> clause with a single sort descriptor
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSOrderBy *_Nonnull CSOrderByKey(NSSortDescriptor *_Nonnull sortDescriptor) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSOrderBy</tt> clause with a list of sort descriptors
@code
MyPersonEntity *people = [transaction
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSOrderByKeys(CSSortAscending(@"fullname"), CSSortDescending(@"age"), nil))]]];
@endcode
@param sortDescriptor
a nil-terminated array of <tt>NSSortDescriptor</tt>s
@result
a <tt>CSOrderBy</tt> clause with a list of sort descriptors
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN CORESTORE_OVERLOADABLE
CSOrderBy *_Nonnull CSOrderByKeys(NSSortDescriptor *_Nonnull sortDescriptor, ...) CORESTORE_RETURNS_RETAINED CORESTORE_REQUIRES_NIL_TERMINATION;
/**
@abstract
Initializes a <tt>CSOrderBy</tt> clause with a list of sort descriptors
@code
MyPersonEntity *people = [transaction
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSOrderByKeys(@[CSSortAscending(@"fullname"), CSSortDescending(@"age")]))]]];
@endcode
@param sortDescriptors
an array of <tt>NSSortDescriptor</tt>s
@result
a <tt>CSOrderBy</tt> clause with a list of sort descriptors
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN CORESTORE_OVERLOADABLE
CSOrderBy *_Nonnull CSOrderByKeys(NSArray<NSSortDescriptor *> *_Nonnull sortDescriptors) CORESTORE_RETURNS_RETAINED;
@@ -362,120 +148,27 @@ CSOrderBy *_Nonnull CSOrderByKeys(NSArray<NSSortDescriptor *> *_Nonnull sortDesc
@class CSSelect;
@class CSSelectTerm;
/**
@abstract
Creates a <tt>CSSelect</tt> clause for querying an <tt>NSNumber</tt> value
@code
NSNumber *maxAge = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectNumber(CSAggregateMax(@"age"))
// ...
@endcode
@param selectTerm
the <tt>CSSelectTerm</tt> specifying the attribute/aggregate value to query
@result
a <tt>CSSelect</tt> clause for querying an <tt>NSNumber</tt> value
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSSelect *_Nonnull CSSelectNumber(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Creates a <tt>CSSelect</tt> clause for querying an <tt>NSDecimalNumber</tt> value
@code
NSDecimalNumber *averagePrice = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectDecimal(CSAggregateAverage(@"price"))
// ...
@endcode
@param selectTerm
the <tt>CSSelectTerm</tt> specifying the attribute/aggregate value to query
@result
a <tt>CSSelect</tt> clause for querying an <tt>NSDecimalNumber</tt> value
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSSelect *_Nonnull CSSelectDecimal(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Creates a <tt>CSSelect</tt> clause for querying an <tt>NSString</tt> value
@code
NSString *fullname = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectString(CSAttribute(@"fullname"))
// ...
@endcode
@param selectTerm
the <tt>CSSelectTerm</tt> specifying the attribute/aggregate value to query
@result
a <tt>CSSelect</tt> clause for querying an <tt>NSString</tt> value
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSSelect *_Nonnull CSSelectString(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Creates a <tt>CSSelect</tt> clause for querying an <tt>NSDate</tt> value
@code
NSDate *lastUpdate = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectDate(CSAggregateMax(@"updatedDate"))
// ...
@endcode
@param selectTerm
the <tt>CSSelectTerm</tt> specifying the attribute/aggregate value to query
@result
a <tt>CSSelect</tt> clause for querying an <tt>NSDate</tt> value
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSSelect *_Nonnull CSSelectDate(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Creates a <tt>CSSelect</tt> clause for querying an <tt>NSData</tt> value
@code
NSData *imageData = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectData(CSAttribute(@"imageData"))
// ...
@endcode
@param selectTerm
the <tt>CSSelectTerm</tt> specifying the attribute/aggregate value to query
@result
a <tt>CSSelect</tt> clause for querying an <tt>NSData</tt> value
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSSelect *_Nonnull CSSelectData(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Creates a <tt>CSSelect</tt> clause for querying an <tt>NSManagedObjectID</tt> value
@code
NSManagedObjectID *objectID = [CSCoreStore
queryValueFrom:CSFromClass([MyPersonEntity class])
select:CSSelectObjectID()
// ...
@endcode
@result
a <tt>CSSelect</tt> clause for querying an <tt>NSManagedObjectID</tt> value
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSSelect *_Nonnull CSSelectObjectID(void) CORESTORE_RETURNS_RETAINED;
@@ -484,19 +177,7 @@ CSSelect *_Nonnull CSSelectObjectID(void) CORESTORE_RETURNS_RETAINED;
@class CSTweak;
/**
@abstract
Initializes a <tt>CSTweak</tt> clause with a block where the <tt>NSFetchRequest</tt> may be configured.
@important
<tt>CSTweak</tt>'s closure is executed only just before the fetch occurs, so make sure that any values captured by the closure is not prone to race conditions. Also, some utilities (such as <tt>CSListMonitor</tt>s) may keep <tt>CSFetchClause</tt>s in memory and may thus introduce retain cycles if reference captures are not handled properly.
@param block
the block to customize the <tt>NSFetchRequest</tt>
@result
a <tt>CSTweak</tt> clause with the <tt>NSFetchRequest</tt> configuration block
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN CORESTORE_OVERLOADABLE
CSTweak *_Nonnull CSTweakRequest(void (^_Nonnull block)(NSFetchRequest *_Nonnull fetchRequest)) CORESTORE_RETURNS_RETAINED;
@@ -505,61 +186,15 @@ CSTweak *_Nonnull CSTweakRequest(void (^_Nonnull block)(NSFetchRequest *_Nonnull
@class CSWhere;
/**
@abstract
Initializes a <tt>CSWhere</tt> clause with a predicate that always evaluates to the specified boolean value
@code
MyPersonEntity *people = [transaction
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSWhereValue(YES)]];
@endcode
@param value
the boolean value for the predicate
@result
a <tt>CSWhere</tt> clause with a predicate that always evaluates to the specified boolean value
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSWhere *_Nonnull CSWhereValue(BOOL value) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSWhere</tt> clause with a predicate using the specified string format and arguments
@code
MyPersonEntity *people = [transaction
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSWhereFormat(@"%K == %@", @"key", @"value")]];
@endcode
@param format
the format string for the predicate, followed by an optional comma-separated argument list
@result
a <tt>CSWhere</tt> clause with a predicate using the specified string format and arguments
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSWhere *_Nonnull CSWhereFormat(NSString *_Nonnull format, ...) CORESTORE_RETURNS_RETAINED;
/**
@abstract
Initializes a <tt>CSWhere</tt> clause with an <tt>NSPredicate</tt>
@code
NSPredicate *predicate = // ...
MyPersonEntity *people = [transaction
fetchAllFrom:CSFromClass([MyPersonEntity class])
fetchClauses:@[CSWherePredicate(predicate)]];
@endcode
@param predicate
the <tt>NSPredicate</tt> for the fetch or query
@result
a <tt>CSWhere</tt> clause with an <tt>NSPredicate</tt>
*/
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_EXTERN
CSWhere *_Nonnull CSWherePredicate(NSPredicate *_Nonnull predicate) CORESTORE_RETURNS_RETAINED;

View File

@@ -33,81 +33,79 @@
#pragma mark CSFrom
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass) CORESTORE_RETURNS_RETAINED {
return [[CSFrom alloc] initWithEntityClass:entityClass];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass, NSNull *_Nonnull configuration) CORESTORE_RETURNS_RETAINED {
return [[CSFrom alloc] initWithEntityClass:entityClass configuration:configuration];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass, NSString *_Nonnull configuration) CORESTORE_RETURNS_RETAINED {
return [[CSFrom alloc] initWithEntityClass:entityClass configuration:configuration];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass, NSArray<id> *_Nonnull configurations) CORESTORE_RETURNS_RETAINED {
return [[CSFrom alloc] initWithEntityClass:entityClass configurations:configurations];
abort();
}
#pragma mark CSGroupBy
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSGroupBy *_Nonnull CSGroupByKeyPath(NSString *_Nonnull keyPath) CORESTORE_RETURNS_RETAINED {
return [[CSGroupBy alloc] initWithKeyPath:keyPath];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSGroupBy *_Nonnull CSGroupByKeyPaths(NSString *_Nonnull keyPath, ...) CORESTORE_RETURNS_RETAINED {
va_list args;
va_start(args, keyPath);
NSMutableArray *keyPaths = [NSMutableArray new];
[keyPaths addObject:keyPath];
NSString *next;
while ((next = va_arg(args, NSString *)) != nil) {
[keyPaths addObject:next];
}
va_end(args);
return [[CSGroupBy alloc] initWithKeyPaths:keyPaths];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSGroupBy *_Nonnull CSGroupByKeyPaths(NSArray<NSString *> *_Nonnull keyPaths) CORESTORE_RETURNS_RETAINED {
return [[CSGroupBy alloc] initWithKeyPaths:keyPaths];
abort();
}
#pragma mark CSInto
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass) CORESTORE_RETURNS_RETAINED {
return [[CSInto alloc] initWithEntityClass:entityClass];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass, NSNull *_Nonnull configuration) CORESTORE_RETURNS_RETAINED {
return [[CSInto alloc] initWithEntityClass:entityClass configuration:nil];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass, NSString *_Nonnull configuration) CORESTORE_RETURNS_RETAINED {
return [[CSInto alloc] initWithEntityClass:entityClass configuration:configuration];
abort();
}
@@ -115,106 +113,104 @@ CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass, NSString *_Nonnull conf
@class CSOrderBy;
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
NSSortDescriptor *_Nonnull CSSortAscending(NSString *_Nonnull key) {
return [[NSSortDescriptor alloc] initWithKey:key ascending:YES];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
NSSortDescriptor *_Nonnull CSSortDescending(NSString *_Nonnull key) {
return [[NSSortDescriptor alloc] initWithKey:key ascending:NO];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSOrderBy *_Nonnull CSOrderByKey(NSSortDescriptor *_Nonnull sortDescriptor) CORESTORE_RETURNS_RETAINED {
return [[CSOrderBy alloc] initWithSortDescriptor:sortDescriptor];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSOrderBy *_Nonnull CSOrderByKeys(NSSortDescriptor *_Nonnull sortDescriptor, ...) CORESTORE_RETURNS_RETAINED {
va_list args;
va_start(args, sortDescriptor);
NSMutableArray *sortDescriptors = [NSMutableArray new];
[sortDescriptors addObject:sortDescriptor];
NSSortDescriptor *next;
while ((next = va_arg(args, NSSortDescriptor *)) != nil) {
[sortDescriptors addObject:next];
}
va_end(args);
return [[CSOrderBy alloc] initWithSortDescriptors:sortDescriptors];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSOrderBy *_Nonnull CSOrderByKeys(NSArray<NSSortDescriptor *> *_Nonnull sortDescriptors) CORESTORE_RETURNS_RETAINED {
return [[CSOrderBy alloc] initWithSortDescriptors:sortDescriptors];
abort();
}
#pragma mark CSSelect
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSSelect *_Nonnull CSSelectNumber(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED {
return [[CSSelect alloc] initWithNumberTerm:selectTerm];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSSelect *_Nonnull CSSelectDecimal(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED {
return [[CSSelect alloc] initWithDecimalTerm:selectTerm];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSSelect *_Nonnull CSSelectString(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED {
return [[CSSelect alloc] initWithStringTerm:selectTerm];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSSelect *_Nonnull CSSelectDate(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED {
return [[CSSelect alloc] initWithDateTerm:selectTerm];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSSelect *_Nonnull CSSelectData(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED {
return [[CSSelect alloc] initWithDataTerm:selectTerm];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSSelect *_Nonnull CSSelectObjectID() CORESTORE_RETURNS_RETAINED {
return [[CSSelect alloc] initWithObjectIDTerm];
abort();
}
#pragma mark CSTweak
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CORESTORE_OVERLOADABLE
CSTweak *_Nonnull CSTweakRequest(void (^_Nonnull block)(NSFetchRequest *_Nonnull fetchRequest)) CORESTORE_RETURNS_RETAINED {
return [[CSTweak alloc] initWithBlock:block];
abort();
}
#pragma mark CSWhere
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSWhere *_Nonnull CSWhereValue(BOOL value) CORESTORE_RETURNS_RETAINED {
return [[CSWhere alloc] initWithValue:value];
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSWhere *_Nonnull CSWhereFormat(NSString *_Nonnull format, ...) CORESTORE_RETURNS_RETAINED {
CSWhere *where;
va_list args;
va_start(args, format);
where = [[CSWhere alloc] initWithPredicate:[NSPredicate predicateWithFormat:format arguments:args]];
va_end(args);
return where;
abort();
}
NS_UNAVAILABLE // CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.
CSWhere *_Nonnull CSWherePredicate(NSPredicate *_Nonnull predicate) CORESTORE_RETURNS_RETAINED {
return [[CSWhere alloc] initWithPredicate:predicate];
abort();
}

View File

@@ -28,157 +28,23 @@ import Foundation
// MARK: - CoreStoreObjectiveCType
/**
`CoreStoreObjectiveCType`s are Objective-C accessible classes that represent CoreStore's Swift types.
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
public protocol CoreStoreObjectiveCType: AnyObject {
/**
The corresponding Swift type
*/
associatedtype SwiftType
/**
The bridged Swift instance
*/
var bridgeToSwift: SwiftType { get }
/**
Initializes this instance with the Swift instance to bridge from
*/
init(_ swiftValue: SwiftType)
}
// MARK: - CoreStoreSwiftType
/**
`CoreStoreSwiftType`s are CoreStore's Swift types that are bridgeable to Objective-C.
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
public protocol CoreStoreSwiftType {
/**
The corresponding Objective-C type
*/
associatedtype ObjectiveCType
/**
The bridged Objective-C instance
*/
var bridgeToObjectiveC: ObjectiveCType { get }
}
// MARK: - Internal
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> T) -> T.ObjectiveCType {
return closure().bridgeToObjectiveC
}
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> [T]) -> [T.ObjectiveCType] {
return closure().map { $0.bridgeToObjectiveC }
}
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> T?) -> T.ObjectiveCType? {
return closure()?.bridgeToObjectiveC
}
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
internal func bridge<T: CoreStoreSwiftType>(_ closure: () throws -> T) throws -> T.ObjectiveCType {
do {
return try closure().bridgeToObjectiveC
}
catch {
throw error.bridgeToObjectiveC
}
}
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
internal func bridge(_ closure: () throws -> Void) throws {
do {
try closure()
}
catch {
throw error.bridgeToObjectiveC
}
}
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
internal func bridge<T: CoreStoreSwiftType>(_ error: NSErrorPointer, _ closure: () throws -> T) -> T.ObjectiveCType? {
do {
let result = try closure()
error?.pointee = nil
return result.bridgeToObjectiveC
}
catch let swiftError {
error?.pointee = swiftError.bridgeToObjectiveC
return nil
}
}
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> Void) -> Bool {
do {
try closure()
error?.pointee = nil
return true
}
catch let swiftError {
error?.pointee = swiftError.bridgeToObjectiveC
return false
}
}
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
internal func bridge<T>(_ error: NSErrorPointer, _ closure: () throws -> T?) -> T? {
do {
let result = try closure()
error?.pointee = nil
return result
}
catch let swiftError {
error?.pointee = swiftError.bridgeToObjectiveC
return nil
}
}
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
internal func bridge<T: CoreStoreSwiftType>(_ error: NSErrorPointer, _ closure: () throws -> [T]) -> [T.ObjectiveCType]? {
do {
let result = try closure()
error?.pointee = nil
return result.map { $0.bridgeToObjectiveC }
}
catch let swiftError {
error?.pointee = swiftError.bridgeToObjectiveC
return nil
}
}

View File

@@ -258,8 +258,23 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
// MARK: Internal
internal init(_ error: Error?) {
self = error.flatMap({ $0.bridgeToSwift }) ?? .unknown
guard let error = error else {
self = .unknown
return
}
switch error {
case let error as CoreStoreError:
self = error
case let error as NSError:
self = .internalError(NSError: error)
default:
self = .unknown
}
}
}

View File

@@ -216,7 +216,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
*/
public subscript(attribute: KeyPathString) -> Any? {
return self.rawObject.cs_accessValueForKVCKey(attribute)
return self.rawObject.getValue(forKvcKey: attribute)
}
/**
@@ -224,7 +224,7 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
*/
public subscript(attribute: NSAttributeDescription) -> Any? {
return self.rawObject.cs_accessValueForKVCKey(attribute.name)
return self.rawObject.getValue(forKvcKey: attribute.name)
}
/**
@@ -273,8 +273,8 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
*/
public subscript(attribute: KeyPathString) -> Any? {
get { return self.rawObject.cs_accessValueForKVCKey(attribute) }
set { self.rawObject.cs_setValue(newValue, forKVCKey: attribute) }
get { return self.rawObject.getValue(forKvcKey: attribute) }
set { self.rawObject.setValue(newValue, forKvcKey: attribute) }
}
/**
@@ -282,8 +282,8 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
*/
public subscript(attribute: NSAttributeDescription) -> Any? {
get { return self.rawObject.cs_accessValueForKVCKey(attribute.name) }
set { self.rawObject.cs_setValue(newValue, forKVCKey: attribute.name) }
get { return self.rawObject.getValue(forKvcKey: attribute.name) }
set { self.rawObject.setValue(newValue, forKvcKey: attribute.name) }
}
/**

View File

@@ -199,7 +199,7 @@ extension DataStack {
)
if let progress = progress {
progress.cs_setProgressHandler { [weak self] progress in
progress.setProgressHandler { [weak self] progress in
guard
let self = self,

View File

@@ -29,47 +29,30 @@ import CoreData
// MARK: - NSManagedObject
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension NSManagedObject {
/**
Provides a convenience wrapper for accessing `-primitiveValueForKey:` with proper calls to `-willAccessValueForKey:` and `-didAccessValueForKey:`. This is useful when implementing accessor methods for transient attributes.
- parameter KVCKey: the KVC key
- returns: the primitive value for the KVC key
*/
@objc
public func cs_accessValueForKVCKey(_ KVCKey: KeyPathString) -> Any? {
return self.getValue(forKvcKey: KVCKey)
fatalError()
}
/**
Provides a convenience wrapper for setting `-setPrimitiveValue:` with proper calls to `-willChangeValueForKey:` and `-didChangeValueForKey:`. This is useful when implementing mutator methods for transient attributes.
- parameter value: the value to set the KVC key with
- parameter KVCKey: the KVC key
*/
@objc
public func cs_setValue(_ value: Any?, forKVCKey KVCKey: KeyPathString) {
self.setValue(value, forKvcKey: KVCKey)
fatalError()
}
/**
Re-faults the object to use the latest values from the persistent store
*/
@objc
public func cs_refreshAsFault() {
self.refreshAsFault()
fatalError()
}
/**
Re-faults the object to use the latest values from the persistent store and merges previously pending changes back
*/
@nonobjc
public func cs_refreshAndMerge() {
self.refreshAndMerge()
fatalError()
}
}

View File

@@ -1,142 +0,0 @@
//
// NSManagedObjectContext+ObjectiveC.swift
// CoreStore
//
// Copyright © 2018 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
import CoreData
// MARK: - NSManagedObjectContext
extension NSManagedObjectContext {
// MARK: Internal
@nonobjc
internal func fetchOne(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> NSManagedObject? {
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObject>()
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
fetchRequest.fetchLimit = 1
fetchRequest.resultType = .managedObjectResultType
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
return try self.fetchOne(fetchRequest)
}
@nonobjc
internal func fetchAll<T: NSManagedObject>(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> [T] {
let fetchRequest = Internals.CoreStoreFetchRequest<T>()
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
fetchRequest.fetchLimit = 0
fetchRequest.resultType = .managedObjectResultType
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
return try self.fetchAll(fetchRequest)
}
@nonobjc
internal func fetchCount(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> Int {
let fetchRequest = Internals.CoreStoreFetchRequest<NSNumber>()
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
fetchRequest.resultType = .countResultType
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
return try self.fetchCount(fetchRequest)
}
@nonobjc
internal func fetchObjectID(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> NSManagedObjectID? {
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObjectID>()
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
fetchRequest.fetchLimit = 1
fetchRequest.resultType = .managedObjectIDResultType
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
return try self.fetchObjectID(fetchRequest)
}
@nonobjc
internal func fetchObjectIDs(_ from: CSFrom, _ fetchClauses: [CSFetchClause]) throws -> [NSManagedObjectID] {
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObjectID>()
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
fetchRequest.fetchLimit = 0
fetchRequest.resultType = .managedObjectIDResultType
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
return try self.fetchObjectIDs(fetchRequest)
}
@nonobjc
internal func deleteAll(_ from: CSFrom, _ deleteClauses: [CSDeleteClause]) throws -> Int {
let fetchRequest = Internals.CoreStoreFetchRequest<NSManagedObject>()
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
fetchRequest.fetchLimit = 0
fetchRequest.resultType = .managedObjectResultType
fetchRequest.returnsObjectsAsFaults = true
fetchRequest.includesPropertyValues = false
deleteClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
return try self.deleteAll(fetchRequest)
}
@nonobjc
internal func queryValue(_ from: CSFrom, _ selectClause: CSSelect, _ queryClauses: [CSQueryClause]) throws -> Any? {
let fetchRequest = Internals.CoreStoreFetchRequest<NSDictionary>()
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
fetchRequest.fetchLimit = 0
selectClause.applyToFetchRequest(fetchRequest)
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
return try self.queryValue(selectClause.selectTerms, fetchRequest: fetchRequest)
}
@nonobjc
internal func queryAttributes(_ from: CSFrom, _ selectClause: CSSelect, _ queryClauses: [CSQueryClause]) throws -> [[String: Any]] {
let fetchRequest = Internals.CoreStoreFetchRequest<NSDictionary>()
try from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
fetchRequest.fetchLimit = 0
selectClause.applyToFetchRequest(fetchRequest)
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
return try self.queryAttributes(fetchRequest)
}
}

View File

@@ -28,16 +28,12 @@ import Foundation
// MARK: - Progress
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension Progress {
/**
Sets a closure that the `NSProgress` calls whenever its `fractionCompleted` changes. You can use this instead of setting up KVO.
- parameter closure: the closure to execute on progress change
*/
@objc
dynamic public func cs_setProgressHandler(_ closure: ((_ progress: Progress) -> Void)?) {
self.setProgressHandler(closure)
fatalError()
}
}