Wednesday, February 22, 2012

CouchCocoa - An iOS client for working with CouchDB

CouchCocoa is a framework / library for iPhone use that abstracts out the work needed to talk to CouchDB instances running on the web or on the device itself. If you want to jump right into the setup for a simple project, then simply follow these steps:
  1. Add CouchCocoa as a submodule to your project:
    • cd ~/dev/myProject/
    • git submodule add git://github.com/couchbaselabs/CouchCocoa.git
  2. Get all the dependencies of this submodule itself:
    • cd ~/dev/myProject/CouchCocoa/
    • git submodule update --init --recursive
  3. Drag & drop CouchCocoa's .xcodeproj file under your own project in Xcode
  4. Add the following as your target's dependencies so that they will get built:
    • iOS Framework (CouchCocoa)
    • iOS Library (CouchCocoa)
  5. Add the following in "Link Binary With Libraries" for your target:
    • libCouchCocoa.a
  6. Add the following in "Header Search Paths" for your target:
    • "$(SRCROOT)/CouchCocoa/Model"
    • "$(SRCROOT)/CouchCocoa/REST"
    • "$(SRCROOT)/CouchCocoa/Couch"
    • "$(SRCROOT)/CouchCocoa/UI/iOS"
  7. In Xcode, select CouchCocoa.xcodeproj in the Project Navigator and edit the Target > Build Settings and set the Skip Install setting to Yes.
  8. If at a later point of time you realize that you want to work with TouchDB as well then you *may* need to update your CouchCocoa submodule and bring it up to speed:
    • cd ~/dev/myProject/CouchCocoa/
    • git checkout touchdb
    • git pull origin touchdb
If you have any problems, post your questions on the google group for mobile couchbase.

Aside from the process there are some "big picture" points to consider:
  • CouchCocoa can talk directly to CouchDB (or CouchBase - a more performant variant). For example, if you use the hosting services provided by IrisCouch, you can configure CouchCocoa to work directly with that Couch server.
  • CouchCocoa can work with an embedded version of CouchDB on mobile devices.
    • TouchDB is one such implementation which is lightweight and exists for iOS and Android mobile devices.
      • For iOS however, I do find it a bit confusing when I think about how to structure my project, there are two ways to do it:
        • Build and soft-link the TouchDB framework. And use CouchCocoa as a submodule as outlined earlier in the blog.
          • If you choose to use TouchDB-iOS as a submodule as well then don't forget that TouchDB's itself also needs a soft-link to CouchCocoa.framework:
            cd ~/dev/superProject
            ln -s ./DerivedData/superProject/Build/Products/Debug-ios-universal/CouchCocoa.framework ./TouchDB-iOS/Demo-iOS/Frameworks/CouchCocoa.framework
        • Syncpoint-iOS which bundles TouchDB and CouchCocoa together but lags behind the individual projects in terms of stability and features. To experiment with it, you can follow a this discussion thread where it was introduced to the community.
      • Another huge pain-point is the fact that for all of GitHub's glory it doesn't let me search for content in wiki pages so when it comes time to try out the infamous Grocery-Sync example, I'm left wondering where to look! This relative path should shed some light I hope: TouchDB-iOS/Demo-iOS/DemoAppDelegate.m
    • Couchbase Mobile is another implementation. Recently it has seen some serious progress in terms of tutorials (one & two) and example-code covering its usage.

0 comments:

Post a Comment