# Protocols

The following protocols are available globally.

### CSFetchClause

- `CSFetchClause`

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

  See also

  `FetchClause`

  #### Declaration

  Swift

      @objc
      public protocol CSFetchClause

### CSQueryClause

- `CSQueryClause`

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

  See also

  `QueryClause`

  #### Declaration

  Swift

      @objc
      public protocol CSQueryClause

### CSDeleteClause

- `CSDeleteClause`

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

  See also

  `DeleteClause`

  #### Declaration

  Swift

      @objc
      public protocol CSDeleteClause

### CSDynamicSchema

- `CSDynamicSchema`

  The `CSDynamicSchema` serves as the Objective-C bridging type for `DynamicSchema`.

  See also

  `DynamicSchema`
  See more

  #### Declaration

  Swift

      @objc
      public protocol CSDynamicSchema

### CSListObserver

- `CSListObserver`

  Implement the `CSListObserver` protocol to observe changes to a list of `NSManagedObject`s. `CSListObserver`s may register themselves to a `CSListMonitor`‘s `-addListObserver:` method:

      CSListMonitor *monitor = [CSCoreStore
          monitorListFrom:[CSFrom entityClass:[MyPersonEntity class]]
          fetchClauses:@[[CSOrderBy sortDescriptor:[CSSortKey withKeyPath:@"lastName" ascending:YES]]]];
      [monitor addListObserver:self];

  See also

  `ListObserver`
  See more

  #### Declaration

  Swift

      @available(OSX 10.12, *)
      @objc
      public protocol CSListObserver : AnyObject

### ListObjectObserver

- `CSListObjectObserver`

  Implement the `CSListObjectObserver` protocol to observe detailed changes to a list’s object. `CSListObjectObserver`s may register themselves to a `CSListMonitor`‘s `-addListObjectObserver(_:)` method:

      CSListMonitor *monitor = [CSCoreStore
          monitorListFrom:[CSFrom entityClass:[MyPersonEntity class]]
          fetchClauses:@[[CSOrderBy sortDescriptor:[CSSortKey withKeyPath:@"lastName" ascending:YES]]]];
      [monitor addListObjectObserver:self];

  See also

  `ListObjectObserver`
  See more

  #### Declaration

  Swift

      @available(OSX 10.12, *)
      @objc
      public protocol CSListObjectObserver : CSListObserver

### CSListSectionObserver

- `CSListSectionObserver`

  Implement the `CSListSectionObserver` protocol to observe changes to a list’s section info. `CSListSectionObserver`s may register themselves to a `CSListMonitor`‘s `-addListSectionObserver:` method:

      CSListMonitor *monitor = [CSCoreStore
          monitorSectionedListFrom:[CSFrom entityClass:[MyPersonEntity class]]
          sectionBy:[CSSectionBy keyPath:@"age"]
          fetchClauses:@[[CSOrderBy sortDescriptor:[CSSortKey withKeyPath:@"lastName" ascending:YES]]]];
      [monitor addListSectionObserver:self];

  See also

  `ListSectionObserver`
  See more

  #### Declaration

  Swift

      @available(OSX 10.12, *)
      @objc
      public protocol CSListSectionObserver : CSListObjectObserver

### CSObjectObserver

- `CSObjectObserver`

  Implement the `CSObjectObserver` protocol to observe changes to a single `NSManagedObject` instance. `CSObjectObserver`s may register themselves to a `CSObjectMonitor`‘s `-addObjectObserver:` method:

      CSObjectMonitor *monitor = [CSCoreStore monitorObject:myObject];
      [monitor addObjectObserver:self];

  See also

  `ObjectObserver`
  See more

  #### Declaration

  Swift

      @available(OSX 10.12, *)
      @objc
      public protocol CSObjectObserver : AnyObject

### CSStorageInterface

- `CSStorageInterface`

  The `CSStorageInterface` serves as the Objective-C bridging type for `StorageInterface`.

  See also

  `StorageInterface`
  See more

  #### Declaration

  Swift

      @objc
      public protocol CSStorageInterface

### CSLocalStorage

- `CSLocalStorage`

  The `CSLocalStorage` serves as the Objective-C bridging type for `LocalStorage`.

  See also

  `LocalStorage`
  See more

  #### Declaration

  Swift

      @objc
      public protocol CSLocalStorage : CSStorageInterface

### 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 : AnyObject, NSObjectProtocol

### CoreStoreObjectiveCType

- `CoreStoreObjectiveCType`

  `CoreStoreObjectiveCType`s are Objective-C accessible classes that represent CoreStore’s Swift types.

  See more

  #### Declaration

  Swift

      public protocol CoreStoreObjectiveCType : AnyObject

### CoreStoreSwiftType

- `CoreStoreSwiftType`

  `CoreStoreSwiftType`s are CoreStore’s Swift types that are bridgeable to Objective-C.

  See more

  #### Declaration

  Swift

      public protocol CoreStoreSwiftType

### CoreStoreLogger

- `CoreStoreLogger`

  Custom loggers should implement the `CoreStoreLogger` protocol and pass its instance to `CoreStore.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

### DynamicKeyPath

- `DynamicKeyPath`

  Used only for utility methods.

  See more

  #### Declaration

  Swift

      public protocol DynamicKeyPath : AnyDynamicKeyPath

### 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

### 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

### 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
          // ...
      }

      CoreStore.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
          // ...
      }

      CoreStore.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

### AllowedObjectiveCKeyPathValue

- `AllowedObjectiveCKeyPathValue`

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

  #### 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

### AllowedObjectiveCCollectionKeyPathValue

- `AllowedObjectiveCCollectionKeyPathValue`

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

  #### Declaration

  Swift

      public protocol AllowedObjectiveCCollectionKeyPathValue : AllowedOptionalObjectiveCKeyPathValue

### AllowedCoreStoreObjectKeyPathValue

- `AllowedCoreStoreObjectKeyPathValue`

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

  #### Declaration

  Swift

      public protocol AllowedCoreStoreObjectKeyPathValue : DynamicKeyPath

### AllowedCoreStoreObjectCollectionKeyPathValue

- `AllowedCoreStoreObjectCollectionKeyPathValue`

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

  #### Declaration

  Swift

      public protocol AllowedCoreStoreObjectCollectionKeyPathValue : AllowedCoreStoreObjectKeyPathValue

### 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 = CoreStore.monitorList(
          From<Person>(),
          OrderBy(.ascending("lastName"))
      )
      monitor.addObserver(self)

  See more

  #### Declaration

  Swift

      @available(OSX 10.12, *)
      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 = CoreStore.monitorList(
          From<MyPersonEntity>(),
          OrderBy(.ascending("lastName"))
      )
      monitor.addObserver(self)

  See more

  #### Declaration

  Swift

      @available(OSX 10.12, *)
      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 = CoreStore.monitorSectionedList(
          From<MyPersonEntity>(),
          SectionBy("age") { "Age \($0)" },
          OrderBy(.ascending("lastName"))
      )
      monitor.addObserver(self)

  See more

  #### Declaration

  Swift

      @available(OSX 10.12, *)
      public protocol ListSectionObserver : ListObjectObserver

### ObjectObserver

- `ObjectObserver`

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

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

  See more

  #### Declaration

  Swift

      @available(OSX 10.12, *)
      public protocol ObjectObserver : AnyObject

### 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

      @available(OSX 10.12, *)
      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

### CloudStorage

- `CloudStorage`

  The `CloudStorage` represents `StorageInterface`s that are synchronized from a cloud-based store.

  See more

  #### Declaration

  Swift

      public protocol CloudStorage : 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