Protocols

The following protocols are available globally.

Embeddable

  • A Embeddable type can be used in a Model as an embedded type. All types embedded in a Model as an embedded(type:) or embeddedCollection(of:) must comform to the Embeddable protocol except for Swift’s Basic types embedded as a collection. A collection of String can be embedded in the Model as embeddedCollection(of: String.self) without needing to conform to Embeddable.

    Warning

    Although this has public access, it is intended for internal & codegen use and should not be used directly by host applications. The behavior of this may change without warning. Though it is not used by host application making any change to these public types should be backward compatible, otherwise it will be a breaking change.
    See more

    Declaration

    Swift

    public protocol Embeddable : Decodable, Encodable

Model

  • All persistent models should conform to the Model protocol.

    See more

    Declaration

    Swift

    public protocol Model : Decodable, Encodable
  • Protocol that represents a Codable Enum that can be persisted and easily integrate with remote APIs since it must have a raw String value.

    That means only enums without associated values can be used as model properties.

    • Example:
    public enum PostStatus: String, EnumPersistable {
        case draft
        case published
    }
    

    Warning

    Although this has public access, it is intended for internal use and should not be used directly by host applications. The behavior of this may change without warning.
    See more

    Declaration

    Swift

    public protocol EnumPersistable : Decodable, Encodable
  • ModelListDecoder provides decoding and list functionality.

    Warning

    Although this has public access, it is intended for internal & codegen use and should not be used directly by host applications. The behavior of this may change without warning. Though it is not used by host application making any change to these public types should be backward compatible, otherwise it will be a breaking change.
    See more

    Declaration

    Swift

    public protocol ModelListDecoder
  • Empty protocol used as a marker to detect when the type is a List

    Warning

    Although this has public access, it is intended for internal & codegen use and should not be used directly by host applications. The behavior of this may change without warning. Though it is not used by host application making any change to these public types should be backward compatible, otherwise it will be a breaking change.

    Declaration

    Swift

    public protocol ModelListMarker
  • Warning

    Although this has public access, it is intended for internal & codegen use and should not be used directly by host applications. The behavior of this may change without warning. Though it is not used by host application making any change to these public types should be backward compatible, otherwise it will be a breaking change.
    See more

    Declaration

    Swift

    public protocol ModelListProvider
  • Protocol used as a marker to detect when the type is a LazyReference. Used to retrieve either the reference or the identifiers of the Model directly, without having load a not loaded LazyReference. This is useful when translating the model object over to the payload required for the underlying storage, such as storing the values in DataStore’s local database or AppSync GraphQL request payload.

    Warning

    Although this has public access, it is intended for internal & codegen use and should not be used directly by host applications. The behavior of this may change without warning. Though it is not used by host application making any change to these public types should be backward compatible, otherwise it will be a breaking change.
    See more

    Declaration

    Swift

    public protocol _LazyReferenceValue
  • Warning

    Although this has public access, it is intended for internal & codegen use and should not be used directly by host applications. The behavior of this may change without warning. Though it is not used by host application making any change to these public types should be backward compatible, otherwise it will be a breaking change.
    See more

    Declaration

    Swift

    public protocol ModelProvider
  • ModelProviderDecoder provides decoding and lazy reference functionality.

    Warning

    Although this has public access, it is intended for internal & codegen use and should not be used directly by host applications. The behavior of this may change without warning. Though it is not used by host application making any change to these public types should be backward compatible, otherwise it will be a breaking change.
    See more

    Declaration

    Swift

    public protocol ModelProviderDecoder
  • Types that conform to the Persistable protocol represent values that can be persisted in a database.

    Core Types that conform to this protocol:

    Warning

    Although this has public access, it is intended for internal use and should not be used directly by host applications. The behavior of this may change without warning.

    Declaration

    Swift

    public protocol Persistable : Encodable
  • Establishes how Model fields should be converted to and from different targets (e.g. SQL and GraphQL).

    Warning

    Although this has public access, it is intended for internal use and should not be used directly by host applications. The behavior of this may change without warning.
    See more

    Declaration

    Swift

    public protocol ModelValueConverter
  • A type that holds internal data in json format

    Internally a JSONValueHolder will have the data stored as a json map. Properties of the type can be retrieved using the function jsonValue(for:) passing in the key of the property.

    Example:

        struct DynamicModel: JSONValueHolder {
            let values: [String: Any]
    
            public func jsonValue(for key: String) -> Any??  {
                return values[key]
            }
         }
    
    See more

    Declaration

    Swift

    public protocol JSONValueHolder
  • AnyModelIdentifierFormat

    Declaration

    Swift

    public protocol AnyModelIdentifierFormat
  • Defines requirements for a model to be identifiable with a unique identifier that can be either a single field or a combination of fields

    See more

    Declaration

    Swift

    public protocol ModelIdentifiable
  • Defines a ModelIdentifier requirements.

    See more

    Declaration

    Swift

    public protocol ModelIdentifierProtocol
  • Represents a property of a Model. PropertyPath is a way of representing the structure of a model with static typing, so developers can reference model properties in queries and other functionality that require them.

    See more

    Declaration

    Swift

    public protocol PropertyPath
  • This is a specialized protocol to indicate the property is a container of other properties, i.e. a struct representing another Model.

    See also

    ModelPath
    See more

    Declaration

    Swift

    public protocol PropertyContainerPath : PropertyPath
  • Supports addition and subtraction of Temporal.Date and Temporal.DateTime with DateUnit

    See more

    Declaration

    Swift

    public protocol DateUnitOperable
  • The TemporalSpec protocol defines an ISO-8601 formatted Date value. Types that conform to this protocol are responsible for providing the parsing and formatting logic with the correct granularity.

    See more

    Declaration

    Swift

    public protocol TemporalSpec
  • Defines a common format for a TemporalSpec unit used in operations. It is a tuple of Calendar.Component, such as .year, and an integer value. Those two are later used in date operations such “4 hours from now” and “2 months ago”.

    See more

    Declaration

    Swift

    @available(*, deprecated, message: "This protocol will be removed in the future.")
    public protocol TemporalUnit
  • Supports addition and subtraction of Temporal.Time and Temporal.DateTime with TimeUnit

    See more

    Declaration

    Swift

    public protocol TimeUnitOperable
  • Declaration

    Swift

    public protocol Evaluable
  • The ModelKey protocol is used to decorate Swift standard’s CodingKey enum with query functions and operators that are used to build query conditions.

    let post = Post.keys
    
    Amplify.DataStore.query(Post.self, where: {
        post.title.contains("[Amplify]")
        .and(post.content.ne(nil))
    })
    

    Using Operators:

    The operators on a ModelKey reference are defined so queries can also be written with Swift operators as well:

    let post = Post.keys
    
    Amplify.DataStore.query(Post.self, where: {
        post.title ~= "[Amplify]" &&
        post.content != nil
    })
    

    Declaration

    Swift

    public protocol ModelKey : QueryFieldOperation, CaseIterable, CodingKey
  • QueryFieldOperation provides functions that creates predicates based on a field name. These functions are matchers that get executed at a later point by specific implementations of the Model filtering logic (e.g. SQL or GraphQL queries).

    Seealso

    QueryField

    Seealso

    ModelKey
    See more

    Declaration

    Swift

    public protocol QueryFieldOperation
  • Protocol that indicates concrete types conforming to it can be used a predicate member.

    Declaration

    Swift

    public protocol QueryPredicate : Evaluable, Encodable
  • Behavior of the Geo category that clients will use

    See more

    Declaration

    Swift

    public protocol GeoCategoryBehavior
  • Geo category plugin

    See more

    Declaration

    Swift

    public protocol GeoCategoryPlugin : GeoCategoryBehavior, Plugin
  • Behavior of the Hub category that clients will use

    See more

    Declaration

    Swift

    public protocol HubCategoryBehavior
  • Declaration

    Swift

    public protocol HubCategoryPlugin : HubCategoryBehavior, Plugin
  • Declaration

    Swift

    public protocol HubPayloadEventNameable
  • Defines a log convenience property, and provides a default implementation that returns a Logger for a category name of String(describing: self)

    See more

    Declaration

    Swift

    public protocol DefaultLogger
  • Declaration

    Swift

    public protocol LoggingCategoryClientBehavior
  • Declaration

    Swift

    public protocol Logger
  • The behavior that all LoggingPlugins provide

    See more

    Declaration

    Swift

    public protocol LoggingCategoryPlugin : LoggingCategoryClientBehavior, Plugin
  • Defines the behaviour of a Notifications subcategory

    Declaration

    Swift

    public protocol NotificationsSubcategoryBehaviour
  • Defines the behaviour of the Push Notifications category that clients will use

    See more

    Declaration

    Swift

    public protocol PushNotificationsCategoryBehaviour : NotificationsSubcategoryBehaviour
  • Defines a plugin that implements the behaviour of the Push Notifications category

    See more

    Declaration

    Swift

    public protocol PushNotificationsCategoryPlugin : Plugin, PushNotificationsCategoryBehaviour
  • protocol describing identified text in an image

    See more

    Declaration

    Swift

    public protocol IdentifiedText
  • Behavior of the Predictions category that clients will use

    See more

    Declaration

    Swift

    public protocol PredictionsCategoryBehavior
  • Declaration

    Swift

    public protocol PredictionsCategoryPlugin : Plugin, PredictionsCategoryBehavior
    • Tag: StorageDownloadDataOperation

    Declaration

    Swift

    public protocol StorageDownloadDataOperation: AmplifyInProcessReportingOperation<
        StorageDownloadDataRequest,
        Progress,
        Data,
        StorageError
    >
  • This operation encapsulates work to download an object from cloud storage to local storage.

    Event descriptions

    • InProcess: Progress - representing the progress of the download. This event will be emitted as controlled by the underlying NSURLSession behavior, but could be multiple times per second. Apps should not rely on Progress to be 1.0 to determine a completed operation
    • Completed: Void - Receipt of a .completed event indicates the download is complete and the file has been successfully stored to the local URL supplied in the original StorageDownloadFileRequest
    • Error: StorageError - Emitted if the download encounters an error.

    • Tag: StorageDownloadFileOperation

    Declaration

    Swift

    public protocol StorageDownloadFileOperation: AmplifyInProcessReportingOperation<
        StorageDownloadFileRequest,
        Progress,
        Void,
        StorageError
    >
    • Tag: StorageGetURLOperation

    Declaration

    Swift

    public protocol StorageGetURLOperation : AmplifyOperation<StorageGetURLRequest, URL, StorageError>
    • Tag: StorageListOperation

    Declaration

    Swift

    public protocol StorageListOperation : AmplifyOperation<StorageListRequest, StorageListResult, StorageError>
    • Tag: StorageRemoveOperation

    Declaration

    Swift

    public protocol StorageRemoveOperation : AmplifyOperation<StorageRemoveRequest, String, StorageError>
    • Tag: StorageUploadDataOperation

    Declaration

    Swift

    public protocol StorageUploadDataOperation: AmplifyInProcessReportingOperation<
        StorageUploadDataRequest,
        Progress,
        String,
        StorageError
    >
    • Tag: StorageUploadFileOperation

    Declaration

    Swift

    public protocol StorageUploadFileOperation: AmplifyInProcessReportingOperation<
        StorageUploadFileRequest,
        Progress,
        String,
        StorageError
    >
  • Behavior of the Storage category used though Amplify.Storage.*. Plugin implementations conform to this protocol indirectly though the StorageCategoryPlugin protocol.

    • Tag: StorageCategoryBehavior
    See more

    Declaration

    Swift

    public protocol StorageCategoryBehavior
    • Tag: StorageCategoryPlugin
    See more

    Declaration

    Swift

    public protocol StorageCategoryPlugin : Plugin, StorageCategoryBehavior
  • An Amplify Category stores certain global states, holds references to plugins for the category, and routes method requests to those plugins appropriately.

    • Tag: Category
    See more

    Declaration

    Swift

    public protocol Category : AnyObject, CategoryTypeable, DefaultLogger
  • The Amplify category with which the conforming type is associated. Categories, Plugins, ClientBehaviors, etc must all share the same CategoryType

    • Tag: CategoryTypeable
    See more

    Declaration

    Swift

    public protocol CategoryTypeable
  • A CategoryConfiguration must contain a plugins field used to configure plugins for that category

    • Tag: CategoryConfiguration
    See more

    Declaration

    Swift

    public protocol CategoryConfiguration : Decodable, Encodable
  • Contains specific data for a User

    See more

    Declaration

    Swift

    public protocol UserProfile
  • Properties of a UserProfile can store values of different common types. This protocol is an encapsulation of said types.

    Currently supported types are String, Int, Double, Bool and Array<String>.

    If the underlying service does not support one of these, it is expected that the plugin will cast it to another supported type. For example, casting a Bool to a String.

    Declaration

    Swift

    public protocol UserProfilePropertyValue
  • Note that although this protocol is public, the reset method is intended only for internal use, and should not be invoked by host applications.

    See more

    Declaration

    Swift

    public protocol Resettable
  • CategoryPlugins implement the behavior defined by the category. The Plugin protocol defines behavior common to all plugins, but each category will also define client API behavior and optionally, plugin API behavior to describe the contract to which the plugin must conform.

    See more

    Declaration

    Swift

    public protocol Plugin : CategoryTypeable, Resettable
  • The conforming type can be initialized with a Plugin. Allows for construction of concrete, type-erasing wrappers to store heterogenous collections of Plugins in a category.

    Throws

    PluginError.mismatchedPlugin if the instance is associated with the wrong category
    See more

    Declaration

    Swift

    public protocol PluginInitializable
  • Amplify’s philosophy is to expose friendly error messages to the customer that assist with debugging. Therefore, failable APIs are declared to return error results with Amplify errors, which require recovery suggestions and error messages.

    • Tag: AmplifyError
    See more

    Declaration

    Swift

    public protocol AmplifyError : CustomDebugStringConvertible, Error
  • Describes the parameters that are passed during the creation of an AmplifyOperation

    See more

    Declaration

    Swift

    public protocol AmplifyOperationRequest
  • Simple task that represents a unit of work and its result.

    See Also: AmplifyInProcessReportingTask

    • Tag: AmplifyTask
    See more

    Declaration

    Swift

    public protocol AmplifyTask
  • Simple task that represents a unit of work and its result and is able to report its progress.

    See Also: AmplifyTask

    • Tag: AmplifyInProcessReportingTask
    See more

    Declaration

    Swift

    public protocol AmplifyInProcessReportingTask
  • Declaration

    Swift

    public protocol BufferingSequence
  • The conforming type supports cancelling an in-process operation. The exact semantics of “canceling” are not defined in the protocol. Specifically, there is no guarantee that a cancel results in immediate cessation of activity.

    See more

    Declaration

    Swift

    public protocol Cancellable

Sequences

Hub Support

Result/Value

Control