ObjectBox.Entityprotocol, or add annotations to them. Then ObjectBox can take care of your entities.
Useras a persistable entity. This will trigger ObjectBox to generate persistence code tailored for this class, even if it does not conform to the
Idtype, or your ID uses the types
Int64, you can use an annotation to mark a particular property as the ID of your entity:
MyEntitywould be replaced with the name of your class), you can also annotate a property of type
Int64as an ID.
Id. The code generator will look for one of these configurations, in the following order
// objectbox: idcomment annotation on the line above the property definition.
var id: Id.
Idtype, if there is only one.
Idtype. 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.
nameannotation 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: transientannotation 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.
staticproperties are always ignored by ObjectBox and do not need to be marked as transient.
// objectbox: indexto create a database index for the corresponding database column. This can greatly improve performance when querying for that property.
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.
Stringproperties 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.
Stringproperty 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.
String,this may require more storage than a hash-based index.
uniqueto enforce that values are unique before an entity is put:
put()operation will abort and throw an
// objectbox: convertannotation 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: backlinkannotation, see the Relations documentation for details.
setup.rbscript should have automatically configured your project to run the code generator when you compile your project, for example using Product > Build in Xcode.