Customizing Code Generation

Although you should generally not need to, you can adjust the behaviour of ObjectBox's code generator by passing it additional arguments.

The general procedure is the same: Open the [OBX] Update Sourcery Generated Files build phase for your target in Xcode and edit the shell script there. Usually it looks something like:

"$PODS_ROOT/ObjectBox/" -- --output "$PROJECT_DIR/generated/EntityInfo-TARGETNAME-iOS.generated.swift"
--model-json "$PROJECT_DIR/model-TARGETNAME-iOS.json"

where TARGETNAME is the name of your target.

Note the extra two dashes, which help the script distinguish arguments to be forwarded to the code generator from arguments directly to the script. You only need one double-dash at the start, even when passing multiple options to the script.

Controlling Output File Names

If you have several different targets in your project and want them to share the same model, you can customize the names and paths for the model.json and EntityInfo.generated.swift files by changing the script to use the same name for these files:

"${PODS_ROOT}/ObjectBox/" -- --output "${PROJECT_DIR}/generated/EntityInfo.generated.swift"
--model-json "${PROJECT_DIR}/model.json"

In this example, EntityInfo.generated.swift and model.json without the target name in them.

Modifying the Module Name

Or if you wanted to control the Swift module name under which the generated source code should end up, you would do this by telling the script to forward that option to the code generator:

"${PODS_ROOT}/ObjectBox/" -- --xcode-module JennasModule

Where JennasModule would be the module name to use.

Specifying Access Control for Generated Code

If you are writing a framework and want to export your entity classes from it, you will need to make the generated code public. You do this similarly, by adding the --visibility option:

"${PODS_ROOT}/ObjectBox/" -- --visibility public

Other Options

It is not recommended to customize any other options, as they are subject to change, but should you need to do so, you can obtain a list by asking the code generator directly by typing the following into Terminal:

/path/to/ObjectBox/ --help

Which will print a syntax description for the code generator.