This is a simple demo app showing how to use the Couchbase Lite framework to embed a nonrelational ("NoSQL"), document-oriented database in an iOS app and sync it with a database server in "the cloud".
If you prefer developing in Swift, click here!
Here's the "user story":
So this dude is at the grocery store picking up produce and checking it off on his phone. He's all proud looking when he is about to check off the last item on the list, but then ... suddenly new items start appearing. Cut to his wife at home with the kids, and she's adding items.
"Okra? Ok. Coconut milk? But I already got regular milk!" He checks them off as he goes. Cut to his wife who sees them marked done; she gets a big grin and starts adding cookies and ice cream and paper towels or whatever.
The app just presents a simple editable list of textual items with checkboxes, which are stored persistently in a local database, and shared in realtime with all other users who are synced with the same cloud database.
For demo purposes, the app is hardcoded to sync with a specific database on a server run by Couchbase. You can (and should) easily modify it to sync with a database you create on a Couchbase Sync Gateway. Instructions for that are below.
These instructions assume you are familiar with building and running an iOS app.
If you have questions or get stuck or just want to say hi, please visit the Mobile-Couchbase group on Google Groups.
Prerequisite: Xcode 6.0 or later with an iOS SDK.
git clone git://github.com/couchbaselabs/Grocery-Sync-iOS.git
Note: If you want the Swift version, run git checkout swift
.
- Download Couchbase Lite for iOS.
- Copy
CouchbaseLite.framework
into theFrameworks
directory of this repo.
open GrocerySync.xcodeproj
- Select the appropriate destination (an iOS device or simulator) from the pop-up menu in the Xcode toolbar.
- Click the Run button
That's it! Now that you're set up, you can just use the Run command again after making changes to the demo code.
-
Download and install Sync Gateway (see the installation page for details).
-
Start Sync Gateway with the configuration file in the root of this project.
~/Downloads/couchbase-sync-gateway/bin/sync_gateway sync-gateway-config.json
-
Open DemoAppDelegate.m and update the
kServerDbURL
constant to point to your Sync Gateway instance.#define kServerDbURL @"http://localhost:4984/grocery-sync/"
-
Build and run the app.
-
Add items and they should be visible on the Sync Gateway Admin UI at [http://localhost:4985/_admin/] (http://localhost:4985/_admin/).
If you've installed Couchbase Server and the Couchbase Sync Gateway, you can easily configure Grocery Sync to sync locally instead of with the remote server.
(For help setting up the Sync Gateway, read the getting started guide.)
- Create a Couchbase Server bucket named
grocery-sync
. - If Couchbase Server is not running on the same computer as the Sync Gateway, edit the
sync_gateway_config.json
file in this directory and enter the correct server URL. - Start the Sync Gateway using the supplied configuration file:
sync_gateway sync_gateway_config.json
- Edit
DemoAppDelegate.m
and change the value ofkServerDbURL
to have the hostname/address and port of the Sync Gateway. Make sure to specify the public API port (4984) not the admin port (4985). - Build and run Grocery Sync.
Please see the documentation for Couchbase Lite.
Released under the Apache license, 2.0.
Copyright 2011-2014, Couchbase, Inc.