CoreStoreObject

open class CoreStoreObject : DynamicObject, Hashable
extension CoreStoreObject: CustomDebugStringConvertible, CoreStoreDebugStringConvertible
extension CoreStoreObject: ObservableObject
extension CoreStoreObject: ObjectRepresentation

The CoreStoreObject is an abstract class for creating CoreStore-managed objects that are more type-safe and more convenient than NSManagedObject subclasses. The model entities for CoreStoreObject subclasses are inferred from the Swift declaration themselves; no .xcdatamodeld files are needed. To declare persisted attributes and relationships for the CoreStoreObject subclass, declare properties of type Value.Required<T>, Value.Optional<T> for values, or Relationship.ToOne<T>, Relationship.ToManyOrdered<T>, Relationship.ToManyUnordered<T> for relationships.

class Animal: CoreStoreObject {
    let species = Value.Required<String>("species", initial: "")
    let nickname = Value.Optional<String>("nickname")
    let master = Relationship.ToOne<Person>("master")
}

class Person: CoreStoreObject {
    let name = Value.Required<String>("name", initial: "")
    let pet = Relationship.ToOne<Animal>("pet", inverse: { $0.master })
}

CoreStoreObject entities for a model version should be added to CoreStoreSchema instance.

CoreStoreDefaults.dataStack = DataStack(
    CoreStoreSchema(
        modelVersion: "V1",
        entities: [
            Entity<Animal>("Animal"),
            Entity<Person>("Person")
        ]
    )
)

See also

CoreStoreSchema

See also

CoreStoreObject.Value

See also

CoreStoreObject.Relationship
  • Do not call this directly. This is exposed as public only as a required initializer.

    Important

    subclasses that need a custom initializer should override both init(rawObject:) and init(asMeta:), and to call their corresponding super implementations.

    Declaration

    Swift

    public required init(rawObject: NSManagedObject)
  • Do not call this directly. This is exposed as public only as a required initializer.

    Important

    subclasses that need a custom initializer should override both init(rawObject:) and init(asMeta:), and to call their corresponding super implementations.

    Declaration

    Swift

    public required init(asMeta: Void)

Equatable

  • Declaration

    Swift

    public static func == (lhs: CoreStoreObject, rhs: CoreStoreObject) -> Bool

Hashable

  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)

CustomDebugStringConvertible

  • Declaration

    Swift

    public var debugDescription: String { get }

CoreStoreObject

  • Exposes a FetchableSource that can fetch sibling objects of this CoreStoreObject instance. This may be the DataStack, a BaseDataTransaction, the NSManagedObjectContext itself, or nil if the obejct’s parent is already deallocated.

    Warning

    Future implementations may change the instance returned by this method depending on the timing or condition that fetchSource() was called. Do not make assumptions that the instance will be a specific instance. If the NSManagedObjectContext instance is desired, use the FetchableSource.unsafeContext() method to get the correct instance. Also, do not assume that the fetchSource() and querySource() return the same instance all the time.

    Declaration

    Swift

    @nonobjc
    public func fetchSource() -> FetchableSource?

    Return Value

    a FetchableSource that can fetch sibling objects of this CoreStoreObject instance. This may be the DataStack, a BaseDataTransaction, the NSManagedObjectContext itself, or nil if the object’s parent is already deallocated.

  • Exposes a QueryableSource that can query attributes and aggregate values. This may be the DataStack, a BaseDataTransaction, the NSManagedObjectContext itself, or nil if the obejct’s parent is already deallocated.

    Warning

    Future implementations may change the instance returned by this method depending on the timing or condition that querySource() was called. Do not make assumptions that the instance will be a specific instance. If the NSManagedObjectContext instance is desired, use the QueryableSource.unsafeContext() method to get the correct instance. Also, do not assume that the fetchSource() and querySource() return the same instance all the time.

    Declaration

    Swift

    @nonobjc
    public func querySource() -> QueryableSource?

    Return Value

    a QueryableSource that can query attributes and aggregate values. This may be the DataStack, a BaseDataTransaction, the NSManagedObjectContext itself, or nil if the object’s parent is already deallocated.

  • Re-faults the object to use the latest values from the persistent store

    Declaration

    Swift

    @nonobjc
    public func refreshAsFault()
  • Re-faults the object to use the latest values from the persistent store and merges previously pending changes back

    Declaration

    Swift

    @nonobjc
    public func refreshAndMerge()

ObservableObject

  • Declaration

    Swift

    public var objectWillChange: ObservableObjectPublisher { get }

DynamicObject

  • Declaration

    Swift

    public class func cs_fromRaw(object: NSManagedObject) -> Self