Core
-
The Store represents an ObjectBox database on the local disk. For each persisted object type, you can obtain a
Boxinstance with thebox(for:)method. Boxes provide the interfaces for object persistence.A typical setup sequence looks like this:
let store = try Store(directoryPath: pathToStoreData) let personBox = store.box(for: Person.self) let persons = try personBox.all()See moreNote
You must run the code generator by building at least once to create a Store initializer according to your data model. This generated initializer does not have a “model” parameter (that one is an internal initializer), and comes with convenient defaults for its named parameters.Declaration
Swift
public class Store : CustomDebugStringConvertible -
Declaration
Swift
public class Box<E: EntityInspectable & __EntityRelatable>: CustomDebugStringConvertible where E == E.EntityBindingType.EntityType -
Optional protocol to signal the ObjectBox code generator that a class/struct is an entity (part of the persisted ObjectBox data model).
class Person: Entity { var id: Id = 0 init() { } }While not enforced by this protocol, adopting classes or structs must at least provide an ID property of type
Id. Classes must also provide a no-argument constructor, likeinit()and all persisted properties must be mutable. For structs, a constructor that accepts all persisted properties must be available.Instead of adopting this protocol, an annotation can be used:
// objectbox: entity class Person { var id: Id = 0 init() { } }Persisted Properties
All properties that have a supported type are persisted.
For numbers, ObjectBox supports
Bool,Int8,Int16,Int32,Int64,Intand their unsigned variants, as well asFloatandDouble.It also recognizes
String,[String],DateandData(the latter of which may also be written as[UInt8]).Relations
To create relations between entities, use
ToOneandToManyto wrap the target type, likecustomer: ToOne<Customer>.More information
For more details see the documentation.
Declaration
Swift
public protocol Entity -
Identifier (ID) for objects (instances of an entity) stored in ObjectBox.
Each entity class/struct must have an ID property. IDs are assigned by the framework automatically when persisting objects with
Box.put.A value of
0indicates the object hasn’t been persisted, yet.Declaration
Swift
public typealias Id = UInt64 -
Metadata of object properties, used by the framework to determine how to store the values.
These are created by the code generator for you.
Usually, you only deal with this class when writing queries. The property names you use in your queries are actually instances of Property, and you can use operators and comparison methods like isLessThan() on them to express your queries. Below you see a list of methods that are available to you for property queries, apart from the operators described under Query Syntax.
See moreDeclaration
Swift
public struct Property<E: EntityInspectable & __EntityRelatable, V: EntityPropertyTypeConvertible, R> where E == E.EntityBindingType.EntityType
View on GitHub
Install in Dash
Core Reference