mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-04-21 16:31:21 +02:00
comments cleanup
This commit is contained in:
@@ -31,9 +31,9 @@ import CoreData
|
|||||||
|
|
||||||
public extension NSFetchedResultsController {
|
public extension NSFetchedResultsController {
|
||||||
|
|
||||||
|
/**
|
||||||
// MARK: Public
|
Utility for creating an `NSFetchedResultsController` from a `DataStack`. This is useful to partially support Objective-C classes by passing an `NSFetchedResultsController` instance instead of a `ListMonitor`.
|
||||||
|
*/
|
||||||
public func createForStack<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController {
|
public func createForStack<T: NSManagedObject>(dataStack: DataStack, fetchRequest: NSFetchRequest, from: From<T>? = nil, sectionBy: SectionBy? = nil, fetchClauses: [FetchClause]) -> NSFetchedResultsController {
|
||||||
|
|
||||||
return CoreStoreFetchedResultsController<T>(
|
return CoreStoreFetchedResultsController<T>(
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ import Foundation
|
|||||||
|
|
||||||
public extension NSProgress {
|
public extension NSProgress {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sets a closure that the `NSProgress` calls whenever its `fractionCompleted` changes. You can use this instead of setting up KVO.
|
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
|
- parameter closure: the closure to execute on progress change
|
||||||
|
|||||||
@@ -28,4 +28,3 @@
|
|||||||
|
|
||||||
FOUNDATION_EXPORT double CoreStoreVersionNumber;
|
FOUNDATION_EXPORT double CoreStoreVersionNumber;
|
||||||
FOUNDATION_EXPORT const unsigned char CoreStoreVersionString[];
|
FOUNDATION_EXPORT const unsigned char CoreStoreVersionString[];
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ import CoreData
|
|||||||
*/
|
*/
|
||||||
public enum CoreStore {
|
public enum CoreStore {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The default `DataStack` instance to be used. If `defaultStack` is not set before the first time accessed, a default-configured `DataStack` will be created.
|
The default `DataStack` instance to be used. If `defaultStack` is not set before the first time accessed, a default-configured `DataStack` will be created.
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ import CoreData
|
|||||||
|
|
||||||
public extension BaseDataTransaction {
|
public extension BaseDataTransaction {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObject` instance in the transaction's context from a reference created from a transaction or from a different managed object context.
|
Fetches the `NSManagedObject` instance in the transaction's context from a reference created from a transaction or from a different managed object context.
|
||||||
|
|
||||||
|
|||||||
@@ -30,38 +30,77 @@ import CoreData
|
|||||||
// MARK: - From
|
// MARK: - From
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A `Form` clause binds the `NSManagedObject` entity type to the generics type system.
|
A `From` clause specifies the source entity and source persistent store for fetch and query methods. A common usage is to just indicate the entity:
|
||||||
|
```
|
||||||
|
let person = transaction.fetchOne(From(MyPersonEntity))
|
||||||
|
```
|
||||||
|
For cases where multiple `NSPersistentStore`s contain the same entity, the source configuration's name needs to be specified as well:
|
||||||
|
```
|
||||||
|
let person = transaction.fetchOne(From<MyPersonEntity>("Configuration1"))
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
public struct From<T: NSManagedObject> {
|
public struct From<T: NSManagedObject> {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes a `From` clause with the specified entity type and configuration.
|
Initializes a `From` clause.
|
||||||
Sample Usage:
|
Sample Usage:
|
||||||
|
```
|
||||||
let person = transaction.fetchOne(From<MyPersonEntity>())
|
let people = transaction.fetchAll(From<MyPersonEntity>())
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
public init(){
|
public init(){
|
||||||
|
|
||||||
self.init(entityClass: T.self)
|
self.init(entityClass: T.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initializes a `From` clause with the specified entity type.
|
||||||
|
Sample Usage:
|
||||||
|
```
|
||||||
|
let people = transaction.fetchAll(From<MyPersonEntity>())
|
||||||
|
```
|
||||||
|
- parameter entity: the `NSManagedObject` type to be created
|
||||||
|
*/
|
||||||
public init(_ entity: T.Type) {
|
public init(_ entity: T.Type) {
|
||||||
|
|
||||||
self.init(entityClass: entity)
|
self.init(entityClass: entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initializes a `From` clause with the specified entity class.
|
||||||
|
Sample Usage:
|
||||||
|
```
|
||||||
|
let people = transaction.fetchAll(From<MyPersonEntity>())
|
||||||
|
```
|
||||||
|
- parameter entityClass: the `NSManagedObject` class type to be created
|
||||||
|
*/
|
||||||
public init(_ entityClass: AnyClass) {
|
public init(_ entityClass: AnyClass) {
|
||||||
|
|
||||||
self.init(entityClass: entityClass)
|
self.init(entityClass: entityClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initializes a `From` clause with the specified configurations.
|
||||||
|
Sample Usage:
|
||||||
|
```
|
||||||
|
let people = transaction.fetchAll(From<MyPersonEntity>(nil, "Configuration1"))
|
||||||
|
```
|
||||||
|
- 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 `nil` to use the default configuration.
|
||||||
|
- parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter)
|
||||||
|
*/
|
||||||
public init(_ configuration: String?, otherConfigurations: String?...) {
|
public init(_ configuration: String?, otherConfigurations: String?...) {
|
||||||
|
|
||||||
self.init(entityClass: T.self, configurations: [configuration] + otherConfigurations)
|
self.init(entityClass: T.self, configurations: [configuration] + otherConfigurations)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initializes a `From` clause with the specified configurations.
|
||||||
|
Sample Usage:
|
||||||
|
```
|
||||||
|
let people = transaction.fetchAll(From<MyPersonEntity>(["Configuration1", "Configuration2"]))
|
||||||
|
```
|
||||||
|
- parameter configurations: a list of `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
|
||||||
|
*/
|
||||||
public init(_ configurations: [String?]) {
|
public init(_ configurations: [String?]) {
|
||||||
|
|
||||||
self.init(entityClass: T.self, configurations: configurations)
|
self.init(entityClass: T.self, configurations: configurations)
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ The `GroupBy` clause specifies that the result of a query be grouped accoording
|
|||||||
*/
|
*/
|
||||||
public struct GroupBy: QueryClause {
|
public struct GroupBy: QueryClause {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes a `GroupBy` clause with a list of key path strings
|
Initializes a `GroupBy` clause with a list of key path strings
|
||||||
|
|
||||||
@@ -72,7 +70,7 @@ public struct GroupBy: QueryClause {
|
|||||||
|
|
||||||
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
||||||
|
|
||||||
if fetchRequest.propertiesToGroupBy != nil {
|
if let keyPaths = fetchRequest.propertiesToGroupBy as? [String] where keyPaths != self.keyPaths {
|
||||||
|
|
||||||
CoreStore.log(
|
CoreStore.log(
|
||||||
.Warning,
|
.Warning,
|
||||||
|
|||||||
@@ -69,8 +69,6 @@ The `OrderBy` clause specifies the sort order for results for a fetch or a query
|
|||||||
*/
|
*/
|
||||||
public struct OrderBy: FetchClause, QueryClause, DeleteClause {
|
public struct OrderBy: FetchClause, QueryClause, DeleteClause {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes a `OrderBy` clause with a list of sort descriptors
|
Initializes a `OrderBy` clause with a list of sort descriptors
|
||||||
|
|
||||||
@@ -139,7 +137,7 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause {
|
|||||||
|
|
||||||
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
||||||
|
|
||||||
if fetchRequest.sortDescriptors != nil {
|
if let sortDescriptors = fetchRequest.sortDescriptors where sortDescriptors != self.sortDescriptors {
|
||||||
|
|
||||||
CoreStore.log(
|
CoreStore.log(
|
||||||
.Warning,
|
.Warning,
|
||||||
|
|||||||
@@ -64,25 +64,23 @@ The `SelectTerm` is passed to the `Select` clause to indicate the attributes/agg
|
|||||||
*/
|
*/
|
||||||
public enum SelectTerm: StringLiteralConvertible {
|
public enum SelectTerm: StringLiteralConvertible {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute. A shorter way to do the same is to assign from the string keypath directly:
|
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute. A shorter way to do the same is to assign from the string keypath directly:
|
||||||
|
```
|
||||||
let fullName = CoreStore.queryValue(
|
let fullName = CoreStore.queryValue(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Select<String>(.Attribute("fullName")),
|
Select<String>(.Attribute("fullName")),
|
||||||
Where("employeeID", isEqualTo: 1111)
|
Where("employeeID", isEqualTo: 1111)
|
||||||
)
|
)
|
||||||
|
```
|
||||||
is equivalent to:
|
is equivalent to:
|
||||||
|
```
|
||||||
let fullName = CoreStore.queryValue(
|
let fullName = CoreStore.queryValue(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Select<String>("fullName"),
|
Select<String>("fullName"),
|
||||||
Where("employeeID", isEqualTo: 1111)
|
Where("employeeID", isEqualTo: 1111)
|
||||||
)
|
)
|
||||||
|
```
|
||||||
- parameter keyPath: the attribute name
|
- parameter keyPath: the attribute name
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
||||||
*/
|
*/
|
||||||
@@ -93,12 +91,12 @@ public enum SelectTerm: StringLiteralConvertible {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Provides a `SelectTerm` to a `Select` clause for querying the average value of an attribute.
|
Provides a `SelectTerm` to a `Select` clause for querying the average value of an attribute.
|
||||||
|
```
|
||||||
let averageAge = CoreStore.queryValue(
|
let averageAge = CoreStore.queryValue(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Select<Int>(.Average("age"))
|
Select<Int>(.Average("age"))
|
||||||
)
|
)
|
||||||
|
```
|
||||||
- parameter keyPath: the attribute name
|
- 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 "average(<attributeName>)" is used
|
- 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 "average(<attributeName>)" is used
|
||||||
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
|
||||||
@@ -115,12 +113,12 @@ public enum SelectTerm: StringLiteralConvertible {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Provides a `SelectTerm` to a `Select` clause for a count query.
|
Provides a `SelectTerm` to a `Select` clause for a count query.
|
||||||
|
```
|
||||||
let numberOfEmployees = CoreStore.queryValue(
|
let numberOfEmployees = CoreStore.queryValue(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Select<Int>(.Count("employeeID"))
|
Select<Int>(.Count("employeeID"))
|
||||||
)
|
)
|
||||||
|
```
|
||||||
- parameter keyPath: the attribute name
|
- 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
|
- 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
|
- returns: a `SelectTerm` to a `Select` clause for a count query
|
||||||
@@ -137,12 +135,12 @@ public enum SelectTerm: StringLiteralConvertible {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Provides a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute.
|
Provides a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute.
|
||||||
|
```
|
||||||
let maximumAge = CoreStore.queryValue(
|
let maximumAge = CoreStore.queryValue(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Select<Int>(.Maximum("age"))
|
Select<Int>(.Maximum("age"))
|
||||||
)
|
)
|
||||||
|
```
|
||||||
- parameter keyPath: the attribute name
|
- 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
|
- 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 `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
|
||||||
@@ -159,12 +157,12 @@ public enum SelectTerm: StringLiteralConvertible {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Provides a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute.
|
Provides a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute.
|
||||||
|
```
|
||||||
let minimumAge = CoreStore.queryValue(
|
let minimumAge = CoreStore.queryValue(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Select<Int>(.Minimum("age"))
|
Select<Int>(.Minimum("age"))
|
||||||
)
|
)
|
||||||
|
```
|
||||||
- parameter keyPath: the attribute name
|
- 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
|
- 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 `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
|
||||||
@@ -181,12 +179,12 @@ public enum SelectTerm: StringLiteralConvertible {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Provides a `SelectTerm` to a `Select` clause for querying the sum value for an attribute.
|
Provides a `SelectTerm` to a `Select` clause for querying the sum value for an attribute.
|
||||||
|
```
|
||||||
let totalAge = CoreStore.queryValue(
|
let totalAge = CoreStore.queryValue(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Select<Int>(.Sum("age"))
|
Select<Int>(.Sum("age"))
|
||||||
)
|
)
|
||||||
|
```
|
||||||
- parameter keyPath: the attribute name
|
- 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
|
- 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 `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||||
@@ -233,19 +231,19 @@ public enum SelectTerm: StringLiteralConvertible {
|
|||||||
The `Select` clause indicates the attribute / aggregate value to be queried. The generic type is a `SelectResultType`, and will be used as the return type for the query.
|
The `Select` clause indicates the attribute / aggregate value to be queried. The generic type is a `SelectResultType`, and will be used as the return type for the query.
|
||||||
|
|
||||||
You can bind the return type by specializing the initializer:
|
You can bind the return type by specializing the initializer:
|
||||||
|
```
|
||||||
let maximumAge = CoreStore.queryValue(
|
let maximumAge = CoreStore.queryValue(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Select<Int>(.Maximum("age"))
|
Select<Int>(.Maximum("age"))
|
||||||
)
|
)
|
||||||
|
```
|
||||||
or by casting the type of the return value:
|
or by casting the type of the return value:
|
||||||
|
```
|
||||||
let maximumAge: Int = CoreStore.queryValue(
|
let maximumAge: Int = CoreStore.queryValue(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Select(.Maximum("age"))
|
Select(.Maximum("age"))
|
||||||
)
|
)
|
||||||
|
```
|
||||||
Valid return types depend on the query:
|
Valid return types depend on the query:
|
||||||
|
|
||||||
- for `queryValue(...)` methods:
|
- for `queryValue(...)` methods:
|
||||||
@@ -271,8 +269,6 @@ Valid return types depend on the query:
|
|||||||
*/
|
*/
|
||||||
public struct Select<T: SelectResultType> {
|
public struct Select<T: SelectResultType> {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The `SelectResultType` type for the query's return value
|
The `SelectResultType` type for the query's return value
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -31,9 +31,8 @@ import CoreData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
The `Tweak` clause allows fine-tuning the `NSFetchRequest` for a fetch or query.
|
The `Tweak` clause allows fine-tuning the `NSFetchRequest` for a fetch or query.
|
||||||
|
|
||||||
Sample usage:
|
Sample usage:
|
||||||
|
```
|
||||||
let employees = transaction.fetchAll(
|
let employees = transaction.fetchAll(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Tweak { (fetchRequest) -> Void in
|
Tweak { (fetchRequest) -> Void in
|
||||||
@@ -41,11 +40,10 @@ Sample usage:
|
|||||||
fetchRequest.fetchLimit = 5
|
fetchRequest.fetchLimit = 5
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
public struct Tweak: FetchClause, QueryClause, DeleteClause {
|
public struct Tweak: FetchClause, QueryClause, DeleteClause {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes a `Tweak` clause with a closure where the `NSFetchRequest` may be configured.
|
Initializes a `Tweak` clause with a closure where the `NSFetchRequest` may be configured.
|
||||||
|
|
||||||
@@ -65,5 +63,7 @@ public struct Tweak: FetchClause, QueryClause, DeleteClause {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: Private
|
||||||
|
|
||||||
private let customization: (fetchRequest: NSFetchRequest) -> Void
|
private let customization: (fetchRequest: NSFetchRequest) -> Void
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,6 @@ The `Where` clause specifies the conditions for a fetch or a query.
|
|||||||
*/
|
*/
|
||||||
public struct Where: FetchClause, QueryClause, DeleteClause {
|
public struct Where: FetchClause, QueryClause, DeleteClause {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes a `Where` clause with an `NSPredicate`
|
Initializes a `Where` clause with an `NSPredicate`
|
||||||
|
|
||||||
@@ -144,7 +142,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause {
|
|||||||
|
|
||||||
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
||||||
|
|
||||||
if fetchRequest.predicate != nil {
|
if let predicate = fetchRequest.predicate where predicate != self.predicate {
|
||||||
|
|
||||||
CoreStore.log(
|
CoreStore.log(
|
||||||
.Warning,
|
.Warning,
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ import CoreData
|
|||||||
|
|
||||||
public extension CoreStore {
|
public extension CoreStore {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Using the `defaultStack`, fetches the `NSManagedObject` instance in the `DataStack`'s context from a reference created from a transaction or from a different managed object context.
|
Using the `defaultStack`, fetches the `NSManagedObject` instance in the `DataStack`'s context from a reference created from a transaction or from a different managed object context.
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ import CoreData
|
|||||||
|
|
||||||
public extension DataStack {
|
public extension DataStack {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetches the `NSManagedObject` instance in the `DataStack`'s context from a reference created from a transaction or from a different managed object context.
|
Fetches the `NSManagedObject` instance in the `DataStack`'s context from a reference created from a transaction or from a different managed object context.
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ import CoreData
|
|||||||
|
|
||||||
// MARK: - FetchClause
|
// MARK: - FetchClause
|
||||||
|
|
||||||
|
/**
|
||||||
|
The `FetchClause` implement clauses used to configure `NSFetchRequest`s.
|
||||||
|
*/
|
||||||
public protocol FetchClause {
|
public protocol FetchClause {
|
||||||
|
|
||||||
func applyToFetchRequest(fetchRequest: NSFetchRequest)
|
func applyToFetchRequest(fetchRequest: NSFetchRequest)
|
||||||
@@ -37,6 +40,9 @@ public protocol FetchClause {
|
|||||||
|
|
||||||
// MARK: - QueryClause
|
// MARK: - QueryClause
|
||||||
|
|
||||||
|
/**
|
||||||
|
The `QueryClause` implement clauses used to configure `NSFetchRequest`s.
|
||||||
|
*/
|
||||||
public protocol QueryClause {
|
public protocol QueryClause {
|
||||||
|
|
||||||
func applyToFetchRequest(fetchRequest: NSFetchRequest)
|
func applyToFetchRequest(fetchRequest: NSFetchRequest)
|
||||||
@@ -45,6 +51,9 @@ public protocol QueryClause {
|
|||||||
|
|
||||||
// MARK: - DeleteClause
|
// MARK: - DeleteClause
|
||||||
|
|
||||||
|
/**
|
||||||
|
The `DeleteClause` implement clauses used to configure `NSFetchRequest`s.
|
||||||
|
*/
|
||||||
public protocol DeleteClause {
|
public protocol DeleteClause {
|
||||||
|
|
||||||
func applyToFetchRequest(fetchRequest: NSFetchRequest)
|
func applyToFetchRequest(fetchRequest: NSFetchRequest)
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ import CoreData
|
|||||||
|
|
||||||
public extension BaseDataTransaction {
|
public extension BaseDataTransaction {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates an `ImportableObject` by importing from the specified import source.
|
Creates an `ImportableObject` by importing from the specified import source.
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import CoreData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
`NSManagedObject` subclasses that conform to the `ImportableObject` protocol can be imported from a specified `ImportSource`. This allows transactions to create and insert instances this way:
|
`NSManagedObject` subclasses that conform to the `ImportableObject` protocol can be imported from a specified `ImportSource`. This allows transactions to create and insert instances this way:
|
||||||
|
```
|
||||||
class MyPersonEntity: NSManagedObject, ImportableObject {
|
class MyPersonEntity: NSManagedObject, ImportableObject {
|
||||||
typealias ImportSource = NSDictionary
|
typealias ImportSource = NSDictionary
|
||||||
// ...
|
// ...
|
||||||
@@ -46,6 +46,7 @@ import CoreData
|
|||||||
// ...
|
// ...
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
}
|
}
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
public protocol ImportableObject: class {
|
public protocol ImportableObject: class {
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import CoreData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
`NSManagedObject` subclasses that conform to the `ImportableUniqueObject` protocol can be imported from a specified `ImportSource`. This allows transactions to either update existing objects or create new instances this way:
|
`NSManagedObject` subclasses that conform to the `ImportableUniqueObject` protocol can be imported from a specified `ImportSource`. This allows transactions to either update existing objects or create new instances this way:
|
||||||
|
```
|
||||||
class MyPersonEntity: NSManagedObject, ImportableUniqueObject {
|
class MyPersonEntity: NSManagedObject, ImportableUniqueObject {
|
||||||
typealias ImportSource = NSDictionary
|
typealias ImportSource = NSDictionary
|
||||||
typealias UniqueIDType = NSString
|
typealias UniqueIDType = NSString
|
||||||
@@ -47,6 +47,7 @@ import CoreData
|
|||||||
// ...
|
// ...
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
}
|
}
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
public protocol ImportableUniqueObject: ImportableObject {
|
public protocol ImportableUniqueObject: ImportableObject {
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ import Foundation
|
|||||||
|
|
||||||
public extension CoreStore {
|
public extension CoreStore {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The `CoreStoreLogger` instance to be used. The default logger is an instance of a `DefaultLogger`.
|
The `CoreStoreLogger` instance to be used. The default logger is an instance of a `DefaultLogger`.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -101,6 +101,5 @@ internal func typeName(value: AnyClass) -> String {
|
|||||||
|
|
||||||
internal func typeName(name: String?) -> String {
|
internal func typeName(name: String?) -> String {
|
||||||
|
|
||||||
let typeName = name ?? "unknown"
|
return "<\(name ?? "unknown")>"
|
||||||
return "<\(typeName)>"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,23 +33,23 @@ import CoreData
|
|||||||
A `MigrationChain` indicates the sequence of model versions to be used as the order for incremental migration. This is typically passed to the `DataStack` initializer and will be applied to all stores added to the `DataStack` with `addSQLiteStore(...)` and its variants.
|
A `MigrationChain` indicates the sequence of model versions to be used as the order for incremental migration. This is typically passed to the `DataStack` initializer and will be applied to all stores added to the `DataStack` with `addSQLiteStore(...)` and its variants.
|
||||||
|
|
||||||
Initializing with empty values (either `nil`, `[]`, or `[:]`) instructs the `DataStack` to use the .xcdatamodel's current version as the final version, and to disable incremental migrations:
|
Initializing with empty values (either `nil`, `[]`, or `[:]`) instructs the `DataStack` to use the .xcdatamodel's current version as the final version, and to disable incremental migrations:
|
||||||
|
```
|
||||||
let dataStack = DataStack(migrationChain: nil)
|
let dataStack = DataStack(migrationChain: nil)
|
||||||
|
```
|
||||||
This means that the mapping model will be computed from the store's version straight to the `DataStack`'s model version.
|
This means that the mapping model will be computed from the store's version straight to the `DataStack`'s model version.
|
||||||
To support incremental migrations, specify the linear order of versions:
|
To support incremental migrations, specify the linear order of versions:
|
||||||
|
```
|
||||||
let dataStack = DataStack(migrationChain:
|
let dataStack = DataStack(migrationChain:
|
||||||
["MyAppModel", "MyAppModelV2", "MyAppModelV3", "MyAppModelV4"])
|
["MyAppModel", "MyAppModelV2", "MyAppModelV3", "MyAppModelV4"])
|
||||||
|
```
|
||||||
or for more complex migration paths, a version tree that maps the key-values to the source-destination versions:
|
or for more complex migration paths, a version tree that maps the key-values to the source-destination versions:
|
||||||
|
```
|
||||||
let dataStack = DataStack(migrationChain: [
|
let dataStack = DataStack(migrationChain: [
|
||||||
"MyAppModel": "MyAppModelV3",
|
"MyAppModel": "MyAppModelV3",
|
||||||
"MyAppModelV2": "MyAppModelV4",
|
"MyAppModelV2": "MyAppModelV4",
|
||||||
"MyAppModelV3": "MyAppModelV4"
|
"MyAppModelV3": "MyAppModelV4"
|
||||||
])
|
])
|
||||||
|
```
|
||||||
This allows for different migration paths depending on the starting version. The example above resolves to the following paths:
|
This allows for different migration paths depending on the starting version. The example above resolves to the following paths:
|
||||||
- MyAppModel-MyAppModelV3-MyAppModelV4
|
- MyAppModel-MyAppModelV3-MyAppModelV4
|
||||||
- MyAppModelV2-MyAppModelV4
|
- MyAppModelV2-MyAppModelV4
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import Foundation
|
|||||||
/**
|
/**
|
||||||
The `MigrationResult` indicates the result of a migration.
|
The `MigrationResult` indicates the result of a migration.
|
||||||
The `MigrationResult` can be treated as a boolean:
|
The `MigrationResult` can be treated as a boolean:
|
||||||
|
```
|
||||||
CoreStore.upgradeSQLiteStoreIfNeeded { transaction in
|
CoreStore.upgradeSQLiteStoreIfNeeded { transaction in
|
||||||
// ...
|
// ...
|
||||||
let result = transaction.commit()
|
let result = transaction.commit()
|
||||||
@@ -42,9 +42,9 @@ The `MigrationResult` can be treated as a boolean:
|
|||||||
// failed
|
// failed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
```
|
||||||
or as an `enum`, where the resulting associated object can also be inspected:
|
or as an `enum`, where the resulting associated object can also be inspected:
|
||||||
|
```
|
||||||
CoreStore.beginAsynchronous { transaction in
|
CoreStore.beginAsynchronous { transaction in
|
||||||
// ...
|
// ...
|
||||||
let result = transaction.commit()
|
let result = transaction.commit()
|
||||||
@@ -59,8 +59,6 @@ or as an `enum`, where the resulting associated object can also be inspected:
|
|||||||
*/
|
*/
|
||||||
public enum MigrationResult {
|
public enum MigrationResult {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
`MigrationResult.Success` indicates either the migration succeeded, or there were no migrations needed. The associated value is an array of `MigrationType`s reflecting the migration steps completed.
|
`MigrationResult.Success` indicates either the migration succeeded, or there were no migrations needed. The associated value is an array of `MigrationType`s reflecting the migration steps completed.
|
||||||
*/
|
*/
|
||||||
@@ -103,6 +101,7 @@ extension MigrationResult: BooleanType {
|
|||||||
public var boolValue: Bool {
|
public var boolValue: Bool {
|
||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
|
|
||||||
case .Success: return true
|
case .Success: return true
|
||||||
case .Failure: return false
|
case .Failure: return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ The `MigrationType` specifies the type of migration required for a store.
|
|||||||
*/
|
*/
|
||||||
public enum MigrationType: BooleanType {
|
public enum MigrationType: BooleanType {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Indicates that the persistent store matches the latest model version and no migration is needed
|
Indicates that the persistent store matches the latest model version and no migration is needed
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -26,6 +26,9 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import CoreData
|
import CoreData
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: - CoreStoreError
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The `NSError` error domain for `CoreStore`.
|
The `NSError` error domain for `CoreStore`.
|
||||||
*/
|
*/
|
||||||
@@ -58,7 +61,7 @@ public enum CoreStoreErrorCode: Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - NSError+CoreStore
|
// MARK: - NSError
|
||||||
|
|
||||||
public extension NSError {
|
public extension NSError {
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ import CoreData
|
|||||||
@available(OSX, unavailable)
|
@available(OSX, unavailable)
|
||||||
public extension CoreStore {
|
public extension CoreStore {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Using the `defaultStack`, creates a `ObjectMonitor` for the specified `NSManagedObject`. Multiple `ObjectObserver`s may then register themselves to be notified when changes are made to the `NSManagedObject`.
|
Using the `defaultStack`, creates a `ObjectMonitor` for the specified `NSManagedObject`. Multiple `ObjectObserver`s may then register themselves to be notified when changes are made to the `NSManagedObject`.
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ import CoreData
|
|||||||
@available(OSX, unavailable)
|
@available(OSX, unavailable)
|
||||||
public extension DataStack {
|
public extension DataStack {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a `ObjectMonitor` for the specified `NSManagedObject`. Multiple `ObjectObserver`s may then register themselves to be notified when changes are made to the `NSManagedObject`.
|
Creates a `ObjectMonitor` for the specified `NSManagedObject`. Multiple `ObjectObserver`s may then register themselves to be notified when changes are made to the `NSManagedObject`.
|
||||||
|
|
||||||
|
|||||||
@@ -34,25 +34,25 @@ import CoreData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
The `ListMonitor` monitors changes to a list of `NSManagedObject` instances. Observers that implement the `ListObserver` protocol may then register themselves to the `ListMonitor`'s `addObserver(_:)` method:
|
The `ListMonitor` monitors changes to a list of `NSManagedObject` instances. Observers that implement the `ListObserver` protocol may then register themselves to the `ListMonitor`'s `addObserver(_:)` method:
|
||||||
|
```
|
||||||
let monitor = CoreStore.monitorList(
|
let monitor = CoreStore.monitorList(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
Where("title", isEqualTo: "Engineer"),
|
Where("title", isEqualTo: "Engineer"),
|
||||||
OrderBy(.Ascending("lastName"))
|
OrderBy(.Ascending("lastName"))
|
||||||
)
|
)
|
||||||
monitor.addObserver(self)
|
monitor.addObserver(self)
|
||||||
|
```
|
||||||
The `ListMonitor` instance needs to be held on (retained) for as long as the list needs to be observed.
|
The `ListMonitor` instance needs to be held on (retained) for as long as the list needs to be observed.
|
||||||
Observers registered via `addObserver(_:)` are not retained. `ListMonitor` only keeps a `weak` reference to all observers, thus keeping itself free from retain-cycles.
|
Observers registered via `addObserver(_:)` are not retained. `ListMonitor` only keeps a `weak` reference to all observers, thus keeping itself free from retain-cycles.
|
||||||
|
|
||||||
Lists created with `monitorList(...)` keep a single-section list of objects, where each object can be accessed by index:
|
Lists created with `monitorList(...)` keep a single-section list of objects, where each object can be accessed by index:
|
||||||
|
```
|
||||||
let firstPerson: MyPersonEntity = monitor[0]
|
let firstPerson: MyPersonEntity = monitor[0]
|
||||||
|
```
|
||||||
Accessing the list with an index above the valid range will throw an exception.
|
Accessing the list with an index above the valid range will throw an exception.
|
||||||
|
|
||||||
Creating a sectioned-list is also possible with the `monitorSectionedList(...)` method:
|
Creating a sectioned-list is also possible with the `monitorSectionedList(...)` method:
|
||||||
|
```
|
||||||
let monitor = CoreStore.monitorSectionedList(
|
let monitor = CoreStore.monitorSectionedList(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
SectionBy("age") { "Age \($0)" },
|
SectionBy("age") { "Age \($0)" },
|
||||||
@@ -60,13 +60,13 @@ Creating a sectioned-list is also possible with the `monitorSectionedList(...)`
|
|||||||
OrderBy(.Ascending("lastName"))
|
OrderBy(.Ascending("lastName"))
|
||||||
)
|
)
|
||||||
monitor.addObserver(self)
|
monitor.addObserver(self)
|
||||||
|
```
|
||||||
Objects from `ListMonitor`s created this way can be accessed either by an `NSIndexPath` or a tuple:
|
Objects from `ListMonitor`s created this way can be accessed either by an `NSIndexPath` or a tuple:
|
||||||
|
```
|
||||||
let indexPath = NSIndexPath(forItem: 3, inSection: 2)
|
let indexPath = NSIndexPath(forItem: 3, inSection: 2)
|
||||||
let person1 = monitor[indexPath]
|
let person1 = monitor[indexPath]
|
||||||
let person2 = monitor[2, 3]
|
let person2 = monitor[2, 3]
|
||||||
|
```
|
||||||
In the example above, both `person1` and `person2` will contain the object at section=2, index=3.
|
In the example above, both `person1` and `person2` will contain the object at section=2, index=3.
|
||||||
*/
|
*/
|
||||||
@available(OSX, unavailable)
|
@available(OSX, unavailable)
|
||||||
|
|||||||
@@ -31,12 +31,13 @@ import CoreData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Implement the `ListObserver` protocol to observe changes to a list of `NSManagedObject`s. `ListObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
|
Implement the `ListObserver` protocol to observe changes to a list of `NSManagedObject`s. `ListObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
|
||||||
|
```
|
||||||
let monitor = CoreStore.monitorList(
|
let monitor = CoreStore.monitorList(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
OrderBy(.Ascending("lastName"))
|
OrderBy(.Ascending("lastName"))
|
||||||
)
|
)
|
||||||
monitor.addObserver(self)
|
monitor.addObserver(self)
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
@available(OSX, unavailable)
|
@available(OSX, unavailable)
|
||||||
public protocol ListObserver: class {
|
public protocol ListObserver: class {
|
||||||
@@ -107,12 +108,13 @@ public extension ListObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Implement the `ListObjectObserver` protocol to observe detailed changes to a list's object. `ListObjectObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
|
Implement the `ListObjectObserver` protocol to observe detailed changes to a list's object. `ListObjectObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
|
||||||
|
```
|
||||||
let monitor = CoreStore.monitorList(
|
let monitor = CoreStore.monitorList(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
OrderBy(.Ascending("lastName"))
|
OrderBy(.Ascending("lastName"))
|
||||||
)
|
)
|
||||||
monitor.addObserver(self)
|
monitor.addObserver(self)
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
@available(OSX, unavailable)
|
@available(OSX, unavailable)
|
||||||
public protocol ListObjectObserver: ListObserver {
|
public protocol ListObjectObserver: ListObserver {
|
||||||
@@ -187,13 +189,14 @@ public extension ListObjectObserver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Implement the `ListSectionObserver` protocol to observe changes to a list's section info. `ListSectionObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
|
Implement the `ListSectionObserver` protocol to observe changes to a list's section info. `ListSectionObserver`s may register themselves to a `ListMonitor`'s `addObserver(_:)` method:
|
||||||
|
```
|
||||||
let monitor = CoreStore.monitorSectionedList(
|
let monitor = CoreStore.monitorSectionedList(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
SectionBy("age") { "Age \($0)" },
|
SectionBy("age") { "Age \($0)" },
|
||||||
OrderBy(.Ascending("lastName"))
|
OrderBy(.Ascending("lastName"))
|
||||||
)
|
)
|
||||||
monitor.addObserver(self)
|
monitor.addObserver(self)
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
@available(OSX, unavailable)
|
@available(OSX, unavailable)
|
||||||
public protocol ListSectionObserver: ListObjectObserver {
|
public protocol ListSectionObserver: ListObjectObserver {
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ import CoreData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
The `ObjectMonitor` monitors changes to a single `NSManagedObject` instance. Observers that implement the `ObjectObserver` protocol may then register themselves to the `ObjectMonitor`'s `addObserver(_:)` method:
|
The `ObjectMonitor` monitors changes to a single `NSManagedObject` instance. Observers that implement the `ObjectObserver` protocol may then register themselves to the `ObjectMonitor`'s `addObserver(_:)` method:
|
||||||
|
```
|
||||||
let monitor = CoreStore.monitorObject(object)
|
let monitor = CoreStore.monitorObject(object)
|
||||||
monitor.addObserver(self)
|
monitor.addObserver(self)
|
||||||
|
```
|
||||||
The created `ObjectMonitor` instance needs to be held on (retained) for as long as the object needs to be observed.
|
The created `ObjectMonitor` instance needs to be held on (retained) for as long as the object needs to be observed.
|
||||||
|
|
||||||
Observers registered via `addObserver(_:)` are not retained. `ObjectMonitor` only keeps a `weak` reference to all observers, thus keeping itself free from retain-cycles.
|
Observers registered via `addObserver(_:)` are not retained. `ObjectMonitor` only keeps a `weak` reference to all observers, thus keeping itself free from retain-cycles.
|
||||||
@@ -45,8 +45,6 @@ Observers registered via `addObserver(_:)` are not retained. `ObjectMonitor` onl
|
|||||||
@available(OSX, unavailable)
|
@available(OSX, unavailable)
|
||||||
public final class ObjectMonitor<T: NSManagedObject> {
|
public final class ObjectMonitor<T: NSManagedObject> {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the `NSManagedObject` instance being observed, or `nil` if the object was already deleted.
|
Returns the `NSManagedObject` instance being observed, or `nil` if the object was already deleted.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -31,9 +31,10 @@ import CoreData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Implement the `ObjectObserver` protocol to observe changes to a single `NSManagedObject` instance. `ObjectObserver`s may register themselves to a `ObjectMonitor`'s `addObserver(_:)` method:
|
Implement the `ObjectObserver` protocol to observe changes to a single `NSManagedObject` instance. `ObjectObserver`s may register themselves to a `ObjectMonitor`'s `addObserver(_:)` method:
|
||||||
|
```
|
||||||
let monitor = CoreStore.monitorObject(object)
|
let monitor = CoreStore.monitorObject(object)
|
||||||
monitor.addObserver(self)
|
monitor.addObserver(self)
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
@available(OSX, unavailable)
|
@available(OSX, unavailable)
|
||||||
public protocol ObjectObserver: class {
|
public protocol ObjectObserver: class {
|
||||||
|
|||||||
@@ -31,18 +31,17 @@ import CoreData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
The `SectionBy` clause indicates the key path to use to group the `ListMonitor` objects into sections. An optional closure can also be provided to transform the value into an appropriate section name:
|
The `SectionBy` clause indicates the key path to use to group the `ListMonitor` objects into sections. An optional closure can also be provided to transform the value into an appropriate section name:
|
||||||
|
```
|
||||||
let monitor = CoreStore.monitorSectionedList(
|
let monitor = CoreStore.monitorSectionedList(
|
||||||
From(MyPersonEntity),
|
From(MyPersonEntity),
|
||||||
SectionBy("age") { "Age \($0)" },
|
SectionBy("age") { "Age \($0)" },
|
||||||
OrderBy(.Ascending("lastName"))
|
OrderBy(.Ascending("lastName"))
|
||||||
)
|
)
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
@available(OSX, unavailable)
|
@available(OSX, unavailable)
|
||||||
public struct SectionBy {
|
public struct SectionBy {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes a `SectionBy` clause with the key path to use to group `ListMonitor` objects into sections
|
Initializes a `SectionBy` clause with the key path to use to group `ListMonitor` objects into sections
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,6 @@ import CoreData
|
|||||||
@available(OSX, unavailable)
|
@available(OSX, unavailable)
|
||||||
public extension UnsafeDataTransaction {
|
public extension UnsafeDataTransaction {
|
||||||
|
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a `ObjectMonitor` for the specified `NSManagedObject`. Multiple `ObjectObserver`s may then register themselves to be notified when changes are made to the `NSManagedObject`.
|
Creates a `ObjectMonitor` for the specified `NSManagedObject`. Multiple `ObjectObserver`s may then register themselves to be notified when changes are made to the `NSManagedObject`.
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ The `AsynchronousDataTransaction` provides an interface for `NSManagedObject` cr
|
|||||||
*/
|
*/
|
||||||
public final class AsynchronousDataTransaction: BaseDataTransaction {
|
public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Saves the transaction changes. This method should not be used after the `commit()` method was already called once.
|
Saves the transaction changes. This method should not be used after the `commit()` method was already called once.
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ import Foundation
|
|||||||
|
|
||||||
public extension CoreStore {
|
public extension CoreStore {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Using the `defaultStack`, begins a transaction asynchronously where `NSManagedObject` creates, updates, and deletes can be made.
|
Using the `defaultStack`, begins a transaction asynchronously where `NSManagedObject` creates, updates, and deletes can be made.
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ import CoreData
|
|||||||
|
|
||||||
public extension DataStack {
|
public extension DataStack {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Begins a transaction asynchronously where `NSManagedObject` creates, updates, and deletes can be made.
|
Begins a transaction asynchronously where `NSManagedObject` creates, updates, and deletes can be made.
|
||||||
|
|
||||||
|
|||||||
@@ -30,25 +30,23 @@ import CoreData
|
|||||||
// MARK: - Into
|
// MARK: - Into
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A `Into` clause contains the destination entity and destination persistent store for a `create(...)` method. A common usage is to just indicate the entity:
|
An `Into` clause contains the destination entity and destination persistent store for a `create(...)` method. A common usage is to just indicate the entity:
|
||||||
|
```
|
||||||
let person = transaction.create(Into(MyPersonEntity))
|
let person = transaction.create(Into(MyPersonEntity))
|
||||||
|
```
|
||||||
For cases where multiple `NSPersistentStore`s contain the same entity, the destination configuration's name needs to be specified as well:
|
For cases where multiple `NSPersistentStore`s contain the same entity, the destination configuration's name needs to be specified as well:
|
||||||
|
```
|
||||||
let person = transaction.create(Into<MyPersonEntity>("Configuration1"))
|
let person = transaction.create(Into<MyPersonEntity>("Configuration1"))
|
||||||
|
```
|
||||||
This helps the `NSManagedObjectContext` to determine which
|
|
||||||
*/
|
*/
|
||||||
public struct Into<T: NSManagedObject> {
|
public struct Into<T: NSManagedObject> {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes an `Into` clause.
|
Initializes an `Into` clause.
|
||||||
Sample Usage:
|
Sample Usage:
|
||||||
|
```
|
||||||
let person = transaction.create(Into<MyPersonEntity>())
|
let person = transaction.create(Into<MyPersonEntity>())
|
||||||
|
```
|
||||||
*/
|
*/
|
||||||
public init(){
|
public init(){
|
||||||
|
|
||||||
@@ -60,9 +58,9 @@ public struct Into<T: NSManagedObject> {
|
|||||||
/**
|
/**
|
||||||
Initializes an `Into` clause with the specified entity type.
|
Initializes an `Into` clause with the specified entity type.
|
||||||
Sample Usage:
|
Sample Usage:
|
||||||
|
```
|
||||||
let person = transaction.create(Into(MyPersonEntity))
|
let person = transaction.create(Into(MyPersonEntity))
|
||||||
|
```
|
||||||
- parameter entity: the `NSManagedObject` type to be created
|
- parameter entity: the `NSManagedObject` type to be created
|
||||||
*/
|
*/
|
||||||
public init(_ entity: T.Type) {
|
public init(_ entity: T.Type) {
|
||||||
@@ -74,7 +72,10 @@ public struct Into<T: NSManagedObject> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes an `Into` clause with the specified entity class.
|
Initializes an `Into` clause with the specified entity class.
|
||||||
|
Sample Usage:
|
||||||
|
```
|
||||||
|
let person = transaction.create(Into(MyPersonEntity))
|
||||||
|
```
|
||||||
- parameter entityClass: the `NSManagedObject` class type to be created
|
- parameter entityClass: the `NSManagedObject` class type to be created
|
||||||
*/
|
*/
|
||||||
public init(_ entityClass: AnyClass) {
|
public init(_ entityClass: AnyClass) {
|
||||||
@@ -87,9 +88,9 @@ public struct Into<T: NSManagedObject> {
|
|||||||
/**
|
/**
|
||||||
Initializes an `Into` clause with the specified configuration.
|
Initializes an `Into` clause with the specified configuration.
|
||||||
Sample Usage:
|
Sample Usage:
|
||||||
|
```
|
||||||
let person = transaction.create(Into<MyPersonEntity>("Configuration1"))
|
let person = transaction.create(Into<MyPersonEntity>("Configuration1"))
|
||||||
|
```
|
||||||
- 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.
|
- 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.
|
||||||
*/
|
*/
|
||||||
public init(_ configuration: String?) {
|
public init(_ configuration: String?) {
|
||||||
@@ -102,9 +103,9 @@ public struct Into<T: NSManagedObject> {
|
|||||||
/**
|
/**
|
||||||
Initializes an `Into` clause with the specified entity type and configuration.
|
Initializes an `Into` clause with the specified entity type and configuration.
|
||||||
Sample Usage:
|
Sample Usage:
|
||||||
|
```
|
||||||
let person = transaction.create(Into(MyPersonEntity.self, "Configuration1"))
|
let person = transaction.create(Into(MyPersonEntity.self, "Configuration1"))
|
||||||
|
```
|
||||||
- parameter entity: the `NSManagedObject` type to be created
|
- parameter entity: the `NSManagedObject` 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.
|
- 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.
|
||||||
*/
|
*/
|
||||||
@@ -118,9 +119,9 @@ public struct Into<T: NSManagedObject> {
|
|||||||
/**
|
/**
|
||||||
Initializes an `Into` clause with the specified entity class and configuration.
|
Initializes an `Into` clause with the specified entity class and configuration.
|
||||||
Sample Usage:
|
Sample Usage:
|
||||||
|
```
|
||||||
let person = transaction.create(Into(MyPersonEntity.self, "Configuration1"))
|
let person = transaction.create(Into(MyPersonEntity.self, "Configuration1"))
|
||||||
|
```
|
||||||
- parameter entityClass: the `NSManagedObject` class type to be created
|
- 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.
|
- 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.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -26,12 +26,11 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import CoreData
|
import CoreData
|
||||||
|
|
||||||
|
|
||||||
// MARK: - NSManagedObject
|
// MARK: - NSManagedObject
|
||||||
|
|
||||||
public extension NSManagedObject {
|
public extension NSManagedObject {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns this object's parent `UnsafeDataTransaction` instance if it was created from one. Returns `nil` if the parent transaction is either an `AsynchronousDataTransaction` or a `SynchronousDataTransaction`, or if the object is not managed by CoreStore.
|
Returns this object's parent `UnsafeDataTransaction` instance if it was created from one. Returns `nil` if the parent transaction is either an `AsynchronousDataTransaction` or a `SynchronousDataTransaction`, or if the object is not managed by CoreStore.
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import Foundation
|
|||||||
/**
|
/**
|
||||||
The `SaveResult` indicates the result of a `commit(...)` for a transaction.
|
The `SaveResult` indicates the result of a `commit(...)` for a transaction.
|
||||||
The `SaveResult` can be treated as a boolean:
|
The `SaveResult` can be treated as a boolean:
|
||||||
|
```
|
||||||
CoreStore.beginAsynchronous { transaction in
|
CoreStore.beginAsynchronous { transaction in
|
||||||
// ...
|
// ...
|
||||||
let result = transaction.commit()
|
let result = transaction.commit()
|
||||||
@@ -42,9 +42,9 @@ The `SaveResult` can be treated as a boolean:
|
|||||||
// failed
|
// failed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
```
|
||||||
or as an `enum`, where the resulting associated object can also be inspected:
|
or as an `enum`, where the resulting associated object can also be inspected:
|
||||||
|
```
|
||||||
CoreStore.beginAsynchronous { transaction in
|
CoreStore.beginAsynchronous { transaction in
|
||||||
// ...
|
// ...
|
||||||
let result = transaction.commit()
|
let result = transaction.commit()
|
||||||
@@ -59,8 +59,6 @@ or as an `enum`, where the resulting associated object can also be inspected:
|
|||||||
*/
|
*/
|
||||||
public enum SaveResult {
|
public enum SaveResult {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
`SaveResult.Success` indicates that the `commit()` for the transaction succeeded, either because the save succeeded or because there were no changes to save. The associated value `hasChanges` indicates if there were saved changes or not.
|
`SaveResult.Success` indicates that the `commit()` for the transaction succeeded, either because the save succeeded or because there were no changes to save. The associated value `hasChanges` indicates if there were saved changes or not.
|
||||||
*/
|
*/
|
||||||
@@ -103,6 +101,7 @@ extension SaveResult: BooleanType {
|
|||||||
public var boolValue: Bool {
|
public var boolValue: Bool {
|
||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
|
|
||||||
case .Success: return true
|
case .Success: return true
|
||||||
case .Failure: return false
|
case .Failure: return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ The `SynchronousDataTransaction` provides an interface for `NSManagedObject` cre
|
|||||||
*/
|
*/
|
||||||
public final class SynchronousDataTransaction: BaseDataTransaction {
|
public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Saves the transaction changes and waits for completion synchronously. This method should not be used after the `commit()` method was already called once.
|
Saves the transaction changes and waits for completion synchronously. This method should not be used after the `commit()` method was already called once.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -41,8 +41,6 @@ The `UnsafeDataTransaction` provides an interface for non-contiguous `NSManagedO
|
|||||||
*/
|
*/
|
||||||
public final class UnsafeDataTransaction: BaseDataTransaction {
|
public final class UnsafeDataTransaction: BaseDataTransaction {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Saves the transaction changes asynchronously. For a `UnsafeDataTransaction`, multiple commits are allowed, although it is the developer's responsibility to ensure a reasonable leeway to prevent blocking the main thread.
|
Saves the transaction changes asynchronously. For a `UnsafeDataTransaction`, multiple commits are allowed, although it is the developer's responsibility to ensure a reasonable leeway to prevent blocking the main thread.
|
||||||
|
|
||||||
|
|||||||
@@ -50,8 +50,6 @@ The `DataStack` encapsulates the data model for the Core Data stack. Each `DataS
|
|||||||
*/
|
*/
|
||||||
public final class DataStack {
|
public final class DataStack {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes a `DataStack` from an `NSManagedObjectModel`.
|
Initializes a `DataStack` from an `NSManagedObjectModel`.
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import CoreData
|
|||||||
/**
|
/**
|
||||||
The `PersistentStoreResult` indicates the result of an asynchronous initialization of a persistent store.
|
The `PersistentStoreResult` indicates the result of an asynchronous initialization of a persistent store.
|
||||||
The `PersistentStoreResult` can be treated as a boolean:
|
The `PersistentStoreResult` can be treated as a boolean:
|
||||||
|
```
|
||||||
try! CoreStore.addSQLiteStore(completion: { (result: PersistentStoreResult) -> Void in
|
try! CoreStore.addSQLiteStore(completion: { (result: PersistentStoreResult) -> Void in
|
||||||
if result {
|
if result {
|
||||||
// succeeded
|
// succeeded
|
||||||
@@ -41,9 +41,9 @@ The `PersistentStoreResult` can be treated as a boolean:
|
|||||||
// failed
|
// failed
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
```
|
||||||
or as an `enum`, where the resulting associated object can also be inspected:
|
or as an `enum`, where the resulting associated object can also be inspected:
|
||||||
|
```
|
||||||
try! CoreStore.addSQLiteStore(completion: { (result: PersistentStoreResult) -> Void in
|
try! CoreStore.addSQLiteStore(completion: { (result: PersistentStoreResult) -> Void in
|
||||||
switch result {
|
switch result {
|
||||||
case .Success(let persistentStore):
|
case .Success(let persistentStore):
|
||||||
@@ -56,8 +56,6 @@ or as an `enum`, where the resulting associated object can also be inspected:
|
|||||||
*/
|
*/
|
||||||
public enum PersistentStoreResult {
|
public enum PersistentStoreResult {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
`PersistentStoreResult.Success` indicates that the persistent store process succeeded. The associated object for this `enum` value is the related `NSPersistentStore` instance.
|
`PersistentStoreResult.Success` indicates that the persistent store process succeeded. The associated object for this `enum` value is the related `NSPersistentStore` instance.
|
||||||
*/
|
*/
|
||||||
@@ -88,9 +86,7 @@ public enum PersistentStoreResult {
|
|||||||
|
|
||||||
internal init(_ errorCode: CoreStoreErrorCode, userInfo: [NSObject: AnyObject]?) {
|
internal init(_ errorCode: CoreStoreErrorCode, userInfo: [NSObject: AnyObject]?) {
|
||||||
|
|
||||||
self.init(NSError(
|
self.init(NSError(coreStoreErrorCode: errorCode, userInfo: userInfo))
|
||||||
coreStoreErrorCode: errorCode,
|
|
||||||
userInfo: userInfo))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,8 +95,6 @@ public enum PersistentStoreResult {
|
|||||||
|
|
||||||
extension PersistentStoreResult: BooleanType {
|
extension PersistentStoreResult: BooleanType {
|
||||||
|
|
||||||
// MARK: Public
|
|
||||||
|
|
||||||
public var boolValue: Bool {
|
public var boolValue: Bool {
|
||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
|
|||||||
Reference in New Issue
Block a user