ObjectBox Swift
objectbox.ioBlogTwitterGitHub
  • ObjectBox Swift Database Docs
  • Install ObjectBox Swift
  • Get Started with ObjectBox Swift
  • Entity Annotations in ObjectBox
  • Queries
  • Relations
  • Transactions
  • ObjectBox Swift FAQ
  • Swift API Docs
  • Advanced
    • The Sandbox on macOS
    • Enums and Custom Types
    • Data Model Updates
    • Meta Model, IDs and UIDs
    • Manual Installation
    • The setup.rb Script
    • Customizing Code Generation
  • Data Sync
  • Android Database
  • Flutter Database
Powered by GitBook
On this page
  • CocoaPods
  • Troubleshoot setup issues
  • Update to a new version
  • Swift Package
  • Set up an Xcode project
  • Set up a Swift Package Manager manifest
  • Recommended Xcode project settings

Was this helpful?

Export as PDF

Install ObjectBox Swift

ObjectBox is a NoSQL Swift database uniquely optimized for high-performance on smartphones. Learn how to set up ObjectBox Swift and persist objects in your iOS or macOS application.

PreviousObjectBox Swift Database DocsNextGet Started with ObjectBox Swift

Last updated 3 days ago

Was this helpful?

Having problems installing ObjectBox using this guide? Please, . Thanks for your help!

ObjectBox Swift is available as a:

  • pod

Alternatively, a is possible.

CocoaPods

If you are new to CocoaPods, for an introduction and installation instructions.

To add the ObjectBox Swift dependency, add the following line to your Podfile:

pod 'ObjectBox'

Then install the pod and run the ObjectBox setup script:

pod install --repo-update
Pods/ObjectBox/setup.rb

The setup.rb script will configure your Xcode project to run ObjectBox generator on every build by adding a build phase (called [OBX] Update Sourcery Generated Files) for every target with an executable.

Disable the User Script Sandboxing option to run the ObjectBox generator in recent Xcode versions:

The ObjectBox code generator needs to run in the project directory and will generate files there. If this is executed in a sandbox, the build phase will fail.

Then, open your Xcode workspace (.xcworkspace) instead of the Xcode project (.xcodeproj).

Troubleshoot setup issues

If installing the pod or configuring the project failed, try to update the xcodeproj and cocoapods gem:

gem update xcodeproj && gem update cocoapods && pod repo update

On Apple Silicon (M1), ensure you have the latest gems for CocoaPods:

gem update ffi ethon

Update to a new version

After a new version of ObjectBox Swift is released, update the ObjectBox pod and run the setup script again:

pod repo update
pod update ObjectBox
Pods/ObjectBox/setup.rb

Swift Package

Instructions depend on whether you want to set up an Xcode project or a Swift Package Manager manifest.

Set up an Xcode project

https://github.com/objectbox/objectbox-swift-spm

Finally, when asked, add the ObjectBox.xcframework to your app target.

Set up a Swift Package Manager manifest

In your Swift.package file, add the ObjectBox Swift Package repository to the dependencies block:

.package(url: "https://github.com/objectbox/objectbox-swift-spm.git", from: "4.3.0-beta.1"),

Add the ObjectBox.xcframework to the dependencies of the desired target in targets:

.product(name: "ObjectBox.xcframework", package: "objectbox-swift-spm")

Your Swift.package file should then contain sections similar to this:

dependencies: [
    .package(url: "https://github.com/objectbox/objectbox-swift-spm.git", from: "<version>"),
],
targets: [
  .executableTarget(
    name: "YourApp",
    dependencies: [
        .product(name: "ObjectBox.xcframework", package: "objectbox-swift-spm")
    ],
]

Recommended Xcode project settings

Disable Bitcode

Some versions of ObjectBox do not include Bitcode and thus you may need to adjust "Build Settings" in Xcode accordingly. In that tab, ensure "All" is active and search for "bitcode". You will find the "Enable Bitcode" setting which you set to "No".

Otherwise, for some build targets, you will get a build error like this: '.../ObjectBox.framework/ObjectBox' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target.

Now, you are all set to define your first ObjectBox entities! To continue check the or .

The Swift Package is currently in preview, we !

In Xcode, and search for the package URL:

For the Dependency Rule, we recommend to use "Up to Next Major Version" and version 4.3.0-beta.1. To find the latest version to use view the .

Now, you are all set to define your first ObjectBox entities. To continue check the or .

Now, you are all set to define your first ObjectBox entities! To continue check the or .

Getting Started guide
the example project
welcome your feedback
add a package dependency
tags of the objectbox-swift-spm repository
Getting Started guide
the example project
Getting Started guide
the example project
let us know where we lost you
manual setup in Xcode
check out their website
CocoaPods
Swift Package
Search for "sandbox" in your projects build settings and set User Script Sandboxing to No.