mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-20 08:34:23 +01:00
support compound indexes and unique constraints on CoreStore properties
This commit is contained in:
@@ -107,7 +107,6 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
```
|
||||
- parameter keyPath: the permanent attribute name for this property.
|
||||
- parameter initial: the initial value for the property when the object is first created. Defaults to the `ImportableAttributeType`'s empty value if not specified.
|
||||
- parameter isIndexed: `true` if the property should be indexed for searching, otherwise `false`. Defaults to `false` if not specified.
|
||||
- parameter isTransient: `true` if the property is transient, otherwise `false`. Defaults to `false` if not specified. The transient flag specifies whether or not a property's value is ignored when an object is saved to a persistent store. Transient properties are not saved to the persistent store, but are still managed for undo, redo, validation, and so on.
|
||||
- parameter allowsExternalBinaryDataStorage: `true` if the attribute allows external binary storage, otherwise `false`.
|
||||
- parameter versionHashModifier: used to mark or denote a property as being a different "version" than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)
|
||||
@@ -119,7 +118,6 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
public init(
|
||||
_ keyPath: KeyPathString,
|
||||
initial: @autoclosure @escaping () -> V,
|
||||
isIndexed: Bool = false,
|
||||
isTransient: Bool = false,
|
||||
allowsExternalBinaryDataStorage: Bool = false,
|
||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||
@@ -130,7 +128,6 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
|
||||
self.keyPath = keyPath
|
||||
self.defaultValue = initial
|
||||
self.isIndexed = isIndexed
|
||||
self.isTransient = isTransient
|
||||
self.allowsExternalBinaryDataStorage = allowsExternalBinaryDataStorage
|
||||
self.versionHashModifier = versionHashModifier
|
||||
@@ -202,7 +199,6 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
|
||||
internal let keyPath: KeyPathString
|
||||
internal let isOptional = false
|
||||
internal let isIndexed: Bool
|
||||
internal let isTransient: Bool
|
||||
internal let allowsExternalBinaryDataStorage: Bool
|
||||
internal let versionHashModifier: () -> String?
|
||||
@@ -258,15 +254,15 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
|
||||
private let customGetter: ((_ partialObject: PartialObject<O>) -> V)?
|
||||
private let customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V) -> Void)?
|
||||
|
||||
|
||||
|
||||
|
||||
// MARK: Deprecated
|
||||
|
||||
@available(*, deprecated: 3.2, renamed: "init(_:initial:isIndexed:isTransient:versionHashModifier:renamingIdentifier:customGetter:customSetter:affectedByKeyPaths:)")
|
||||
|
||||
@available(*, unavailable, message: "Indexes are now set through the Entity<T> initializer, which now supports compound indexes.")
|
||||
public convenience init(
|
||||
_ keyPath: KeyPathString,
|
||||
`default`: @autoclosure @escaping () -> V,
|
||||
isIndexed: Bool = false,
|
||||
initial: @autoclosure @escaping () -> V,
|
||||
isIndexed: Bool,
|
||||
isTransient: Bool = false,
|
||||
allowsExternalBinaryDataStorage: Bool = false,
|
||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||
@@ -274,18 +270,8 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
customGetter: ((_ partialObject: PartialObject<O>) -> V)? = nil,
|
||||
customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V) -> Void)? = nil,
|
||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
|
||||
|
||||
self.init(
|
||||
keyPath,
|
||||
initial: `default`,
|
||||
isIndexed: isIndexed,
|
||||
isTransient: isTransient,
|
||||
versionHashModifier: versionHashModifier,
|
||||
renamingIdentifier: renamingIdentifier,
|
||||
customGetter: customGetter,
|
||||
customSetter: customSetter,
|
||||
affectedByKeyPaths: affectedByKeyPaths
|
||||
)
|
||||
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,8 +320,8 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
```
|
||||
- parameter keyPath: the permanent attribute name for this property.
|
||||
- parameter initial: the initial value for the property when the object is first created. Defaults to the `ImportableAttributeType`'s empty value if not specified.
|
||||
- parameter isIndexed: `true` if the property should be indexed for searching, otherwise `false`. Defaults to `false` if not specified.
|
||||
- parameter isTransient: `true` if the property is transient, otherwise `false`. Defaults to `false` if not specified. The transient flag specifies whether or not a property's value is ignored when an object is saved to a persistent store. Transient properties are not saved to the persistent store, but are still managed for undo, redo, validation, and so on.
|
||||
- parameter allowsExternalBinaryDataStorage: `true` if the attribute allows external binary storage, otherwise `false`.
|
||||
- parameter versionHashModifier: used to mark or denote a property as being a different "version" than another even if all of the values which affect persistence are equal. (Such a difference is important in cases where the properties are unchanged but the format or content of its data are changed.)
|
||||
- parameter renamingIdentifier: used to resolve naming conflicts between models. When creating an entity mapping between entities in two managed object models, a source entity property and a destination entity property that share the same identifier indicate that a property mapping should be configured to migrate from the source to the destination. If unset, the identifier will be the property's name.
|
||||
- parameter customGetter: use this closure as an "override" for the default property getter. The closure receives a `PartialObject<O>`, which acts as a fast, type-safe KVC interface for `CoreStoreObject`. The reason a `CoreStoreObject` instance is not passed directly is because the Core Data runtime is not aware of `CoreStoreObject` properties' static typing, and so loading those info everytime KVO invokes this accessor method incurs a cumulative performance hit (especially in KVO-heavy operations such as `ListMonitor` observing.) When accessing the property value from `PartialObject<O>`, make sure to use `PartialObject<O>.primitiveValue(for:)` instead of `PartialObject<O>.value(for:)`, which would unintentionally execute the same closure again recursively.
|
||||
@@ -345,8 +331,8 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
public init(
|
||||
_ keyPath: KeyPathString,
|
||||
initial: @autoclosure @escaping () -> V? = nil,
|
||||
isIndexed: Bool = false,
|
||||
isTransient: Bool = false,
|
||||
allowsExternalBinaryDataStorage: Bool = false,
|
||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||
renamingIdentifier: @autoclosure @escaping () -> String? = nil,
|
||||
customGetter: ((_ partialObject: PartialObject<O>) -> V?)? = nil,
|
||||
@@ -355,8 +341,8 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
|
||||
self.keyPath = keyPath
|
||||
self.defaultValue = initial
|
||||
self.isIndexed = isIndexed
|
||||
self.isTransient = isTransient
|
||||
self.allowsExternalBinaryDataStorage = allowsExternalBinaryDataStorage
|
||||
self.versionHashModifier = versionHashModifier
|
||||
self.renamingIdentifier = renamingIdentifier
|
||||
self.customGetter = customGetter
|
||||
@@ -426,8 +412,8 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
|
||||
internal let keyPath: KeyPathString
|
||||
internal let isOptional = true
|
||||
internal let isIndexed: Bool
|
||||
internal let isTransient: Bool
|
||||
internal let allowsExternalBinaryDataStorage: Bool
|
||||
internal let versionHashModifier: () -> String?
|
||||
internal let renamingIdentifier: () -> String?
|
||||
internal let defaultValue: () -> Any?
|
||||
@@ -481,33 +467,24 @@ public enum TransformableContainer<O: CoreStoreObject> {
|
||||
|
||||
private let customGetter: ((_ partialObject: PartialObject<O>) -> V?)?
|
||||
private let customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V?) -> Void)?
|
||||
|
||||
|
||||
|
||||
|
||||
// MARK: Deprecated
|
||||
|
||||
@available(*, deprecated: 3.2, renamed: "init(_:initial:isIndexed:isTransient:versionHashModifier:renamingIdentifier:customGetter:customSetter:affectedByKeyPaths:)")
|
||||
|
||||
@available(*, unavailable, message: "Indexes are now set through the Entity<T> initializer, which now supports compound indexes.")
|
||||
public convenience init(
|
||||
_ keyPath: KeyPathString,
|
||||
`default`: @autoclosure @escaping () -> V? = nil,
|
||||
isIndexed: Bool = false,
|
||||
initial: @autoclosure @escaping () -> V? = nil,
|
||||
isIndexed: Bool,
|
||||
isTransient: Bool = false,
|
||||
allowsExternalBinaryDataStorage: Bool = false,
|
||||
versionHashModifier: @autoclosure @escaping () -> String? = nil,
|
||||
renamingIdentifier: @autoclosure @escaping () -> String? = nil,
|
||||
customGetter: ((_ partialObject: PartialObject<O>) -> V?)? = nil,
|
||||
customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V?) -> Void)? = nil,
|
||||
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
|
||||
|
||||
self.init(
|
||||
keyPath,
|
||||
initial: `default`,
|
||||
isIndexed: isIndexed,
|
||||
isTransient: isTransient,
|
||||
versionHashModifier: versionHashModifier,
|
||||
renamingIdentifier: renamingIdentifier,
|
||||
customGetter: customGetter,
|
||||
customSetter: customSetter,
|
||||
affectedByKeyPaths: affectedByKeyPaths
|
||||
)
|
||||
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user