Core

  • The Store represents an ObjectBox database on the local disk. For each persisted object type, you can obtain a Box instance with the box(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()
    

    Note

    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.
    See more

    Declaration

    Swift

    public class Store : CustomDebugStringConvertible
  • Box

    A box to store objects of a particular type.

    Thread-safe.

    See more

    Declaration

    Swift

    public class Box<E: EntityInspectable & __EntityRelatable>: CustomDebugStringConvertible
    where E == E.EntityBindingType.EntityType
  • Base protocol of anything you want to persist in a box.

    Persisted Properties

    All stored properties of a type that conforms to Entity will be persisted, if possible. For numbers, ObjectBox recognizes Bool, Int8, Int16, Int32, Int64, Int (plus their unsigned variants), Float, and Double. It also recognizes String, Date and Data (the latter of which may also be written as [UInt8]).

    Relations

    To create relations between entities, use ToOne and ToMany to wrap the target type, like customer: ToOne<Customer>.

    Informal requirements: It is assumed that classes implementing this have an init() method and all properties to be serialized are mutable. For struct types, it is assumed that an init method exists that accepts all properties to be serialized.

    Declaration

    Swift

    public protocol Entity
  • Id

    Declaration

    Swift

    extension Id: UntypedIdBase
  • 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 more

    Declaration

    Swift

    public struct Property<E: EntityInspectable & __EntityRelatable, V: EntityPropertyTypeConvertible, R>
    where E == E.EntityBindingType.EntityType