Skip to content

Commit 90f8eb1

Browse files
README: inline install instructions
1 parent d5627ad commit 90f8eb1

File tree

1 file changed

+135
-4
lines changed

1 file changed

+135
-4
lines changed

README.md

Lines changed: 135 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
<p align="center">
1313
<a href="#add-objectbox-to-your-project">
14-
<img src="https://img.shields.io/cocoapods/v/ObjectBox.svg" alt="Version">
14+
<img src="https://img.shields.io/github/v/tag/objectbox/objectbox-swift-spm?label=Swift%20Package" alt="Add Swift Package">
1515
</a>
1616
<a href="#add-objectbox-to-your-project">
17-
<img src="https://img.shields.io/cocoapods/p/ObjectBox.svg?color=17A6A6" alt="Platform">
17+
<img src="https://img.shields.io/cocoapods/v/ObjectBox.svg" alt="Add pod">
1818
</a>
1919
</p>
2020

@@ -92,10 +92,141 @@ Check out the [installation section below](#add-objectbox-to-your-project). You
9292

9393
ObjectBox is available as a
9494

95-
- [CocoaPods](https://swift.objectbox.io/install#cocoapods) pod
95+
- [CocoaPods](#cocoapods) pod
9696
- [Swift Package](https://swift.objectbox.io/install#swift-package)
9797

98-
See [Install ObjectBox Swift](https://swift.objectbox.io/install) for details and alternative setup options.
98+
### CocoaPods
99+
100+
If you are new to CocoaPods, [check out their website](https://cocoapods.org) for an introduction and installation
101+
instructions.
102+
103+
To add the ObjectBox Swift dependency, add the following line to your `Podfile`:
104+
105+
```
106+
pod 'ObjectBox'
107+
```
108+
109+
Then install the pod and run the ObjectBox setup script:
110+
111+
```bash
112+
pod install --repo-update
113+
Pods/ObjectBox/setup.rb
114+
```
115+
116+
The `setup.rb` script will configure your Xcode project to run ObjectBox generator on every build by adding a build
117+
phase (called "[OBX] Update Sourcery Generated Files") for every target with an executable.
118+
119+
**Disable the User Script Sandboxing** option in your Xcode project build settings to allow the ObjectBox generator
120+
script to run.
121+
122+
> [!NOTE]
123+
> The ObjectBox code generator needs to run in the project directory and will generate files there. If this is executed
124+
> in a sandbox, the build phase will fail.
125+
126+
Then, open your Xcode workspace (.xcworkspace) instead of the Xcode project (.xcodeproj).
127+
128+
Now, you are all set to define your first ObjectBox entities! To continue check the
129+
[Getting Started guide](https://swift.objectbox.io/getting-started) or [the example project](#example).
130+
131+
#### Troubleshoot setup issues
132+
133+
If installing the pod or configuring the project failed, try to update the xcodeproj and cocoapods gem:
134+
135+
```bash
136+
gem update xcodeproj && gem update cocoapods && pod repo update
137+
```
138+
139+
> [!NOTE]
140+
> On Apple Silicon (M1), ensure you have the latest gems for CocoaPods:
141+
>
142+
> `gem update ffi ethon`
143+
144+
#### Update to a new version
145+
146+
After a new version of ObjectBox Swift is released, update the ObjectBox pod and run the setup script again:
147+
148+
```bash
149+
pod repo update
150+
pod update ObjectBox
151+
Pods/ObjectBox/setup.rb
152+
```
153+
154+
### Swift Package
155+
156+
> [!NOTE]
157+
> The Swift Package is currently in preview, we [welcome your feedback](https://github.com/objectbox/objectbox-swift/issues/19)!
158+
159+
Instructions depend on whether you want to set up an Xcode project or a Swift Package Manager manifest.
160+
161+
#### Set up an Xcode project
162+
163+
In Xcode, [add a package dependency](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app)
164+
and search for the package URL:
165+
166+
```
167+
https://github.com/objectbox/objectbox-swift-spm
168+
```
169+
170+
For the Dependency Rule, we recommend to use "Up to Next Major Version" and version `4.3.0-beta.2`. To find the latest
171+
version to use view the [tags of the objectbox-swift-spm repository](https://github.com/objectbox/objectbox-swift-spm/tags).
172+
173+
Finally, when asked, add the `ObjectBox.xcframework` to your app target. Or to use
174+
[ObjectBox Sync](https://objectbox.io/sync/) (requires access to the Sync feature), add the `ObjectBox-Sync.xcframework`
175+
instead.
176+
177+
Now, you are all set to define your first ObjectBox entities! To continue check the
178+
[Getting Started guide](https://swift.objectbox.io/getting-started) or [the example project](#example).
179+
180+
#### Set up a Swift Package Manager manifest
181+
182+
In your `Swift.package` file, add the ObjectBox Swift Package repository to the `dependencies` block:
183+
184+
```swift
185+
.package(url: "https://github.com/objectbox/objectbox-swift-spm.git", from: "4.3.0-beta.2"),
186+
```
187+
188+
Add the `ObjectBox.xcframework` to the `dependencies` of the desired target in `targets`:
189+
190+
```swift
191+
.product(name: "ObjectBox.xcframework", package: "objectbox-swift-spm")
192+
```
193+
194+
Or to use [ObjectBox Sync](https://objectbox.io/sync/) (requires access to the Sync feature), add the
195+
`ObjectBox-Sync.xcframework` instead:
196+
197+
```swift
198+
.product(name: "ObjectBox-Sync.xcframework", package: "objectbox-swift-spm")
199+
```
200+
201+
Your `Swift.package` file should then contain sections similar to this:
202+
203+
```swift
204+
dependencies: [
205+
.package(url: "https://github.com/objectbox/objectbox-swift-spm.git", from: "<version>"),
206+
],
207+
targets: [
208+
.executableTarget(
209+
name: "YourApp",
210+
dependencies: [
211+
.product(name: "ObjectBox.xcframework", package: "objectbox-swift-spm")
212+
],
213+
]
214+
```
215+
216+
Now, you are all set to define your first ObjectBox entities! To continue check the
217+
[Getting Started guide](https://swift.objectbox.io/getting-started) or [the example project](#example).
218+
219+
### Recommended Xcode project settings
220+
221+
ObjectBox Swift does not include Bitcode, so you may need to adjust "Build Settings" in Xcode accordingly. In that tab,
222+
ensure "All" is active and search for "bitcode". You will find the "Enable Bitcode" setting which you set to "No".
223+
224+
Otherwise, for some build targets, you will get a build error like this:
225+
226+
```
227+
'.../ObjectBox.framework/ObjectBox' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting
228+
ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target.
229+
```
99230

100231
## Example
101232

0 commit comments

Comments
 (0)