# Protocols

The following protocols are available globally.

### CoreDataNativeType

- `CoreDataNativeType`

  Objective-C Foundation types that are natively supported by Core Data managed attributes all conform to `CoreDataNativeType`.

  #### Declaration

  Swift

      @objc
      public protocol CoreDataNativeType : NSObjectProtocol

### CoreStoreLogger

- `CoreStoreLogger`

  Custom loggers should implement the `CoreStoreLogger` protocol and pass its instance to `CoreStoreDefaults.logger`. Calls to `log(...)`, `assert(...)`, and `abort(...)` are not tied to a specific queue/thread, so it is the implementer’s job to handle thread-safety.

  See more

  #### Declaration

  Swift

      public protocol CoreStoreLogger

### CoreStoreObjectKeyValueObservation

- `CoreStoreObjectKeyValueObservation`

  Observation token for `CoreStoreObject` properties. Make sure to retain this instance to keep observing notifications.

  `invalidate()` will be called automatically when an `CoreStoreObjectKeyValueObservation` is deinited.

  See more

  #### Declaration

  Swift

      public protocol CoreStoreObjectKeyValueObservation : AnyObject

### DynamicObject

- `DynamicObject`

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

  See more

  #### Declaration

  Swift

      public protocol DynamicObject : AnyObject

### DiffableDataSource.Target

- `DiffableDataSourceTarget`

  The `DiffableDataSource.Target` protocol allows custom views to consume `ListSnapshot` diffable data similar to how `DiffableDataSource.TableViewAdapter` and `DiffableDataSource.CollectionViewAdapter` reloads data for their corresponding views.

  See more

  #### Declaration

  Swift

      public protocol DiffableDataSourceTarget

### DynamicSchema

- `DynamicSchema`

  `DynamicSchema` are types that provide `NSManagedObjectModel` instances for a single model version. CoreStore currently supports the following concrete types:

  - `XcodeDataModelSchema`: describes models loaded from a .xcdatamodeld file.
  - `UnsafeDataModelSchema`: describes models loaded directly from an existing `NSManagedObjectModel`. It is not advisable to continue using this model as its metadata are not available to CoreStore.
  - `CoreStoreSchema`: describes models written for `CoreStoreObject` Swift class declarations.
  See more

  #### Declaration

  Swift

      public protocol DynamicSchema

### FieldRelationshipType

- `FieldRelationshipType`

  Values to be used for `Field.Relationship` properties.

  See more

  #### Declaration

  Swift

      public protocol FieldRelationshipType

### FetchChainableBuilderType

- `FetchChainableBuilderType`

  Utility protocol for `FetchChainBuilder`. Used in fetch methods that support chained fetch builders.

  See more

  #### Declaration

  Swift

      public protocol FetchChainableBuilderType

### FetchableSource

- `FetchableSource`

  Encapsulates containers which manages an internal `NSManagedObjectContext`, such as `DataStack`s and transactions, that can be used for fetching objects. CoreStore provides implementations for this protocol and should be used as a read-only abstraction.

  See more

  #### Declaration

  Swift

      public protocol FetchableSource : AnyObject

### FieldCoderType

- `FieldCoderType`

  Types that implement encoding to and decoding from `Data` to be used in `Field.Coded` properties’ `coder:` argument.

      class Person: CoreStoreObject {

          @Field.Coded("profile", coder: FieldCoders.Json.self)
          var profile: Profile = .init()
      }

  See more

  #### Declaration

  Swift

      public protocol FieldCoderType

### DefaultNSSecureCodable

- `DefaultNSSecureCodable`

  Types that are supported by `FieldCoders.DefaultNSSecureCoding`

  #### Declaration

  Swift

      public protocol DefaultNSSecureCodable : NSObject, NSSecureCoding

### FieldOptionalType

- `FieldOptionalType`

  Optional values to be used for `Field` properties.

  See more

  #### Declaration

  Swift

      public protocol FieldOptionalType : ExpressibleByNilLiteral

### FieldStorableType

- `FieldStorableType`

  Values to be used for `Field.Stored` properties.

  See more

  #### Declaration

  Swift

      public protocol FieldStorableType

