EntityBinding
public protocol EntityBinding : AnyObject
The code generator generates concrete instances of EntityBinding objects that perform the actual work of transferring database values into your Swift objects and extracting them for writing out.
As an ObjectBox user, you don’t need to deal with this (directly).
-
The type this binding serves as an adapter for.
Declaration
Swift
associatedtype EntityType : Entity, EntityInspectable
-
The type of the ‘id’ property in EntityType.
Declaration
Swift
associatedtype IdType : IdBase
-
Used by
Box
to create new EntityBinding adapter instances.Declaration
Swift
init()
-
Allows to check for a matching/compatible generator version. Failing this check will raise a fatal error at runtime. This version refers the bindings the generator generates, not the generator version itself. It will only change when there are (relevant) changes in the generated binding.
Version history (with Swift library version which first relied on the version): 1 (1.4 2020-09-07): Added generatorBindingVersion() - you need to update if you get error like this: Type ‘…’ does not conform to protocol ‘EntityBinding’
Declaration
Swift
func generatorBindingVersion() -> Int
-
Writes the given entity’s value to the given FlatBufferBuilder, assigning it the given ID.
entityId
must not be 0.Declaration
Swift
func collect(fromEntity entity: EntityType, id entityId: Id, propertyCollector: FlatBufferBuilder, store: Store) throws
-
postPut(fromEntity:id:store:)
Default implementationThe collected entity has been put and now it’s time to attach and put all relations, if this entity is new.
Default Implementation
The collected entity has been put and now it’s time to attach and put all relations, if this entity is new.
Declaration
Swift
func postPut(fromEntity entity: EntityType, id entityId: Id, store: Store) throws
-
Creates a new entity based on data from the given FlatBufferReader. Returns: The new entity.
Declaration
Swift
func createEntity(entityReader: FlatBufferReader, store: Store) -> EntityType
-
setEntityIdUnlessStruct(of:to:)
Default implementationFor class types, this is used to write the new entity ID back to the entity when they are first put into a box. Note that this function only works on classes, it will quietly do nothing when used on a struct.
Default Implementation
Declaration
Swift
func setEntityIdUnlessStruct(of entity: EntityType, to entityId: Id)
-
setStructEntityId(of:to:)
Default implementationFor struct types, this is used to write the new entity ID back to the entity when they are first put into a box. Note that this function only works on structs, it will raise a fatal error when used on a class.
Default Implementation
Declaration
Swift
func setStructEntityId(of entity: inout EntityType, to entityId: Id)
-
Used to read the ID of an entity.
Declaration
Swift
func entityId(of entity: EntityType) -> Id
-
setToOneRelation(_:of:to:)
Default implementationModify a ToOne relation using its property ID, used when modifying
ToOne
backlinks.Default Implementation
Modify a ToOne relation using its property ID, used when modifying
ToOne
backlinks.Declaration
Swift
func setToOneRelation(_ propertyId: obx_schema_id, of entity: EntityType, to entityId: Id?)