added a typealias for the object type contained in ListMonitor and ObjectMonitor

This commit is contained in:
John Estropia
2017-04-19 17:04:34 +09:00
parent b6bc7c2edf
commit b0e2655bdf
3 changed files with 20 additions and 10 deletions

View File

@@ -39,9 +39,9 @@ public extension BaseDataTransaction {
- throws: an `Error` thrown from any of the `ImportableObject` methods - throws: an `Error` thrown from any of the `ImportableObject` methods
- returns: the created `ImportableObject` instance, or `nil` if the import was ignored - returns: the created `ImportableObject` instance, or `nil` if the import was ignored
*/ */
public func importObject<T>( public func importObject<T: DynamicObject & ImportableObject>(
_ into: Into<T>, _ into: Into<T>,
source: T.ImportSource) throws -> T? where T: DynamicObject, T: ImportableObject { source: T.ImportSource) throws -> T? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -69,9 +69,9 @@ public extension BaseDataTransaction {
- parameter source: the object to import values from - parameter source: the object to import values from
- throws: an `Error` thrown from any of the `ImportableObject` methods - throws: an `Error` thrown from any of the `ImportableObject` methods
*/ */
public func importObject<T>( public func importObject<T: DynamicObject & ImportableObject>(
_ object: T, _ object: T,
source: T.ImportSource) throws where T: DynamicObject, T: ImportableObject { source: T.ImportSource) throws {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -97,9 +97,9 @@ public extension BaseDataTransaction {
- throws: an `Error` thrown from any of the `ImportableObject` methods - throws: an `Error` thrown from any of the `ImportableObject` methods
- returns: the array of created `ImportableObject` instances - returns: the array of created `ImportableObject` instances
*/ */
public func importObjects<T, S: Sequence>( public func importObjects<T: DynamicObject & ImportableObject, S: Sequence>(
_ into: Into<T>, _ into: Into<T>,
sourceArray: S) throws -> [T] where T: DynamicObject, T: ImportableObject, S.Iterator.Element == T.ImportSource { sourceArray: S) throws -> [T] where S.Iterator.Element == T.ImportSource {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -133,9 +133,9 @@ public extension BaseDataTransaction {
- throws: an `Error` thrown from any of the `ImportableUniqueObject` methods - throws: an `Error` thrown from any of the `ImportableUniqueObject` methods
- returns: the created/updated `ImportableUniqueObject` instance, or `nil` if the import was ignored - returns: the created/updated `ImportableUniqueObject` instance, or `nil` if the import was ignored
*/ */
public func importUniqueObject<T>( public func importUniqueObject<T: DynamicObject & ImportableUniqueObject>(
_ into: Into<T>, _ into: Into<T>,
source: T.ImportSource) throws -> T? where T: DynamicObject, T: ImportableUniqueObject { source: T.ImportSource) throws -> T? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -185,10 +185,10 @@ public extension BaseDataTransaction {
- throws: an `Error` thrown from any of the `ImportableUniqueObject` methods - throws: an `Error` thrown from any of the `ImportableUniqueObject` methods
- returns: the array of created/updated `ImportableUniqueObject` instances - returns: the array of created/updated `ImportableUniqueObject` instances
*/ */
public func importUniqueObjects<T, S: Sequence>( public func importUniqueObjects<T: DynamicObject & ImportableUniqueObject, S: Sequence>(
_ into: Into<T>, _ into: Into<T>,
sourceArray: S, sourceArray: S,
preProcess: @escaping (_ mapping: [T.UniqueIDType: T.ImportSource]) throws -> [T.UniqueIDType: T.ImportSource] = { $0 }) throws -> [T] where T: DynamicObject, T: ImportableUniqueObject, S.Iterator.Element == T.ImportSource { preProcess: @escaping (_ mapping: [T.UniqueIDType: T.ImportSource]) throws -> [T.UniqueIDType: T.ImportSource] = { $0 }) throws -> [T] where S.Iterator.Element == T.ImportSource {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),

View File

@@ -71,6 +71,11 @@ public final class ListMonitor<T: DynamicObject>: Hashable {
// MARK: Public (Accessors) // MARK: Public (Accessors)
/**
The type for the objects contained bye the `ListMonitor`
*/
public typealias ObjectType = T
/** /**
Returns the object at the given index within the first section. This subscript indexer is typically used for `ListMonitor`s created with `monitorList(_:)`. Returns the object at the given index within the first section. This subscript indexer is typically used for `ListMonitor`s created with `monitorList(_:)`.

View File

@@ -42,6 +42,11 @@ import CoreData
@available(OSX 10.12, *) @available(OSX 10.12, *)
public final class ObjectMonitor<EntityType: DynamicObject>: Equatable { public final class ObjectMonitor<EntityType: DynamicObject>: Equatable {
/**
The type for the object contained by the `ObjectMonitor`
*/
public typealias ObjectType = EntityType
/** /**
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.
*/ */