### GroupByClause

- `GroupByClause`

  Abstracts the `GroupBy` clause for protocol utilities.

  See more

  #### Declaration

  Swift

      public protocol GroupByClause

### ImportableAttributeType

- `ImportableAttributeType`

  Types supported by CoreStore as `NSManagedObject` and `CoreStoreObject` property types. Supported default types:

  - Bool
  - CGFloat
  - Data

  Date

  Date
  - Double
  - Float
  - Int
  - Int8
  - Int16
  - Int32
  - Int64
  - NSData
  - NSDate
  - NSDecimalNumber
  - NSNumber
  - NSString
  - NSURL
  - NSUUID
  - String
  - URL
  - UUID

  In addition, `RawRepresentable` types whose `RawValue` already implements `ImportableAttributeType` only need to declare conformance to `ImportableAttributeType`.

  #### Declaration

  Swift

      public protocol ImportableAttributeType : QueryableAttributeType

### ImportableObject

- `ImportableObject`

  `NSManagedObject` and `CoreStoreObject` subclasses that conform to the `ImportableObject` protocol can be imported from a specified `ImportSource`. This allows transactions to create and insert instances this way:

      class Person: NSManagedObject, ImportableObject {
          typealias ImportSource = NSDictionary
          // ...
      }

      dataStack.perform(
          asynchronous: { (transaction) -> Void in
              let json: NSDictionary = // ...
              let person = try transaction.importObject(
                  Into<Person>(),
                  source: json
              )
              // ...
          },
          completion: { (result) in
              // ...
          }
      )

  See more

  #### Declaration

  Swift

      public protocol ImportableObject : DynamicObject

### ImportableUniqueObject

- `ImportableUniqueObject`

  `NSManagedObject` subclasses that conform to the `ImportableUniqueObject` protocol can be imported from a specified `ImportSource`. This allows transactions to either update existing objects or create new instances this way:

      class Person: NSManagedObject, ImportableObject {
          typealias ImportSource = NSDictionary
          typealias UniqueIDType = NSString
          // ...
      }

      dataStack.perform(
          asynchronous: { (transaction) -> Void in
              let json: NSDictionary = // ...
              let person = try transaction.importUniqueObject(
                  Into<Person>(),
                  source: json
              )
              // ...
          },
          completion: { (result) in
              // ...
          }
      )

  See more

  #### Declaration

  Swift

      public protocol ImportableUniqueObject : ImportableObject, Hashable

### AllowedObjectiveCKeyPathValue

- `AllowedObjectiveCKeyPathValue`

  Used only for utility methods. Types allowed as `Value` generic type to `KeyPath` utilities.

  See more

  #### Declaration

  Swift

      public protocol AllowedObjectiveCKeyPathValue

### AllowedOptionalObjectiveCKeyPathValue

- `AllowedOptionalObjectiveCKeyPathValue`

  Used only for utility methods. Types allowed as `Value` generic type to `KeyPath` utilities.

  #### Declaration

  Swift

      public protocol AllowedOptionalObjectiveCKeyPathValue : AllowedObjectiveCKeyPathValue

### AllowedObjectiveCAttributeKeyPathValue

- `AllowedObjectiveCAttributeKeyPathValue`

  Used only for utility methods. Types allowed as `Value` generic type to `KeyPath` utilities.

  See more

  #### Declaration

  Swift

      public protocol AllowedObjectiveCAttributeKeyPathValue : AllowedObjectiveCKeyPathValue

### AllowedObjectiveCRelationshipKeyPathValue

- `AllowedObjectiveCRelationshipKeyPathValue`

  Used only for utility methods. Types allowed as `Value` generic type to `KeyPath` utilities.

  #### Declaration

  Swift

      public protocol AllowedObjectiveCRelationshipKeyPathValue : AllowedOptionalObjectiveCKeyPathValue

### AllowedObjectiveCToManyRelationshipKeyPathValue

- `AllowedObjectiveCToManyRelationshipKeyPathValue`

  Used only for utility methods. Types allowed as `Value` generic type to `KeyPath` utilities.

  #### Declaration

  Swift

      public protocol AllowedObjectiveCToManyRelationshipKeyPathValue : AllowedOptionalObjectiveCKeyPathValue

