This folder contains the Swift sources for ObjectBox. This is the API you primarily touch when working with ObjectBox.
These Swift classes internally use ObjectBox's C API, implemented by the libObjectBoxCore library.
ios-framework/
: The ObjectBox Swift framework. Uses a special static ObjectBox C library for macOS/iOS, seefetch_dependencies.command
below.external/
: git submodule and/or pre-built binary container. This contains the ObjectBoxCore static libraries and the ObjectBox Swift code generator.
Scripts and how they depend on each other (subject to future simplifications):
ios-framework/Makefile
: combinesfetch_dependencies.command
and a Carthage build to create the Swift framework.fetch_dependencies.command
: populatesexternal/objectbox-static
with libObjectBoxCore. libObjectBoxCore is a crucial requirement build the Swift framework.create-xcframework.sh
: builds the multi-platform archive containing binaries for multiple platforms and architectures.
ObjectBox comes with a couple of tests of different categories:
- Unit tests:
ios-framework/CommonTests
, based on XCTestCase - Integration tests "CodeGen":
ios-framework/CodeGenTests
run via script (for now only via Xcode/xcodebuild); uses a separate Xcode project and an ObjectBox generator executable to generate actual binding classes. README - Integration tests "IntegrationTests":
ios-framework/IntegrationTests
, currently not maintained, run via script; somewhat similar to CodeGen; subject to a general clean up; see also its README - External integration test project: https://github.com/objectbox/objectbox-swift-integration-test runs "real projects" with "full ObjectBox round-trip" on internal CI and CircleCI
- Ensure the latest Xcode is installed (Swift 5.3+, command line tools should be included).
- Ensure homebrew is installed, e.g. setup.sh uses it.
- Ensure rbenv and ruby is installed, see section below.
- Run
./setup.sh
or see setup.sh and only run what is needed.
Open the Xcode project in ios-framework/ObjectBox.xcodeproj
. See section below on how it is organized.
From the command line:
# Enter the framework directory
cd ios-framework/
# Build the generator
make build_generator
# Build the framework
make build_framework
# Execute all tests
make test
# Execute specific tests
make unit_tests
make integration_tests
Inside ios-framework/
jazzy is configured inside Makefile:
cd ios-framework/
make generate_docs
Jazzy uses the README.md as a front page.
The result is stored inside ios-framework/docs/swift_output/
.
You look at and build the framework itself via ios-framework/ObjectBox.xcodeproj
.
ObjectBox.xcproject
targetsObjectBox-macOS
builds theObjectBox.framework
for the macOS platformObjectBoxTests-macOS
builds the unit tests for the macOS frameworkObjectBox-iOS
builds theObjectBox.framework
for the iOS platformObjectBoxTests-iOS
builds the unit tests for the iOS frameworkiOS-Fat-Framework
builds a universal binary of the iOS framework needed for distribution, with code both for device and simulatorCodeGenTests
Runs a shell script that performs integration tests for various features. This will run the Sourcery code generator over files and then compile the result against the framework.
ObjectBox.xcproject
main groups and directoriesCommonSource
contains all code to be shared by the framework of the macOS and iOS platforms.ObjectBox.h
is the framework umbrella header where all public C and ObjC header files are listed. These are either intended for use by app developers, or required to be visible for the Swift extensions.ObjectBoxC.h
is a modified version of the C API'sobjectbox.h
header generated by thegenerate_ObjectBoxC_header.rb
script so it can be imported into Swift and doesn't have a name collision withObjectBox.h
on case-insensitive file systems.- The directory itself contains general purpose types like
Store
andBox
. The important sub-groups areEntities
,Relation
, andQuery
.
CommonTests
contains all code to be shared by tests for the macOS and iOS platformsObjectBox-macOS
contains macOS-specific files, including the framework's Info.plistObjectBox-iOS
contains iOS-specific files, including the framework's Info.plist
- SwiftLint (macOS build only): calls
swiftlint lint --config .swiftlint-macOS.yml
- Edit .swiftlint-macOS.yml file to customize (e.g. "id" is OK despite less than 3 chars)
To make to-one relations and their backlinks work, the Entity
protocol was extended to require (1) an EntityType
typealias, and (2) an _id
property. The former was needed to disambiguate which concrete entity we're talking about when all we have is the protocol type, and this in turn is needed to specify the generic type requirement of Id<T>
. Since the Entity
protocol itself is intended to be no more than a convenient code annotation (which Sourcery can filter on), it's advised to get rid of this as soon as possible and find a different way to get the data needed for associations in Swift, for example using an IdGetter<T>
like we do in Java and injecting it into EntityInfo
from generated code.