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
-
schema
Default implementationA reference to the
ModelSchema
associated with this model.Default Implementation
Warning
Although this haspublic
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 thesepublic
types should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
static var schema: ModelSchema { get }
-
rootPath
Default implementationThe reference to the root path. It might be
nil
if models do not support property references.Default Implementation
The
rootPath
is set tonil
by default. Specific models should override this behavior and provide the proper path reference when available.Declaration
Swift
static var rootPath: PropertyContainerPath? { get }
-
modelName
Default implementationThe name of the model, as registered in
ModelRegistry
.Default Implementation
Declaration
Swift
static var modelName: String { get }
-
modelName
Default 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
-
identifier
Default 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 haspublic
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 thesepublic
types should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
public subscript(key: String) -> Any?? { get }
-
schema
Extension methodWarning
Although this haspublic
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 thesepublic
types should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
public var schema: ModelSchema { get }
-
defineSchema(name:
Extension methodattributes: define: ) Utility function that enables a DSL-like
ModelSchema
definition. 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
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.Declaration
Swift
public static func defineSchema(name: String? = nil, attributes: ModelAttribute..., define: (inout ModelSchemaDefinition) -> Void) -> ModelSchema
Return Value
a valid
ModelSchema
instance -
rule(allow:
Extension methodownerField: identityClaim: groupClaim: groups: groupsField: provider: operations: ) Warning
Although this haspublic
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.Declaration
Swift
public 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
Model
protocol.Throws
DecodingError.dataCorrupted
in case data is not a valid JSON or any other decoding specific error thatJSONDecoder.decode()
might throw.Warning
Although this haspublic
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 thesepublic
types should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
public static func from(json: String, decoder: JSONDecoder? = nil) throws -> Self
Parameters
json
a valid JSON object as
String
decoder
an 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
Dictionary
into an instance of the concrete type that conforms to theModel
protocol.Throws
DecodingError.dataCorrupted
in case data is not a valid JSON or any other decoding specific error thatJSONDecoder.decode()
might throw.Warning
Although this haspublic
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 thesepublic
types should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
public static func from(dictionary: [String : Any]) throws -> Self
Parameters
dictionary
containing 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
Model
instance to a JSON object asString
.Warning
Although this haspublic
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 thesepublic
types should be backward compatible, otherwise it will be a breaking change.Declaration
Swift
public func toJSON(encoder: JSONEncoder? = nil) throws -> String
Parameters
encoder
an 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