### KeyPathStringConvertible

- `KeyPathStringConvertible`

  Used only for utility methods.

  See more

  #### Declaration

  Swift

      public protocol KeyPathStringConvertible : AnyKeyPathStringConvertible

### AttributeKeyPathStringConvertible

- `AttributeKeyPathStringConvertible`

  Used only for utility methods.

  See more

  #### Declaration

  Swift

      public protocol AttributeKeyPathStringConvertible : KeyPathStringConvertible

### RelationshipKeyPathStringConvertible

- `RelationshipKeyPathStringConvertible`

  Used only for utility methods.

  See more

  #### Declaration

  Swift

      public protocol RelationshipKeyPathStringConvertible : KeyPathStringConvertible

### ToManyRelationshipKeyPathStringConvertible

- `ToManyRelationshipKeyPathStringConvertible`

  Used only for utility methods.

  #### Declaration

  Swift

      public protocol ToManyRelationshipKeyPathStringConvertible : RelationshipKeyPathStringConvertible where Self.ReturnValueType : Sequence

### ListObserver

- `ListObserver`

  Implement the `ListObserver` protocol to observe changes to a list of `NSManagedObject`s. `ListObserver`s may register themselves to a `ListMonitor`‘s `addObserver(_:)` method:

      let monitor = dataStack.monitorList(
          From<Person>(),
          OrderBy(.ascending("lastName"))
      )
      monitor.addObserver(self)

  See more

  #### Declaration

  Swift

      public protocol ListObserver : AnyObject

### ListObjectObserver

- `ListObjectObserver`

  Implement the `ListObjectObserver` protocol to observe detailed changes to a list’s object. `ListObjectObserver`s may register themselves to a `ListMonitor`‘s `addObserver(_:)` method:

      let monitor = dataStack.monitorList(
          From<MyPersonEntity>(),
          OrderBy(.ascending("lastName"))
      )
      monitor.addObserver(self)

  See more

  #### Declaration

  Swift

      public protocol ListObjectObserver : ListObserver

### ListSectionObserver

- `ListSectionObserver`

  Implement the `ListSectionObserver` protocol to observe changes to a list’s section info. `ListSectionObserver`s may register themselves to a `ListMonitor`‘s `addObserver(_:)` method:

      let monitor = dataStack.monitorSectionedList(
          From<MyPersonEntity>(),
          SectionBy("age") { "Age \($0)" },
          OrderBy(.ascending("lastName"))
      )
      monitor.addObserver(self)

  See more

  #### Declaration

  Swift

      public protocol ListSectionObserver : ListObjectObserver

### ObjectObserver

- `ObjectObserver`

  Implement the `ObjectObserver` protocol to observe changes to a single `DynamicObject` instance. `ObjectObserver`s may register themselves to an `ObjectMonitor`‘s `addObserver(_:)` method:

      let monitor = dataStack.monitorObject(object)
      monitor.addObserver(self)

  See more

  #### Declaration

  Swift

      public protocol ObjectObserver : AnyObject

### AnyObjectRepresentation

- `AnyObjectRepresentation`

  Used internally by CoreStore. Do not conform to directly.

  See more

  #### Declaration

  Swift

      public protocol AnyObjectRepresentation

- `ObjectRepresentation`

  An object that acts as interfaces for `CoreStoreObject`s or `NSManagedObject`s

  See more

  #### Declaration

  Swift

      public protocol ObjectRepresentation : AnyObjectRepresentation

### OrderByClause

- `OrderByClause`

  Abstracts the `OrderBy` clause for protocol utilities.

  See more

  #### Declaration

  Swift

      public protocol OrderByClause

### QueryChainableBuilderType

- `QueryChainableBuilderType`

  Utility protocol for `QueryChainBuilder`. Used in fetch methods that support chained query builders.

  See more

  #### Declaration

  Swift

      public protocol QueryChainableBuilderType

### QueryableAttributeType

