WIP: reorganization of keypath utilities (in prep for @propertyWrappers)

This commit is contained in:
John Estropia
2019-07-09 14:50:23 +09:00
parent 67bb9340c7
commit ed3d21db77
14 changed files with 523 additions and 314 deletions

View File

@@ -76,7 +76,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
```
- Important: `Relationship.ToOne` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties.
*/
public final class ToOne<D: CoreStoreObject>: RelationshipProtocol {
public final class ToOne<D: CoreStoreObject>: RelationshipKeyPathStringConvertible, RelationshipProtocol {
/**
Initializes the metadata for the relationship. All relationships require an "inverse", so updates to to this object's relationship are also reflected on its destination object. Make sure to declare this relationship's inverse relationship on its destination object. Due to Swift's compiler limitation, only one of the relationship and its inverse can declare an `inverse:` argument.
@@ -215,11 +215,11 @@ public enum RelationshipContainer<O: CoreStoreObject> {
affectedByKeyPaths: affectedByKeyPaths()
)
}
/**
The relationship destination object.
The relationship value
*/
public var value: D? {
public var value: ReturnValueType {
get {
@@ -230,6 +230,25 @@ public enum RelationshipContainer<O: CoreStoreObject> {
self.nativeValue = newValue?.rawObject
}
}
// MARK: AnyKeyPathStringConvertible
public var cs_keyPathString: String {
return self.keyPath
}
// MARK: KeyPathStringConvertible
public typealias ObjectType = O
public typealias DestinationValueType = D
// MARK: RelationshipKeyPathStringConvertible
public typealias ReturnValueType = DestinationValueType?
// MARK: RelationshipProtocol
@@ -319,7 +338,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
```
- Important: `Relationship.ToManyOrdered` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties.
*/
public final class ToManyOrdered<D: CoreStoreObject>: RelationshipProtocol {
public final class ToManyOrdered<D: CoreStoreObject>: ToManyRelationshipKeyPathStringConvertible, RelationshipProtocol {
/**
Initializes the metadata for the relationship. All relationships require an "inverse", so updates to to this object's relationship are also reflected on its destination object. Make sure to declare this relationship's inverse relationship on its destination object. Due to Swift's compiler limitation, only one of the relationship and its inverse can declare an `inverse:` argument.
@@ -482,11 +501,11 @@ public enum RelationshipContainer<O: CoreStoreObject> {
affectedByKeyPaths: affectedByKeyPaths()
)
}
/**
The relationship ordered objects.
The relationship value
*/
public var value: [D] {
public var value: ReturnValueType {
get {
@@ -497,6 +516,25 @@ public enum RelationshipContainer<O: CoreStoreObject> {
self.nativeValue = NSOrderedSet(array: newValue.map({ $0.rawObject! }))
}
}
// MARK: AnyKeyPathStringConvertible
public var cs_keyPathString: String {
return self.keyPath
}
// MARK: KeyPathStringConvertible
public typealias ObjectType = O
public typealias DestinationValueType = D
// MARK: RelationshipKeyPathStringConvertible
public typealias ReturnValueType = [DestinationValueType]
// MARK: RelationshipProtocol
@@ -591,7 +629,7 @@ public enum RelationshipContainer<O: CoreStoreObject> {
```
- Important: `Relationship.ToManyUnordered` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties.
*/
public final class ToManyUnordered<D: CoreStoreObject>: RelationshipProtocol {
public final class ToManyUnordered<D: CoreStoreObject>: ToManyRelationshipKeyPathStringConvertible, RelationshipProtocol {
/**
Initializes the metadata for the relationship. All relationships require an "inverse", so updates to to this object's relationship are also reflected on its destination object. Make sure to declare this relationship's inverse relationship on its destination object. Due to Swift's compiler limitation, only one of the relationship and its inverse can declare an `inverse:` argument.
@@ -755,11 +793,11 @@ public enum RelationshipContainer<O: CoreStoreObject> {
affectedByKeyPaths: affectedByKeyPaths()
)
}
/**
The relationship unordered objects.
The relationship value
*/
public var value: Set<D> {
public var value: ReturnValueType {
get {
@@ -770,6 +808,25 @@ public enum RelationshipContainer<O: CoreStoreObject> {
self.nativeValue = NSSet(array: newValue.map({ $0.rawObject! }))
}
}
// MARK: AnyKeyPathStringConvertible
public var cs_keyPathString: String {
return self.keyPath
}
// MARK: KeyPathStringConvertible
public typealias ObjectType = O
public typealias DestinationValueType = D
// MARK: RelationshipKeyPathStringConvertible
public typealias ReturnValueType = Set<DestinationValueType>
// MARK: RelationshipProtocol