ObjectBox.Entity
protocol, or add annotations to them. Then ObjectBox can take care of your entities.User
as a persistable entity. This will trigger ObjectBox to generate persistence code tailored for this class, even if it does not conform to the Entity
protocol..Id
type, or your ID uses the types UInt64
or Int64
, you can use an annotation to mark a particular property as the ID of your entity:Id
or EntityId<MyEntity>
(where MyEntity
would be replaced with the name of your class), you can also annotate a property of type UInt64
or Int64
as an ID.Id
. The code generator will look for one of these configurations, in the following order// objectbox: id
comment annotation on the line above the property definition.var id: Id
.Id
type, if there is only one.Id
type. Use ObjectBox's support for object relations if you need to connect entities with each other. In any case, should you need to store a reference to another object for an unusual purpose, simply use annotations to ensure ObjectBox uses the right property as the entity's ID.Id
, you can also use the more type-safe EntityId<ExampleEntity>
struct (where ExampleEntity
is the class of your entity), which will let you ensure that you don't accidentally pass an ID of the wrong type into Box API.UInt64
or Int64
for your IDs, but for ObjectBox to know to use those, you must annotate them.name
annotation lets you define a name on the database level for a property. This allows you to rename the Swift field without affecting the property name on the database level. This is mostly useful in cross-platform code, where different platforms may have different conventions for property names and you need to exchange database files between them.// objectbox: transient
annotation can be used to mark properties that should not be persisted, like the temporary counter above. As far as ObjectBox is concerned, transient properties simply do not exist. static
properties are always ignored by ObjectBox and do not need to be marked as transient.// objectbox: index
to create a database index for the corresponding database column. This can greatly improve performance when querying for that property.Data
, Float
and Double
Array<>
. For example you could store persons using an Array<Person>
. Now, you want to search for all persons with a specific name so you would iterate through the list and check for the name property of each object. This is an O(N) operation and thus does not scale well with an increasing number of objects.Dictionary<String, Person>
with the name as a key. This will give you a superfast lookup time (typically O(1)). The downside of this is that it needs more resources (here: RAM) and slows down add/remove operations on the list a bit. These principles can be transferred to database indexes, just that the primary resource consumed is disk space.String
properties typically take more space than scalar values, ObjectBox uses a hash for indexing strings by default. For any other type, the property value is used for all index look-ups.String
property by specifying an index type:String
, depending on the length of your values, a value-based index may require more storage space than the default hash-based index.hash
for String
, value
for others).String,
this may require more storage than a hash-based index.unique
to enforce that values are unique before an entity is put:put()
operation will abort and throw an ObjectBoxError.uniqueViolation
error:index
annotation.// objectbox: convert
annotation to properties with types that ObjectBox does not know to allow converting it into a recognized type. See Enums and Custom Types for more.// objectbox: backlink
annotation, see the Relations documentation for details.setup.rb
script should have automatically configured your project to run the code generator when you compile your project, for example using Product > Build in Xcode.