- `QueryableAttributeType`

  Types supported by CoreStore for querying, especially as generic type for `Select` clauses. Supported default types:

  - `Bool`
  - `CGFloat`
  - `Data`
  - `Date`
  - `Double`
  - `Float`
  - `Int`
  - `Int8`
  - `Int16`
  - `Int32`
  - `Int64`
  - `NSData`
  - `NSDate`
  - `NSDecimalNumber`
  - `NSManagedObjectID`
  - `NSNull`
  - `NSNumber`
  - `NSString`
  - `NSURL`
  - `NSUUID`
  - `String`
  - `URL`
  - `UUID`

  In addition, `RawRepresentable` types whose `RawValue` already implements `QueryableAttributeType` only need to declare conformance to `QueryableAttributeType`.

  See more

  #### Declaration

  Swift

      public protocol QueryableAttributeType : SelectResultType, Hashable

### QueryableSource

- `QueryableSource`

  Encapsulates containers which manages an internal `NSManagedObjectContext`, such as `DataStack`s and transactions, that can be used for querying values. CoreStore provides implementations for this protocol and should be used as a read-only abstraction.

  See more

  #### Declaration

  Swift

      public protocol QueryableSource : AnyObject

### SchemaMappingProvider

- `SchemaMappingProvider`

  The `SchemaMappingProvider` provides migration mapping information between two `DynamicSchema` versions.

  See more

  #### Declaration

  Swift

      public protocol SchemaMappingProvider

### SectionMonitorBuilderType

- `SectionMonitorBuilderType`

  Utility protocol for `SectionMonitorChainBuilder`. Used in methods that support chained fetch builders.

  See more

  #### Declaration

  Swift

      public protocol SectionMonitorBuilderType

### SelectResultType

- `SelectResultType`

  The `SelectResultType` protocol is implemented by return types supported by the `Select` clause.

  #### Declaration

  Swift

      public protocol SelectResultType

### SelectAttributesResultType

- `SelectAttributesResultType`

  The `SelectAttributesResultType` protocol is implemented by return types supported by the `queryAttributes(...)` methods.

  #### Declaration

  Swift

      public protocol SelectAttributesResultType : SelectResultType

### SelectClause

- `SelectClause`

  Abstracts the `Select` clause for protocol utilities.

  See more

  #### Declaration

  Swift

      public protocol SelectClause

### StorageInterface

- `StorageInterface`

  The `StorageInterface` represents the data store managed (or to be managed) by the `DataStack`. When added to the `DataStack`, the `StorageInterface` serves as the interface for the `NSPersistentStore`. This may be a database file, an in-memory store, etc.

  See more

  #### Declaration

  Swift

      public protocol StorageInterface : AnyObject

### LocalStorage

- `LocalStorage`

  The `LocalStorage` represents `StorageInterface`s that are backed by local files.

  See more

  #### Declaration

  Swift

      public protocol LocalStorage : StorageInterface

### FetchClause

- `FetchClause`

  The `FetchClause` implement clauses used to configure `NSFetchRequest`s.

  #### Declaration

  Swift

      public protocol FetchClause

### QueryClause

- `QueryClause`

  The `QueryClause` implement clauses used to configure `NSFetchRequest`s.

  #### Declaration

  Swift

      public protocol QueryClause : FetchClause

### DeleteClause

- `DeleteClause`

  The `DeleteClause` implement clauses used to configure `NSFetchRequest`s.

  #### Declaration

  Swift

      public protocol DeleteClause : FetchClause

### AnyWhereClause

- `AnyWhereClause`

  Type-erased `Where` clause for protocol utilities.

  See more

  #### Declaration

  Swift

      public protocol AnyWhereClause : DeleteClause, QueryClause

### WhereExpressionTrait

- `WhereExpressionTrait`

  Used only for `Where.Expression` type constraints. Currently supports `SingleTarget` and `CollectionTarget`.

  #### Declaration

  Swift

      public protocol WhereExpressionTrait

### WhereClauseType

- `WhereClauseType`

  Abstracts the `Where` clause for protocol utilities. Typically used only for utility method generic constraints.

  See more

  #### Declaration

  Swift

      public protocol WhereClauseType : AnyWhereClause