CINXE.COM

Store Class Reference

<!DOCTYPE html> <html lang="en"> <head> <title>Store Class Reference</title> <link rel="stylesheet" type="text/css" href="../css/jazzy.css" /> <link rel="stylesheet" type="text/css" href="../css/highlight.css" /> <meta charset='utf-8'> <script src="../js/jquery.min.js" defer></script> <script src="../js/jazzy.js" defer></script> </head> <body> <a name="//apple_ref/swift/Class/Store" class="dashAnchor"></a> <a title="Store Class Reference"></a> <header> <div class="content-wrapper"> <p><a href="../index.html">ObjectBox Docs</a> (81% documented)</p> <p class="header-right"><a href="https://github.com/objectbox/objectbox-swift"><img src="../img/gh.png"/>View on GitHub</a></p> <p class="header-right"><a href="dash-feed://https%3A%2F%2Fobjectbox.io%2Fdocfiles%2Fswift%2Fcurrent%2Fdocsets%2FObjectBox.xml"><img src="../img/dash.png"/>Install in Dash</a></p> </div> </header> <div class="content-wrapper"> <p id="breadcrumbs"> <a href="../index.html">ObjectBox Reference</a> <img id="carat" src="../img/carat.png" /> Store Class Reference </p> </div> <div class="content-wrapper"> <nav class="sidebar"> <ul class="nav-groups"> <li class="nav-group-name"> <a href="../Core.html">Core</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../Classes/Store.html">Store</a> </li> <li class="nav-group-task"> <a href="../Classes/Box.html">Box</a> </li> <li class="nav-group-task"> <a href="../Core.html#/s:9ObjectBox6EntityP">Entity</a> </li> <li class="nav-group-task"> <a href="../Core.html#/s:9ObjectBox2Ida">Id</a> </li> <li class="nav-group-task"> <a href="../Structs/Property.html">Property</a> </li> </ul> </li> <li class="nav-group-name"> <a href="../Relations.html">Relations</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../Classes/ToOne.html">ToOne</a> </li> <li class="nav-group-task"> <a href="../Classes/ToMany.html">ToMany</a> </li> </ul> </li> <li class="nav-group-name"> <a href="../Query.html">Query</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../query-syntax.html">Query Syntax</a> </li> <li class="nav-group-task"> <a href="../Classes/Query.html">Query</a> </li> <li class="nav-group-task"> <a href="../Classes/PropertyQuery.html">PropertyQuery</a> </li> <li class="nav-group-task"> <a href="../Classes/PropertyQueryCondition.html">PropertyQueryCondition</a> </li> <li class="nav-group-task"> <a href="../Classes/QueryCondition.html">QueryCondition</a> </li> <li class="nav-group-task"> <a href="../Classes/PropertyAlias.html">PropertyAlias</a> </li> </ul> </li> <li class="nav-group-name"> <a href="../Sync.html">Sync</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../Classes/Sync.html">Sync</a> </li> <li class="nav-group-task"> <a href="../Protocols/SyncClient.html">SyncClient</a> </li> <li class="nav-group-task"> <a href="../Classes/SyncCredentials.html">SyncCredentials</a> </li> </ul> </li> <li class="nav-group-name"> <a href="../Other%20Classes.html">Other Classes</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../Classes/AsyncBox.html">AsyncBox</a> </li> <li class="nav-group-task"> <a href="../Classes/BoxPublisher.html">BoxPublisher</a> </li> <li class="nav-group-task"> <a href="../Classes/EntityBuilder.html">EntityBuilder</a> </li> <li class="nav-group-task"> <a href="../Classes/EntityInfo.html">EntityInfo</a> </li> <li class="nav-group-task"> <a href="../Classes/FlatBufferBuilder.html">FlatBufferBuilder</a> </li> <li class="nav-group-task"> <a href="../Classes/IdWithScore.html">IdWithScore</a> </li> <li class="nav-group-task"> <a href="../Classes/ModelBuilder.html">ModelBuilder</a> </li> <li class="nav-group-task"> <a href="../Classes/ObjectWithScore.html">ObjectWithScore</a> </li> <li class="nav-group-task"> <a href="../Classes/Observer.html">Observer</a> </li> <li class="nav-group-task"> <a href="../Classes/Observer/Flags.html">– Flags</a> </li> <li class="nav-group-task"> <a href="../Classes/PropertyBuilder.html">PropertyBuilder</a> </li> <li class="nav-group-task"> <a href="../Classes/QueryBuilder.html">QueryBuilder</a> </li> <li class="nav-group-task"> <a href="../Classes/QueryPublisher.html">QueryPublisher</a> </li> </ul> </li> <li class="nav-group-name"> <a href="../Other%20Enums.html">Other Enumerations</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../Enums/DebugFlags.html">DebugFlags</a> </li> <li class="nav-group-task"> <a href="../Enums/EntityFlags.html">EntityFlags</a> </li> <li class="nav-group-task"> <a href="../Enums/HnswDistanceType.html">HnswDistanceType</a> </li> <li class="nav-group-task"> <a href="../Enums/HnswFlags.html">HnswFlags</a> </li> <li class="nav-group-task"> <a href="../Enums/ObjectBoxError.html">ObjectBoxError</a> </li> <li class="nav-group-task"> <a href="../Enums/OrderFlags.html">OrderFlags</a> </li> <li class="nav-group-task"> <a href="../Enums/PropertyFlags.html">PropertyFlags</a> </li> <li class="nav-group-task"> <a href="../Enums/PropertyType.html">PropertyType</a> </li> <li class="nav-group-task"> <a href="../Enums/PutMode.html">PutMode</a> </li> <li class="nav-group-task"> <a href="../Enums/PutPaddingMode.html">PutPaddingMode</a> </li> <li class="nav-group-task"> <a href="../Enums/RequestUpdatesMode.html">RequestUpdatesMode</a> </li> <li class="nav-group-task"> <a href="../Enums/SuccessTimeOut.html">SuccessTimeOut</a> </li> <li class="nav-group-task"> <a href="../Enums/SyncCode.html">SyncCode</a> </li> <li class="nav-group-task"> <a href="../Enums/SyncCredentialsType.html">SyncCredentialsType</a> </li> <li class="nav-group-task"> <a href="../Enums/SyncState.html">SyncState</a> </li> <li class="nav-group-task"> <a href="../Enums/ValidateOnOpenMode.html">ValidateOnOpenMode</a> </li> </ul> </li> <li class="nav-group-name"> <a href="../Other%20Extensions.html">Other Extensions</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../Other%20Extensions.html#/s:9ObjectBox2Ida">Id</a> </li> <li class="nav-group-task"> <a href="../Other%20Extensions.html#/s:s5Int64V">Int64</a> </li> </ul> </li> <li class="nav-group-name"> <a href="../Other%20Functions.html">Other Functions</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../Other%20Functions.html#/s:9ObjectBox2zeoiyAA13PropertyAliasCyxq_GSS_AA0D14QueryConditionCyxq_GtAA17EntityInspectableRzAA02__H9RelatableRz0H11BindingTypeAaIP_0hL0QZRszAA0hdL11ConvertibleR_r0_lF">.=(_:_:)</a> </li> <li class="nav-group-task"> <a href="../Other%20Functions.html#/s:9ObjectBox003jJgoiyAA22PropertyQueryConditionCyxq_GAA0C0Vyxq_SgytG_Sayq_GtAA17EntityInspectableRzAA02__F9RelatableRz0F11BindingTypeAaKP_0fJ0QZRszAA0fcJ11ConvertibleR_s17FixedWidthIntegerR_r0_lF">∈(_:_:)</a> </li> <li class="nav-group-task"> <a href="../Other%20Functions.html#/s:9ObjectBox003jJgoiyAA22PropertyQueryConditionCyxq_GAA0C0Vyxq_ytG_Sayq_GtAA17EntityInspectableRzAA02__F9RelatableRz0F11BindingTypeAaJP_0fJ0QZRszAA0fcJ11ConvertibleR_s17FixedWidthIntegerR_r0_lF">∈(_:_:)</a> </li> </ul> </li> <li class="nav-group-name"> <a href="../Other%20Protocols.html">Other Protocols</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../Protocols/EntityBinding.html">EntityBinding</a> </li> <li class="nav-group-task"> <a href="../Protocols/EntityInspectable.html">EntityInspectable</a> </li> <li class="nav-group-task"> <a href="../Protocols/IdBase.html">IdBase</a> </li> <li class="nav-group-task"> <a href="../Other%20Protocols.html#/s:9ObjectBox18SyncChangeListenerP">SyncChangeListener</a> </li> <li class="nav-group-task"> <a href="../Protocols/SyncCompletedListener.html">SyncCompletedListener</a> </li> <li class="nav-group-task"> <a href="../Protocols/SyncConnectionListener.html">SyncConnectionListener</a> </li> <li class="nav-group-task"> <a href="../Other%20Protocols.html#/s:9ObjectBox12SyncListenerP">SyncListener</a> </li> <li class="nav-group-task"> <a href="../Protocols/SyncLoginListener.html">SyncLoginListener</a> </li> <li class="nav-group-task"> <a href="../Other%20Protocols.html#/s:9ObjectBox13UntypedIdBaseP">UntypedIdBase</a> </li> </ul> </li> <li class="nav-group-name"> <a href="../Other%20Structs.html">Other Structures</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../Structs/EntityId.html">EntityId</a> </li> <li class="nav-group-task"> <a href="../Structs/FlatBufferReader.html">FlatBufferReader</a> </li> <li class="nav-group-task"> <a href="../Other%20Structs.html#/s:9ObjectBox10SyncChangeV">SyncChange</a> </li> <li class="nav-group-task"> <a href="../Structs/ToManyProperty.html">ToManyProperty</a> </li> <li class="nav-group-task"> <a href="../Structs/ToManyProperty/ToManyId.html">– ToManyId</a> </li> </ul> </li> <li class="nav-group-name"> <a href="../Other%20Typealiases.html">Other Type Aliases</a> <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="../Other%20Typealiases.html#/s:9ObjectBox13ValuePropertya">ValueProperty</a> </li> </ul> </li> <li class="nav-group-name"> Links <ul class="nav-group-tasks"> <li class="nav-group-task"> <a href="https://objectbox.io">objectbox.io</a> </li> <li class="nav-group-task"> <a href="https://swift.objectbox.io">Guides</a> </li> <li class="nav-group-task"> <a href="https://github.com/objectbox/objectbox-swift">ObjectBox Github</a> </li> </ul> </li> </ul> </nav> <article class="main-content"> <section> <section class="section"> <h1>Store</h1> <div class="declaration"> <div class="language"> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">Store</span> <span class="p">:</span> <span class="kt">CustomDebugStringConvertible</span></code></pre> </div> </div> <p>The Store represents an ObjectBox database on the local disk. For each persisted object type, you can obtain a <code><a href="../Classes/Box.html">Box</a></code> instance with the <code>box(for:)</code> method. Boxes provide the interfaces for object persistence.</p> <p>A typical setup sequence looks like this:</p> <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">store</span> <span class="o">=</span> <span class="k">try</span> <span class="kt">Store</span><span class="p">(</span><span class="nv">directoryPath</span><span class="p">:</span> <span class="n">pathToStoreData</span><span class="p">)</span> <span class="k">let</span> <span class="nv">personBox</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="nf">box</span><span class="p">(</span><span class="nv">for</span><span class="p">:</span> <span class="kt">Person</span><span class="o">.</span><span class="k">self</span><span class="p">)</span> <span class="k">let</span> <span class="nv">persons</span> <span class="o">=</span> <span class="k">try</span> <span class="n">personBox</span><span class="o">.</span><span class="nf">all</span><span class="p">()</span> </code></pre> <div class="aside aside-note"> <p class="aside-title">Note</p> 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 &ldquo;model&rdquo; parameter (that one is an internal initializer), and comes with convenient defaults for its named parameters. </div> </section> <section class="section task-group-section"> <div class="task-group"> <ul> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC13directoryPathSSvp"></a> <a name="//apple_ref/swift/Property/directoryPath" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC13directoryPathSSvp">directoryPath</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>The path to the directory containing our database files as it was passed to this instance when creating it.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">internal(set)</span> <span class="kd">public</span> <span class="k">var</span> <span class="nv">directoryPath</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC7versionSSvpZ"></a> <a name="//apple_ref/swift/Variable/version" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC7versionSSvpZ">version</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Returns the version of ObjectBox Swift.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="k">var</span> <span class="nv">version</span><span class="p">:</span> <span class="kt">String</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC14inMemoryPrefixSSvpZ"></a> <a name="//apple_ref/swift/Variable/inMemoryPrefix" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC14inMemoryPrefixSSvpZ">inMemoryPrefix</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Pass this together with a String identifier as the directory path to use a file-less in-memory database.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="k">let</span> <span class="nv">inMemoryPrefix</span><span class="p">:</span> <span class="kt">String</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC10versionAllSSvpZ"></a> <a name="//apple_ref/swift/Variable/versionAll" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC10versionAllSSvpZ">versionAll</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Returns the versions of ObjectBox Swift, the ObjectBox lib, and ObjectBox core.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="k">var</span> <span class="nv">versionAll</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC15versionFullInfoSSvpZ"></a> <a name="//apple_ref/swift/Variable/versionFullInfo" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC15versionFullInfoSSvpZ">versionFullInfo</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Returns the product name (&ldquo;ObjectBox Swift&rdquo;) along with all versions (see versionAll()).</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="k">var</span> <span class="nv">versionFullInfo</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC10versionLibSSvpZ"></a> <a name="//apple_ref/swift/Variable/versionLib" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC10versionLibSSvpZ">versionLib</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Returns the version of ObjectBox lib (C API).</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="k">var</span> <span class="nv">versionLib</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC11versionCoreSSvpZ"></a> <a name="//apple_ref/swift/Variable/versionCore" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC11versionCoreSSvpZ">versionCore</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Returns the version of ObjectBox core (&ldquo;internal&rdquo; version).</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="k">var</span> <span class="nv">versionCore</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC8attachTo9directoryACSS_tKFZ"></a> <a name="//apple_ref/swift/Method/attachTo(directory:)" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC8attachTo9directoryACSS_tKFZ">attachTo(directory:)</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Attaches to a previously opened Store given its directory.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="kd">func</span> <span class="nf">attachTo</span><span class="p">(</span><span class="nv">directory</span><span class="p">:</span> <span class="kt">String</span><span class="p">)</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">Store</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC6isOpen9directorySbSS_tKFZ"></a> <a name="//apple_ref/swift/Method/isOpen(directory:)" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC6isOpen9directorySbSS_tKFZ">isOpen(directory:)</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Returns if an open store (i.e. opened before and not yet closed) was found for the given <code>directory</code>.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="kd">func</span> <span class="nf">isOpen</span><span class="p">(</span><span class="nv">directory</span><span class="p">:</span> <span class="kt">String</span><span class="p">)</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC5model9directory16maxDbSizeInKByte8fileMode0F7Readers8readOnlyACs13OpaquePointerV_SSs6UInt64Vs6UInt32VAOSbtKcfc"></a> <a name="//apple_ref/swift/Method/init(model:directory:maxDbSizeInKByte:fileMode:maxReaders:readOnly:)" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC5model9directory16maxDbSizeInKByte8fileMode0F7Readers8readOnlyACs13OpaquePointerV_SSs6UInt64Vs6UInt32VAOSbtKcfc">init(model:directory:maxDbSizeInKByte:fileMode:maxReaders:readOnly:)</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Creates a store using the given model definition. In most cases, you would want to use the initializer without the model argument created by the code generator instead.</p> <h1 id='in-memory-database' class='heading'>In-memory database</h1> <p>To use a file-less in-memory database, instead of a directory path pass <code>memory:</code> together with an identifier string:</p> <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">inMemoryStore</span> <span class="o">=</span> <span class="k">try</span> <span class="kt">Store</span><span class="p">(</span><span class="nv">directoryPath</span><span class="p">:</span> <span class="s">"memory:test-db"</span><span class="p">)</span> </code></pre> <div class="aside aside-important"> <p class="aside-title">Important</p> <p>This initializer should only be used internally. Instead, use the generated initializer without the model parameter (trigger code generation if you don&rsquo;t see it yet).</p> </div> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">(</span><span class="nv">model</span><span class="p">:</span> <span class="kt">OpaquePointer</span><span class="p">,</span> <span class="nv">directory</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">"objectbox"</span><span class="p">,</span> <span class="nv">maxDbSizeInKByte</span><span class="p">:</span> <span class="kt">UInt64</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span><span class="p">,</span> <span class="nv">fileMode</span><span class="p">:</span> <span class="kt">UInt32</span> <span class="o">=</span> <span class="mo">0o644</span><span class="p">,</span> <span class="nv">maxReaders</span><span class="p">:</span> <span class="kt">UInt32</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">readOnly</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kc">false</span><span class="p">)</span> <span class="k">throws</span></code></pre> </div> </div> <div> <h4>Parameters</h4> <table class="graybox"> <tbody> <tr> <td> <code> <em>model</em> </code> </td> <td> <div> <p>A model description generated using a <code><a href="../Classes/ModelBuilder.html">ModelBuilder</a></code>.</p> </div> </td> </tr> <tr> <td> <code> <em>directoryPath</em> </code> </td> <td> <div> <p>The directory path in which ObjectBox places its database files for this store, or to use an in-memory database <code>memory:&lt;identifier&gt;</code>.</p> </div> </td> </tr> <tr> <td> <code> <em>maxDbSizeInKByte</em> </code> </td> <td> <div> <p>Limit of on-disk space for the database files. Default is <code>1024 * 1024</code> (1 GiB).</p> </div> </td> </tr> <tr> <td> <code> <em>fileMode</em> </code> </td> <td> <div> <p>UNIX-style bit mask used for the database files; default is <code>0o644</code>. Note: directories become searchable if the &ldquo;read&rdquo; or &ldquo;write&rdquo; permission is set (e.g. 0640 becomes 0750).</p> </div> </td> </tr> <tr> <td> <code> <em>maxReaders</em> </code> </td> <td> <div> <p>The maximum number of readers. &ldquo;Readers&rdquo; are a finite resource for which we need to define a maximum number upfront. The default value is enough for most apps and usually you can ignore it completely. However, if you get the maxReadersExceeded error, you should verify your threading. For each thread, ObjectBox uses multiple readers. Their number (per thread) depends on number of types, relations, and usage patterns. Thus, if you are working with many threads (e.g. in a server-like scenario), it can make sense to increase the maximum number of readers. Note: The internal default is currently around 120. So when hitting this limit, try values around 200-500.</p> </div> </td> </tr> <tr> <td> <code> <em>readOnly</em> </code> </td> <td> <div> <p>Opens the database in read-only mode, i.e. not allowing write transactions.</p> </div> </td> </tr> </tbody> </table> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC5cloneACyKF"></a> <a name="//apple_ref/swift/Method/clone()" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC5cloneACyKF">clone()</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Clone a previously opened store; while a store instance is usable from multiple threads, situations may exist in which cloning a store simplifies the overall lifecycle. E.g. when a store is used for multiple threads and it may only be fully released once the last thread completes. The returned store is a new instance with its own lifetime.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">clone</span><span class="p">()</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">Store</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC3box3forAA0B0CyxGxm_tAA17EntityInspectableRzAA02__F9RelatableRz0F11BindingTypeAaIP_0fJ0QZRszlF"></a> <a name="//apple_ref/swift/Method/box(for:)" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC3box3forAA0B0CyxGxm_tAA17EntityInspectableRzAA02__F9RelatableRz0F11BindingTypeAaIP_0fJ0QZRszlF">box(for:)</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Return a box for reading/writing entities of the given class from/to the database. Obtain a a <code><a href="../Classes/Box.html">Box</a></code> for the given type.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="n">box</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span><span class="p">(</span><span class="k">for</span> <span class="nv">entityType</span><span class="p">:</span> <span class="kt">T</span><span class="o">.</span><span class="k">Type</span> <span class="o">=</span> <span class="kt">T</span><span class="o">.</span><span class="k">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt"><a href="../Classes/Box.html">Box</a></span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span> <span class="k">where</span> <span class="kt">T</span> <span class="p">:</span> <span class="kt"><a href="../Protocols/EntityInspectable.html">EntityInspectable</a></span><span class="p">,</span> <span class="kt">T</span> <span class="p">:</span> <span class="n">__EntityRelatable</span><span class="p">,</span> <span class="kt">T</span> <span class="o">==</span> <span class="kt">T</span><span class="o">.</span><span class="kt">EntityBindingType</span><span class="o">.</span><span class="kt">EntityType</span></code></pre> </div> </div> <div> <h4>Parameters</h4> <table class="graybox"> <tbody> <tr> <td> <code> <em>entityType</em> </code> </td> <td> <div> <p>Object type to get a box for.</p> </div> </td> </tr> </tbody> </table> </div> <div> <h4>Return Value</h4> <p>Box for the given type.</p> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC22closeAndDeleteAllFilesyyKF"></a> <a name="//apple_ref/swift/Method/closeAndDeleteAllFiles()" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC22closeAndDeleteAllFilesyyKF">closeAndDeleteAllFiles()</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Delete the database files on disk, including the database directory.</p> <p>This Store object will not be usable after calling this.</p> <p>For an in-memory database, this will just clean up the in-memory database.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">closeAndDeleteAllFiles</span><span class="p">()</span> <span class="k">throws</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC10syncClientAA04SyncE0_pSgvp"></a> <a name="//apple_ref/swift/Property/syncClient" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC10syncClientAA04SyncE0_pSgvp">syncClient</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>The SyncClient associated with this store. To create one, please check the Sync class and its makeClient().</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">internal(set)</span> <span class="kd">public</span> <span class="k">var</span> <span class="nv">syncClient</span><span class="p">:</span> <span class="kt"><a href="../Protocols/SyncClient.html">SyncClient</a></span><span class="p">?</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre> </div> </div> </section> </div> </li> </ul> </div> <div class="task-group"> <div class="task-name-container"> <a name="/Explicit%20Transactions"></a> <a name="//apple_ref/swift/Section/Explicit Transactions" class="dashAnchor"></a> <a href="#/Explicit%20Transactions"> <h3 class="section-name">Explicit Transactions</h3> </a> </div> <ul> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC16runInTransactionyxxyKXEKlF"></a> <a name="//apple_ref/swift/Method/runInTransaction(_:)" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC16runInTransactionyxxyKXEKlF">runInTransaction(_:)</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Runs the given block inside a read/write transaction.</p> <p>You can e.g. wrap multiple <code>put</code> calls into a single write transaction to ensure a &ldquo;all or nothing&rdquo; semantic. Also, this is more efficient and provides better performance than having one transactions for each operation.</p> <p>You can nest read-only transaction into read/write transactions, but not vice versa.</p> <div class="aside aside-throws"> <p class="aside-title">Throws</p> rethrows errors thrown inside, plus any ObjectBoxError that makes sense. </div> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="n">runInTransaction</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span> <span class="nv">block</span><span class="p">:</span> <span class="p">()</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">T</span><span class="p">)</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">T</span></code></pre> </div> </div> <div> <h4>Parameters</h4> <table class="graybox"> <tbody> <tr> <td> <code> <em>block</em> </code> </td> <td> <div> <p>Code that needs to run in a read/write transaction.</p> </div> </td> </tr> </tbody> </table> </div> <div> <h4>Return Value</h4> <p>The forwarded result of <code>block</code>.</p> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC24runInReadOnlyTransactionyxxyKXEKlF"></a> <a name="//apple_ref/swift/Method/runInReadOnlyTransaction(_:)" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC24runInReadOnlyTransactionyxxyKXEKlF">runInReadOnlyTransaction(_:)</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Runs the given block inside a read(-only) transaction.</p> <p>You can e.g. wrap multiple <code>get</code> calls into a single read transaction to have a single consistent view on data. Also, this is more efficient and provides better performance than having one transactions for each operation.</p> <p>You can nest read-only transaction into read/write transactions, but not vice versa.</p> <div class="aside aside-throws"> <p class="aside-title">Throws</p> rethrows errors thrown inside, plus any ObjectBoxError that makes sense. </div> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="n">runInReadOnlyTransaction</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span> <span class="nv">block</span><span class="p">:</span> <span class="p">()</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">T</span><span class="p">)</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">T</span></code></pre> </div> </div> <div> <h4>Parameters</h4> <table class="graybox"> <tbody> <tr> <td> <code> <em>block</em> </code> </td> <td> <div> <p>Code that needs to run in a read or read/write transaction.</p> </div> </td> </tr> </tbody> </table> </div> <div> <h4>Return Value</h4> <p>The forwarded result of <code>block</code>.</p> </div> </section> </div> </li> </ul> </div> <div class="task-group"> <div class="task-name-container"> <a name="/Async%20helpers"></a> <a name="//apple_ref/swift/Section/Async helpers" class="dashAnchor"></a> <a href="#/Async%20helpers"> <h3 class="section-name">Async helpers</h3> </a> </div> <ul> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC19awaitAsyncSubmittedSbyF"></a> <a name="//apple_ref/swift/Method/awaitAsyncSubmitted()" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC19awaitAsyncSubmittedSbyF">awaitAsyncSubmitted()</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Wait until anything that&rsquo;s been submitted so far for asynchronous execution on any AsyncBox in this store has been processed.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">@discardableResult</span> <span class="kd">public</span> <span class="kd">func</span> <span class="nf">awaitAsyncSubmitted</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre> </div> </div> </section> </div> </li> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC19awaitAsyncCompletedSbyF"></a> <a name="//apple_ref/swift/Method/awaitAsyncCompleted()" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC19awaitAsyncCompletedSbyF">awaitAsyncCompleted()</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>Wait for the async queue used by all AsyncBoxes in this store to become idle because nothing has been queued up for a while.</p> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">@discardableResult</span> <span class="kd">public</span> <span class="kd">func</span> <span class="nf">awaitAsyncCompleted</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre> </div> </div> </section> </div> </li> </ul> </div> <div class="task-group"> <div class="task-name-container"> <a name="/Generated%20initializer"></a> <a name="//apple_ref/swift/Section/Generated initializer" class="dashAnchor"></a> <a href="#/Generated%20initializer"> <h3 class="section-name">Generated initializer</h3> </a> </div> <ul> <li class="item"> <div> <code> <a name="/s:9ObjectBox5StoreC13directoryPath16maxDbSizeInKByte8fileMode0F7Readers8readOnlyACSS_s6UInt64Vs6UInt32VALSbtKcfc"></a> <a name="//apple_ref/swift/Method/init(directoryPath:maxDbSizeInKByte:fileMode:maxReaders:readOnly:)" class="dashAnchor"></a> <a class="token" href="#/s:9ObjectBox5StoreC13directoryPath16maxDbSizeInKByte8fileMode0F7Readers8readOnlyACSS_s6UInt64Vs6UInt32VALSbtKcfc">init(directoryPath:maxDbSizeInKByte:fileMode:maxReaders:readOnly:)</a> </code> </div> <div class="height-container"> <div class="pointer-container"></div> <section class="section"> <div class="pointer"></div> <div class="abstract"> <p>A store with a fully configured model. Created by the code generator with your model&rsquo;s metadata in place.</p> <h1 id='in-memory-database' class='heading'>In-memory database</h1> <p>To use a file-less in-memory database, instead of a directory path pass <code>memory:</code> together with an identifier string:</p> <pre class="highlight swift"><code><span class="k">let</span> <span class="nv">inMemoryStore</span> <span class="o">=</span> <span class="k">try</span> <span class="kt">Store</span><span class="p">(</span><span class="nv">directoryPath</span><span class="p">:</span> <span class="s">"memory:test-db"</span><span class="p">)</span> </code></pre> <div class="aside aside-important"> <p class="aside-title">Important</p> <p>This initializer is created by the code generator. If you only see the internal <code>init(model:...)</code> initializer, trigger code generation by building your project.</p> </div> </div> <div class="declaration"> <h4>Declaration</h4> <div class="language"> <p class="aside-title">Swift</p> <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">convenience</span> <span class="nf">init</span><span class="p">(</span><span class="nv">directoryPath</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span> <span class="nv">maxDbSizeInKByte</span><span class="p">:</span> <span class="kt">UInt64</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span><span class="p">,</span> <span class="nv">fileMode</span><span class="p">:</span> <span class="kt">UInt32</span> <span class="o">=</span> <span class="mo">0o644</span><span class="p">,</span> <span class="nv">maxReaders</span><span class="p">:</span> <span class="kt">UInt32</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">readOnly</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kc">false</span><span class="p">)</span> <span class="k">throws</span></code></pre> </div> </div> <div> <h4>Parameters</h4> <table class="graybox"> <tbody> <tr> <td> <code> <em>directoryPath</em> </code> </td> <td> <div> <p>The directory path in which ObjectBox places its database files for this store, or to use an in-memory database <code>memory:&lt;identifier&gt;</code>.</p> </div> </td> </tr> <tr> <td> <code> <em>maxDbSizeInKByte</em> </code> </td> <td> <div> <p>Limit of on-disk space for the database files. Default is <code>1024 * 1024</code> (1 GiB).</p> </div> </td> </tr> <tr> <td> <code> <em>fileMode</em> </code> </td> <td> <div> <p>UNIX-style bit mask used for the database files; default is <code>0o644</code>. Note: directories become searchable if the &ldquo;read&rdquo; or &ldquo;write&rdquo; permission is set (e.g. 0640 becomes 0750).</p> </div> </td> </tr> <tr> <td> <code> <em>maxReaders</em> </code> </td> <td> <div> <p>The maximum number of readers. &ldquo;Readers&rdquo; are a finite resource for which we need to define a maximum number upfront. The default value is enough for most apps and usually you can ignore it completely. However, if you get the maxReadersExceeded error, you should verify your threading. For each thread, ObjectBox uses multiple readers. Their number (per thread) depends on number of types, relations, and usage patterns. Thus, if you are working with many threads (e.g. in a server-like scenario), it can make sense to increase the maximum number of readers. Note: The internal default is currently around 120. So when hitting this limit, try values around 200-500.</p> </div> </td> </tr> <tr> <td> <code> <em>readOnly</em> </code> </td> <td> <div> <p>Opens the database in read-only mode, i.e. not allowing write transactions.</p> </div> </td> </tr> </tbody> </table> </div> </section> </div> </li> </ul> </div> </section> </section> <section id="footer"> <p>&copy; 2024 <a class="link" href="https://objectbox.io" target="_blank" rel="external noopener">ObjectBox</a>. All rights reserved. (Last updated: 2024-07-30)</p> <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.15.1</a>.</p> </section> </article> </div> </body> </div> </html>

Pages: 1 2 3 4 5 6 7 8 9 10