Model
public protocol Model : Decodable, Encodable
All persistent models should conform to the Model protocol.
-
Alias of Model identifier (i.e. primary key)
Declaration
Swift
@available(*, deprecated, message: "Use ModelIdentifier") typealias Identifier = String -
schemaDefault implementationA reference to the
ModelSchemaassociated with this model.Default Implementation
Warning
Although this haspublicaccess, 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 thesepublictypes should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
static var schema: ModelSchema { get } -
rootPathDefault implementationThe reference to the root path. It might be
nilif models do not support property references.Default Implementation
The
rootPathis set tonilby default. Specific models should override this behavior and provide the proper path reference when available.Declaration
Swift
static var rootPath: PropertyContainerPath? { get } -
modelNameDefault implementationThe name of the model, as registered in
ModelRegistry.Default Implementation
Declaration
Swift
static var modelName: String { get } -
modelNameDefault implementationConvenience property to return the Type’s
modelName. Developers are strongly encouraged not to override the instance property, as an implementation that returns a different value for the instance property will cause undefined behavior.Default Implementation
Declaration
Swift
var modelName: String { get } -
identifier(schema:Default implementation) For internal use only when a model schema is provided (i.e. calls from Flutter)
Default Implementation
Declaration
Swift
func identifier(schema: ModelSchema) -> ModelIdentifierProtocol -
identifierDefault implementationConvenience property to access the serialized value of a model identifier
Default Implementation
Declaration
Swift
var identifier: String { get } -
subscript(_:Extension method) Warning
Although this haspublicaccess, 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 thesepublictypes should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
subscript(key: String) -> Any?? { get } -
schemaExtension methodWarning
Although this haspublicaccess, 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 thesepublictypes should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
var schema: ModelSchema { get } -
defineSchema(name:Extension methodattributes: define: ) Utility function that enables a DSL-like
ModelSchemadefinition. Instead of building objects individually, developers can use this to create the schema with a more fluid programming model.Example:
static let schema = defineSchema { model in model.fields( .field(name: "title", is: .required, ofType: .string) ) }Parameters
- name: the name of the Model. Defaults to the class name
- attributes: model attributes (aka “directives” or “annotations”)
- define: the closure used to define the model attributes and fields
Warning
Although this has
publicaccess, it is intended for internal & codegen use and should not be used directly by host applications. The behavior of this may change without warning.Declaration
Swift
static func defineSchema( name: String? = nil, attributes: ModelAttribute..., define: (inout ModelSchemaDefinition) -> Void ) -> ModelSchemaReturn Value
a valid
ModelSchemainstance -
rule(allow:Extension methodownerField: identityClaim: groupClaim: groups: groupsField: provider: operations: ) Warning
Although this haspublicaccess, it is intended for internal & codegen use and should not be used directly by host applications. The behavior of this may change without warning.Declaration
Swift
static func rule( allow: AuthStrategy, ownerField: String? = nil, identityClaim: String? = nil, groupClaim: String? = nil, groups: [String] = [], groupsField: String? = nil, provider: AuthRuleProvider? = nil, operations: [ModelOperation] = [] ) -> AuthRule
-
from(json:Extension methoddecoder: ) De-serialize a JSON string into an instance of the concrete type that conforms to the
Modelprotocol.Throws
DecodingError.dataCorruptedin case data is not a valid JSON or any other decoding specific error thatJSONDecoder.decode()might throw.Warning
Although this haspublicaccess, 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 thesepublictypes should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
static func from( json: String, decoder: JSONDecoder? = nil ) throws -> SelfParameters
jsona valid JSON object as
Stringdecoderan optional JSONDecoder to use to decode the model. Defaults to
JSONDecoder(), using a custom date formatter that decodes ISO8601 dates both with and without fractional secondsReturn Value
an instance of the concrete type conforming to
Model -
from(dictionary:Extension method) De-serialize a
Dictionaryinto an instance of the concrete type that conforms to theModelprotocol.Throws
DecodingError.dataCorruptedin case data is not a valid JSON or any other decoding specific error thatJSONDecoder.decode()might throw.Warning
Although this haspublicaccess, 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 thesepublictypes should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
static func from(dictionary: [String : Any]) throws -> SelfParameters
dictionarycontaining keys and values that match the target type
Return Value
an instance of the concrete type conforming to
Model -
toJSON(encoder:Extension method) Converts the
Modelinstance to a JSON object asString.Warning
Although this haspublicaccess, 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 thesepublictypes should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
func toJSON(encoder: JSONEncoder? = nil) throws -> StringParameters
encoderan optional JSONEncoder to use to encode the model. Defaults to
JSONEncoder(), using a custom date formatter that encodes ISO8601 dates with fractional secondsReturn Value
the JSON representation of the
Model
View on GitHub