NSManagedObject

extension NSManagedObject: CoreDataNativeType
extension NSManagedObject: DynamicObject
extension NSManagedObject: AllowedOptionalObjectiveCKeyPathValue
extension NSManagedObject: AllowedObjectiveCRelationshipKeyPathValue
extension NSManagedObject: ObjectRepresentation

DynamicObject

  • 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

AllowedOptionalObjectiveCKeyPathValue

NSManagedObject

  • Exposes a FetchableSource that can fetch sibling objects of this NSManagedObject 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 NSManagedObject 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.

  • Provides a convenience wrapper for accessing primitiveValue(forKey:) with proper calls to willAccessValue(forKey:) and didAccessValue(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 to willAccessValue(forKey:) and didAccessValue(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 to willAccessValue(forKey:) and didAccessValue(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 to willChangeValue(forKey:) and didChangeValue(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 to willChangeValue(forKey:) and didChangeValue(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 to willChangeValue(forKey:) and didChangeValue(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. Returns nil if the parent transaction is either an AsynchronousDataTransaction or a SynchronousDataTransaction, 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 is weak, and it is still the developer’s responsibility to retain a strong reference to the UnsafeDataTransaction.

    Declaration

    Swift

    @nonobjc
    public var unsafeDataTransaction: UnsafeDataTransaction? { get }