Comment on page
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.
Swift Package Manager
On Apple Silicon (M1), ensure you have the latest gems for cocoapods:
gem update ffi ethon
pod 'ObjectBox'to the
Podfilein your Xcode project directory.
- 2.Run these two commands in Terminal:
pod install --repo-update
- 3.Open your
Due to technical limitations of SPM, we can only offer iOS support at this moment. We hope that the next major SPM version will also enable us to support macOS.
Two steps are required; the first is the standard SPM dependency. In your Package.swift manifest file, add this to your
Alternatively, you may use the Xcode UI to add a package dependency.
The second step is to install the ObjectBox generator. The installation process requires Ruby and and the xcodeproj Ruby gem as a prerequisite. Locate the contents of ObjectBox package and run the contained setup script:
gem install xcodeproj # Ruby prerequisite
./setup.rb # from inside the ObjectBox package
Note: a future version of SPM may allow us to get rid of that second step by providing a plugin mechanism.
Carthage support is deprecated and only recommended for experienced users.
github "objectbox/objectbox-swift"to your Cartfile
carthage updateto download ObjectBox.
- 3.Add either
Carthage/Build/iOS/ObjectBox.frameworkto the appropriate targets of your project
- 4.In the "General" build settings tab, locate the "ObjectBox.framework" and sure one of "Embed Without Signing" or "Embed & Sign" is selected.
gem install xcodeprojand then run the ObjectBox setup script from
Carthage/Build/Mac/OBXCodeGen.framework/setup.rbin your project directory.
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.
Still using Swift 5.0? ObjectBox 1.1 supports Swift 5.1+. If you want to give ObjectBox a try but are stuck with Swift 5.0, use the ObjectBox501 pod. We recommend Swift 5.1 though.
If you don't have CocoaPods already, install it by typing
sudo gem install cocoapodsin Terminal. If you don't have a
cdinto your Xcode project folder and create one using
pod initas usual. Now find the
# Pods for MyTargetNamecomment for each target and add the following below it:
pod repo update
The first call will ensure your local copy of the list of available CocoaPods is current, the second call is your usual procedure when adding a new pod to your
Podfilethat will download the newest release of ObjectBox to your
Podsdirectory and install the pod in your Xcode workspace.
Once you have ObjectBox downloaded,
setup.rbwill set up the ObjectBox preprocessor in your project for every target with an executable.
Something doesn't work yet (e.g.
pod installfails)? Try updating CocoaPods related things using:
gem update xcodeproj && gem update cocoapods && pod repo update
After a new ObjectBox version is released, you need to get the new pod and run the setup script again:
pod repo update
pod update ObjectBox
If you don't have Carthage yet, install it e.g. using Homebrew
brew install carthage. If you do not have a Cartfile yet, create a text file named just
.txtsuffix) in your project's folder and write the following text into it
Then open Terminal,
cdinto the folder containing your project and run
gem install xcodeproj
The first call is the typical way to make Carthage download a dependency specified in your Cartfile. Once you have ObjectBox downloaded,
setup.rbwill set up the ObjectBox preprocessor in your project for every target with an executable. The
gem install xcodeprojline installs a helper tool needed by the setup script.
Carthage has a bug preventing the Swift pre-built framework from working. It falsely reports that Swift 5.1.x versions are incompatible. This will cause the setup to fail! Track this Carthage issue for updates. The error looks like this:
Skipped installing objectbox-swift.framework binary due to the error: "Incompatible Swift version - framework was built with 5.1.2 (swiftlang-1100.0.278 clang-1220.127.116.11) and the local version is 5.1 (swiftlang-1100.0.270.13 clang-118.104.22.168)."
Like for all Carthage projects, you now need to open your project in Xcode and add the framework to your target. You do this by dragging either the
Carthage/Build/Mac/ObjectBox.framework(depending on whether your project is for iOS or macOS) to the "Frameworks, Libraries and Embedded Content" list of the "General" tab of your target's settings. Make sure you choose "Embed and Sign" to its right.
OBXCodeGen.frameworkthat you'll also see in
Carthage/Build. It is not intended to be linked into your application and only exists to hold the code generator and setup script so you have them while you build.
If your unit test target does not find the ObjectBox library, please verify that the "Framework Search Paths" build settings of that secondary target are set up. Check the screenshot how to find the setting, and compare the value to the one from your main target. To fix it, press enter and ensure that the following values are present.
For iOS targets:
For macOS targets:
Otherwise, you may get errors like this:
ld: warning: Could not find or use auto-linked framework 'ObjectBox' Undefined symbols for architecture x86_64: "type metadata accessor for ObjectBox.ToManyProperty" ...
After a new ObjectBox version is released, you need to update via Carthage and run the setup script again: