# NSManagedObject

    extension NSManagedObject: CoreDataNativeType

    extension NSManagedObject: DynamicObject

    extension NSManagedObject: AllowedOptionalObjectiveCKeyPathValue

    extension NSManagedObject: AllowedObjectiveCRelationshipKeyPathValue

    extension NSManagedObject: ObjectRepresentation

### DynamicObject

- `cs_forceCreate(entityDescription:into:assignTo:)`

  #### Declaration

  Swift

      public class func cs_forceCreate(entityDescription: NSEntityDescription, into context: NSManagedObjectContext, assignTo store: NSPersistentStore) -> Self

- `cs_snapshotDictionary(id:context:)`

  #### Declaration

  Swift

      public class func cs_snapshotDictionary(id: ObjectID, context: NSManagedObjectContext) -> [String : Any]?

- `cs_fromRaw(object:)`

  #### Declaration

  Swift

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

- `cs_matches(object:)`

  #### Declaration

  Swift

      public static func cs_matches(object: NSManagedObject) -> Bool

- `cs_toRaw()`

  #### Declaration

  Swift

      public func cs_toRaw() -> NSManagedObject

- `cs_id()`

  #### Declaration

  Swift

      public func cs_id() -> ObjectID

### AllowedOptionalObjectiveCKeyPathValue

- `DestinationValueType`

  #### Declaration

  Swift

      public typealias DestinationValueType = NSManagedObject

### NSManagedObject

- `fetchSource()`

  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.

- `querySource()`

  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.

- `getValue(forKvcKey:)`

  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

- `getValue(forKvcKey:didGetValue:)`

  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

- `getValue(forKvcKey:willGetValue:didGetValue:)`

  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

- `setValue(_:forKvcKey:)`

  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

- `setValue(_:forKvcKey:didSetValue:)`

  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:)`.

- `setValue(_:forKvcKey:willSetValue:didSetValue:)`

  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:)`.

- `refreshAsFault()`

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

  #### Declaration

  Swift

      @nonobjc
      public func refreshAsFault()

- `refreshAndMerge()`

  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()

- `unsafeDataTransaction`

  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 }