NSManagedObject
extension NSManagedObject: CoreDataNativeType
extension NSManagedObject: DynamicObject
extension NSManagedObject: AllowedOptionalObjectiveCKeyPathValue
extension NSManagedObject: AllowedObjectiveCRelationshipKeyPathValue
extension NSManagedObject: ObjectRepresentation
-
Declaration
Swift
public class func cs_forceCreate(entityDescription: NSEntityDescription, into context: NSManagedObjectContext, assignTo store: NSPersistentStore) -> Self
-
Declaration
Swift
public class func cs_snapshotDictionary(id: ObjectID, context: NSManagedObjectContext) -> [String : Any]?
-
Declaration
Swift
public class func cs_fromRaw(object: NSManagedObject) -> Self
-
Declaration
Swift
public static func cs_matches(object: NSManagedObject) -> Bool
-
Declaration
Swift
public func cs_toRaw() -> NSManagedObject
-
Declaration
Swift
public func cs_id() -> ObjectID
-
Declaration
Swift
public typealias DestinationValueType = NSManagedObject
-
Exposes a
FetchableSource
that can fetch sibling objects of thisNSManagedObject
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 thisNSManagedObject
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. -
Provides a convenience wrapper for accessing
primitiveValue(forKey:)
with proper calls towillAccessValue(forKey:)
anddidAccessValue(forKey:)
. This is useful when implementing accessor methods for transient attributes.Declaration
Swift
@nonobjc @inline(__always) public func getValue(forKvcKey kvcKey: KeyPathString) -> Any?
Parameters
kvcKey
the KVC key
Return Value
the primitive value for the KVC key
-
Provides a convenience wrapper for accessing
primitiveValue(forKey:)
with proper calls towillAccessValue(forKey:)
anddidAccessValue(forKey:)
. This is useful when implementing accessor methods for transient attributes.Declaration
Swift
@nonobjc @inline(__always) public func getValue<T>(forKvcKey kvcKey: KeyPathString, didGetValue: (Any?) throws -> T) rethrows -> T
Parameters
kvcKey
the KVC key
didGetValue
a closure to transform the primitive value
Return Value
the primitive value transformed by the
didGetValue
closure -
Provides a convenience wrapper for accessing
primitiveValue(forKey:)
with proper calls towillAccessValue(forKey:)
anddidAccessValue(forKey:)
. This is useful when implementing accessor methods for transient attributes.Declaration
Swift
@nonobjc @inline(__always) public func getValue<T>(forKvcKey kvcKey: KeyPathString, willGetValue: () throws -> Void, didGetValue: (Any?) throws -> T) rethrows -> T
Parameters
kvcKey
the KVC key
willGetValue
called before accessing
primitiveValue(forKey:)
. Callers are allowed to cancel the access by throwing an error.didGetValue
a closure to transform the primitive value
Return Value
the primitive value transformed by the
didGetValue
closure -
Provides a convenience wrapper for setting
setPrimitiveValue(_:forKey:)
with proper calls towillChangeValue(forKey:)
anddidChangeValue(forKey:)
. This is useful when implementing mutator methods for transient attributes.Declaration
Swift
@nonobjc @inline(__always) public func setValue(_ value: Any?, forKvcKey KVCKey: KeyPathString)
Parameters
value
the value to set the KVC key with
KVCKey
the KVC key
-
Provides a convenience wrapper for setting
setPrimitiveValue(_:forKey:)
with proper calls towillChangeValue(forKey:)
anddidChangeValue(forKey:)
.Declaration
Swift
@nonobjc @inline(__always) public func setValue(_ value: Any?, forKvcKey KVCKey: KeyPathString, didSetValue: () -> Void)
Parameters
value
the value to set the KVC key with
KVCKey
the KVC key
didSetValue
called after executing
setPrimitiveValue(forKey:)
. -
Provides a convenience wrapper for setting
setPrimitiveValue(_:forKey:)
with proper calls towillChangeValue(forKey:)
anddidChangeValue(forKey:)
. This is useful when implementing mutator methods for transient attributes.Declaration
Swift
@nonobjc @inline(__always) public func setValue<T>(_ value: T, forKvcKey KVCKey: KeyPathString, willSetValue: (T) throws -> Any?, didSetValue: (Any?) -> Void = { _ in }) rethrows
Parameters
value
the value to set the KVC key with
KVCKey
the KVC key
willSetValue
called before accessing
setPrimitiveValue(forKey:)
. Callers are allowed to cancel the mutation by throwing an error, for example, for custom validations.didSetValue
called after executing
setPrimitiveValue(forKey:)
. -
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()
-
Returns this object’s parent
UnsafeDataTransaction
instance if it was created from one. Returnsnil
if the parent transaction is either anAsynchronousDataTransaction
or aSynchronousDataTransaction
, or if the object is not managed by CoreStore.When using an
UnsafeDataTransaction
and passing around a temporary object, you can use this property to execute fetches and updates to the transaction without having to pass around both the object and the transaction instances.Important
The internal reference to the transaction isweak
, and it is still the developer’s responsibility to retain a strong reference to theUnsafeDataTransaction
.Declaration
Swift
@nonobjc public var unsafeDataTransaction: UnsafeDataTransaction? { get }