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
CoreStoreSchemaSee also
CoreStoreObject.ValueSee 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 bothinit(rawObject:)
andinit(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 bothinit(rawObject:)
andinit(asMeta:)
, and to call their corresponding super implementations.Declaration
Swift
public required init(asMeta: Void)
-
Declaration
Swift
public static func == (lhs: CoreStoreObject, rhs: CoreStoreObject) -> Bool
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
-
Declaration
Swift
public var debugDescription: String { get }
-
Exposes a
FetchableSource
that can fetch sibling objects of thisCoreStoreObject
instance. This may be theDataStack
, aBaseDataTransaction
, theNSManagedObjectContext
itself, ornil
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 thatfetchSource()
was called. Do not make assumptions that the instance will be a specific instance. If theNSManagedObjectContext
instance is desired, use theFetchableSource.unsafeContext()
method to get the correct instance. Also, do not assume that thefetchSource()
andquerySource()
return the same instance all the time.Declaration
Swift
@nonobjc public func fetchSource() -> FetchableSource?
Return Value
a
FetchableSource
that can fetch sibling objects of thisCoreStoreObject
instance. This may be theDataStack
, aBaseDataTransaction
, theNSManagedObjectContext
itself, ornil
if the object’s parent is already deallocated. -
Exposes a
QueryableSource
that can query attributes and aggregate values. This may be theDataStack
, aBaseDataTransaction
, theNSManagedObjectContext
itself, ornil
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 thatquerySource()
was called. Do not make assumptions that the instance will be a specific instance. If theNSManagedObjectContext
instance is desired, use theQueryableSource.unsafeContext()
method to get the correct instance. Also, do not assume that thefetchSource()
andquerySource()
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 theDataStack
, aBaseDataTransaction
, theNSManagedObjectContext
itself, ornil
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()
-
Declaration
Swift
public var objectWillChange: ObservableObjectPublisher { get }
-
Declaration
Swift
public class func cs_fromRaw(object: NSManagedObject) -> Self