Core

  • On-disk store of the boxes for your object types.

    In every app, you have to setup a Store only once and call register(entity:) for each entity type to set the store up. Afterwards, you can obtain Box instances with the box(for:) methods. Boxes provide the interfaces for object persistence.

    The code generator will create a convenience initializer for you to use, with sensible defaults set: Store.init(directoryPath:).

    A typical setup sequence looks like this:

    let store = try Store(directoryPath: pathToStoreData)
    store.register(entity: Person.self)
    let personBox = store.box(for: Person.self)
    let persons = personBox.all()
    
    See more

    Declaration

    Swift

    class Store : NSObject
  • Box

    A box to store objects of a particular type.

    Thread-safe.

    See more

    Declaration

    Swift

    public class Box<E>
    where E: Store.InspectableEntity
  • 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, Float, and Double. It also recognizes String and Date.

    Relations

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

    See more

    Declaration

    Swift

    public protocol Entity : AnyObject
  • Id

    Object identifier type.

    Object identifiers are wrappers for EntityId values which are UInt64. These are used for persisted objects. Identifiers are assigned by the framework automatically when you call Box.put.

    A value of 0 indicates the object hasn’t been persisted, yet.

    See more

    Declaration

    Swift

    public struct Id<E> : IdBase, Hashable where E : Entity
  • Metadata of object properties, used by the framework to determine how to store the values.

    These are created by the code generator for you.

    See more

    Declaration

    Swift

    public struct Property<E, T> where E : Entity, T : EntityPropertyTypeConvertible