A retail inventory management app for iOS demonstrating Couchbase Lite's offline-first capabilities, real-time sync with Capella App Services, and peer-to-peer sync between devices.
Important
Before proceeding with the iOS setup, you must complete the Capella backend configuration described in the root README. This includes creating a Capella cluster, deploying an App Service, setting up the bucket/scopes/collections, importing the sample dataset, creating App Endpoints and App Users, and recording the public connection URL. If you skip these steps, the app will fail to authenticate and sync.
- Xcode: 16.4 or later
- iOS: 18.5 or later
- Swift: 6.0 (included with Xcode)
- macOS: Sonoma or later (for running Xcode 16.4)
The project uses Swift Package Manager (SPM) for dependency management. Dependencies are automatically resolved when you open the project:
- Couchbase Lite Swift: 3.3.0 (Enterprise Edition)
Important
Info.plist is not included in the repository but is required by the Xcode project. You must create it before attempting to build, or the build will fail with:
unable to read input file '.../GroceryApp/Info.plist': Operation not permitted
Create the file at GroceryApp/Info.plist with your Capella App Services credentials:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CBL_BASE_URL</key>
<string>wss://your-endpoint.apps.cloud.couchbase.com:4984</string>
<key>CBL_AA_DB</key>
<string>supermarket-aa</string>
<key>CBL_NYC_DB</key>
<string>supermarket-nyc</string>
<key>CBL_AA_USER</key>
<string>aa-store-01@supermarket.com</string>
<key>CBL_NYC_USER</key>
<string>nyc-store-01@supermarket.com</string>
<key>CBL_PASSWORD</key>
<string>P@ssword1</string>
</dict>
</plist>Where to find CBL_BASE_URL: In your Capella dashboard, go to App Services > select your App Endpoint (e.g. supermarket-nyc) > Connect tab. Copy the Public Connection URL — it will look like wss://<id>.apps.cloud.couchbase.com:4984. Use only the base URL; do not append the database name (that is handled separately by CBL_AA_DB / CBL_NYC_DB).
Open the Xcode project:
cd iOS
open GroceryApp.xcodeprojXcode will automatically resolve and download the required Swift packages when you first open the project.
If you prefer not to use Info.plist for configuration, you have two other options. The app checks environment variables first, then falls back to Info.plist.
Set environment variables in your shell:
export CBL_BASE_URL="wss://your-endpoint.apps.cloud.couchbase.com:4984"
export CBL_AA_DB="supermarket-aa"
export CBL_NYC_DB="supermarket-nyc"
export CBL_AA_USER="aa-store-01@supermarket.com"
export CBL_NYC_USER="nyc-store-01@supermarket.com"
export CBL_PASSWORD="P@ssword1"Then launch Xcode from the terminal to inherit these variables:
open GroceryApp.xcodeproj- In Xcode, select Product > Scheme > Edit Scheme
- Go to Run > Arguments tab
- Add the environment variables under Environment Variables:
CBL_BASE_URL:wss://your-endpoint.apps.cloud.couchbase.com:4984CBL_AA_DB:supermarket-aaCBL_NYC_DB:supermarket-nycCBL_AA_USER:aa-store-01@supermarket.comCBL_NYC_USER:nyc-store-01@supermarket.comCBL_PASSWORD:P@ssword1
Note
An Info.plist file is still required for the build to succeed, even when using environment variables. You can create a minimal valid plist (containing a root dict) if you prefer to configure credentials via environment variables only.
Select a simulator or connected device and click Run (⌘R).
iOS/
├── GroceryApp/
│ ├── GroceryAppApp.swift # Main app entry point (@main)
│ ├── App.swift # P2P sync helper (GrocerySyncApp, Network Framework)
│ ├── AppConfig.swift # Configuration (database, sync, stores)
│ ├── DatabaseManager.swift # Couchbase Lite database operations
│ ├── AppServicesSyncManager.swift # Sync with Capella App Services
│ ├── GroceryMultipeerSyncManager.swift # Peer-to-peer sync
│ ├── AuthenticationManager.swift # User authentication
│ ├── Views/
│ │ ├── LoginView.swift
│ │ ├── InventoryView.swift
│ │ ├── OrdersView.swift
│ │ └── StoreProfileView.swift
│ └── Models/
│ ├── GroceryItem.swift
│ ├── Order.swift
│ └── StoreProfile.swift
└── GroceryApp.xcodeproj
- Database Name:
GroceryInventoryDB - Scopes:
AA-Store,NYC-Store(based on selected store) - Collections:
inventory- Product inventory itemsorders- Customer ordersprofile- Store profile information
The app uses continuous replication, which is event-driven (not polling). Changes are pushed and pulled immediately over a persistent WebSocket connection to Capella App Services.
Key settings in AppConfig.swift:
syncContinuous: Enables real-time bidirectional syncenableAppServicesSync: Toggle cloud sync on/offenableP2PSync: Toggle peer-to-peer sync on/off
The app syncs inventory, orders, and store profile data with your Capella cluster through App Services. Changes made in the app are immediately synced to the cloud and to other connected devices.
Devices on the same local network can sync directly with each other without going through the cloud. This is useful for:
- Demo scenarios with multiple devices
- Offline collaboration between nearby devices
- Reducing cloud bandwidth usage
To enable P2P sync, ensure enableP2PSync is set to true in AppConfig.swift.
The app works fully offline using Couchbase Lite as the local database. All operations (create, read, update, delete) work without network connectivity. When connectivity is restored, changes automatically sync to the cloud.
"Cannot find 'CouchbaseLiteSwift' in scope"
- Wait for SPM to finish resolving packages (check progress in Xcode's top status bar)
- Try File > Packages > Reset Package Caches
- Clean build folder: Product > Clean Build Folder (⇧⌘K)
"Could not resolve package dependencies"
- Ensure you have an active internet connection
- Check that the package URLs in
Package.resolvedare accessible - Try removing and re-adding the packages in File > Packages
Sync not working
- Verify your
CBL_BASE_URLis correct and includeswss://protocol - Check that environment variables are set correctly
- Verify your App Services endpoint is running in Capella
- Check Xcode console for sync-related error messages
Authentication failures
- Ensure the user credentials match those configured in Capella App Services
- Verify the database name (
CBL_AA_DBorCBL_NYC_DB) matches your App Endpoint
App crashes on launch
- Check Xcode console for crash logs
- Verify all required environment variables are set
- Ensure the selected iOS simulator/device meets the minimum iOS version (18.5)
Data not appearing
- Confirm your Capella cluster has data imported into the correct scope/collection
- Check that
scopeNameand collection names inAppConfig.swiftmatch your Capella setup - Look for database errors in the console output
This project uses Couchbase Lite Enterprise Edition, which includes additional features like encrypted sync and delta sync. If you need to use the Community Edition, update the package dependency in Xcode to point to the community repository.
Peer-to-peer sync uses Bonjour/mDNS for device discovery on the local network. Make sure:
- Devices are on the same Wi-Fi network
- Local network permissions are granted to the app
- Firewall settings allow Bonjour traffic
- Main Project README - Complete setup including Capella cluster configuration
- Android App README - Android version of this app
- Web App README - Web version of this app
- Couchbase Lite iOS Documentation