# DynamicObject

    public protocol DynamicObject : AnyObject

All CoreStore’s utilities are designed around `DynamicObject` instances. `NSManagedObject` and `CoreStoreObject` instances all conform to `DynamicObject`.

- `ObjectID`

  The object ID for this instance

  #### Declaration

  Swift

      typealias ObjectID = NSManagedObjectID

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

  Used internally by CoreStore. Do not call directly.

  #### Declaration

  Swift

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

- `cs_snapshotDictionary(id:context:)`

  Used internally by CoreStore. Do not call directly.

  #### Declaration

  Swift

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

- `cs_fromRaw(object:)`

  Used internally by CoreStore. Do not call directly.

  #### Declaration

  Swift

      static func cs_fromRaw(object: NSManagedObject) -> Self

- `cs_matches(object:)`

  Used internally by CoreStore. Do not call directly.

  #### Declaration

  Swift

      static func cs_matches(object: NSManagedObject) -> Bool

- `cs_toRaw()`

  Used internally by CoreStore. Do not call directly.

  #### Declaration

  Swift

      func cs_toRaw() -> NSManagedObject

- `cs_id()`

  Used internally by CoreStore. Do not call directly.

  #### Declaration

  Swift

      func cs_id() -> ObjectID

### Available where `Self`: `CoreStoreObject`

- `partialObject()` Extension method

  Returns the `PartialObject` instance for the object, which acts as a fast, type-safe KVC interface for `CoreStoreObject`.

  #### Declaration

  Swift

      public func partialObject() -> PartialObject<Self>

- `Field` Extension method

  The containing type for value propertiess.

      class Pet: CoreStoreObject {

          @Field.Stored("species")
          var species = ""

          @Field.Stored("nickname")
          var nickname: String?

          @Field.Coded("color", coder: FieldCoders.Plist.self)
          var eyeColor: UIColor?

          @Field.Relationship("owner", inverse: \.$pets)
          var owner: Person?

          @Field.Relationship("children")
          var children: Array<Pet>

          @Field.Relationship("parents", inverse: \.$children)
          var parents: Set<Pet>
      }

  Important

  `Field` properties are required to be used as `@propertyWrapper`s. Any other declaration not using the `@Field.*(...) var` syntax will result in undefined behavior.

  #### Declaration

  Swift

      public typealias Field = FieldContainer<Self>

### Public

- `asPublisher()` Extension method

  An `ObjectPublisher` wrapper for the exact same object

  #### Declaration

  Swift

      public func asPublisher() -> ObjectPublisher<Self>?

- `asSnapshot()` Extension method

  A thread-safe `struct` that is a full-copy of the object’s properties

  #### Declaration

  Swift

      public func asSnapshot() -> ObjectSnapshot<Self>?

### Available where `Self`: `CoreStoreObject`

- `Relationship` Extension method

  The containing type for relationships. `Relationship`s can be any `CoreStoreObject` subclass.

      class Dog: CoreStoreObject {
          let master = Relationship.ToOne<Person>("master")
      }
      class Person: CoreStoreObject {
          let pets = Relationship.ToManyUnordered<Dog>("pets", inverse: { $0.master })
      }

  Important

  `Relationship` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties.

  #### Declaration

  Swift

      public typealias Relationship = RelationshipContainer<Self>

- `Transformable` Extension method

  The containing type for transformable properties. `Transformable` properties support types that conforms to `NSCoding & NSCopying`.

      class Animal: CoreStoreObject {
          let species = Value.Required<String>("species", initial: "")
          let nickname = Value.Optional<String>("nickname")
          let color = Transformable.Optional<UIColor>("color")
      }

  Important

  `Transformable` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties.

  #### Declaration

  Swift

      public typealias Transformable = TransformableContainer<Self>

- `Value` Extension method

  The containing type for value propertiess. `Value` properties support any type that conforms to `ImportableAttributeType`.

      class Animal: CoreStoreObject {
          let species = Value.Required<String>("species", initial: "")
          let nickname = Value.Optional<String>("nickname")
          let color = Transformable.Optional<UIColor>("color")
      }

  Important

  `Value` properties are required to be stored properties. Computed properties will be ignored, including `lazy` and `weak` properties.

  #### Declaration

  Swift

      public typealias Value = ValueContainer<Self>