We recommend to setup ObjectBox using CocoaPods. We also offer prelimitary Swift Package Manager support, Carthage (experimental) or a manual setup in Xcode. Here's a quick setup (more details are below the tabs):
pod 'ObjectBox' to the
Podfile in your Xcode project directory.
Run these two commands in Terminal:
pod install --repo-update
.xcworkspace in Xcode.
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
Carthage support is experimental and only recommended for experienced users. Note: Carthage may falsely report incompatible Swift 5.1.x versions. This Carthage bug prevents the framework to be installed!
github "objectbox/objectbox-swift" to your Cartfile
carthage update to download ObjectBox.
Carthage/Build/iOS/ObjectBox.framework to the appropriate targets of your project
In the "General" build settings tab, locate the "ObjectBox.framework" and sure one of "Embed Without Signing" or "Embed & Sign" is selected.
gem install xcodeproj and then run the ObjectBox setup script from
Carthage/Build/Mac/OBXCodeGen.framework/setup.rb in 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.
If you don't have CocoaPods already, install it by typing
sudo gem install cocoapods in Terminal. If you don't have a
cd into your Xcode project folder and create one using
pod init as usual. Now find the
# Pods for MyTargetName comment for each target and add the following below it:
pod repo updatepod installPods/ObjectBox/setup.rb
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
Podfile that will download the newest release of ObjectBox to your
Pods directory and install the pod in your Xcode workspace.
Once you have ObjectBox downloaded,
setup.rb will set up the ObjectBox preprocessor in your project for every target with an executable.
You can now open your project's Xcode workspace as usual and follow the rest of this tutorial.
Something doesn't work yet (e.g.
pod install fails)? 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 updatepod update ObjectBoxPods/ObjectBox/setup.rb
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
.txt suffix) in your project's folder and write the following text into it
Then open Terminal,
cd into the folder containing your project and run
carthage updategem install xcodeprojCarthage/Build/Mac/OBXCodeGen.framework/setup.rb
The first call is the typical way to make Carthage download a dependency specified in your Cartfile. Once you have ObjectBox downloaded,
setup.rb will set up the ObjectBox preprocessor in your project for every target with an executable. The
gem install xcodeproj line installs a helper tool needed by the setup script.
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.
You can now open your project's Xcode workspace as usual and follow the tutorial.
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: