{"id":3205,"date":"2017-04-10T10:15:32","date_gmt":"2017-04-10T17:15:32","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=3205"},"modified":"2025-06-13T21:37:13","modified_gmt":"2025-06-14T04:37:13","slug":"couchbase-lite-embedded-in-ios-app-part1","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/","title":{"rendered":"Getting Started with Couchbase Lite in your iOS App : Part1"},"content":{"rendered":"<p>This post looks at\u00a0 how you can get started with\u00a0Couchbase Lite in\u00a0your iOS App. Couchbase Lite is an embedded JSON database that can work standalone, in a P2P network, or with a\u00a0Sync Gateway as a remote endpoint. While we will be looking at the framework\u00a0in the context of an iOS App in Swift, everything that\u2019s discussed here applies equally to mobile apps developed in any other platform (Android, iOS (ObjC), Xamarin). Deviations will be specified as such. Stay tuned for related posts for the other platforms!<\/p>\n<p><strong>NOTE<\/strong>:\u00a0 We will be discussing Couchbase Mobile v1.4 which is the current production release. There is a newer <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/2.0\/whatsnew.html?language=ios\">Developer Preview version 2.0 of Couchbase Mobile<\/a> . We will dive into that in a future post.<\/p>\n<h3><\/h3>\n<p><!--more--><\/p>\n<h3>Background<\/h3>\n<p>The Couchbase Mobile Stack comprises the Couchbase Server, Couchbase Sync Gateway and Couchbase Lite embedded Database. You can learn more about the server in\u00a0the <a href=\"https:\/\/www.couchbase.com\/blog\/getting-comfortable-with-couchbase-mobile-installing-couchbase-server\/\">Getting started with Couchbase Server guide<\/a> and the Sync Gateway in the\u00a0<a href=\"https:\/\/www.couchbase.com\/blog\/getting-comfortable-couchbase-mobile-installing-sync-gateway\/\">Getting Started with Couchbase Sync Gateway guide<\/a>.<\/p>\n<p>I\u2019ll assume you\u2019re familiar with developing iOS Apps and basics of Swift. If you want to read up on NoSQL databases or Couchbase, you can find lots of resources on the\u00a0<a href=\"https:\/\/www.couchbase.com\/?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">Couchbase<\/a>\u00a0site.<\/p>\n<p>Couchbase is open-source. Everything I\u2019ll use here is free to try out.<\/p>\n<h3>Couchbase Lite<\/h3>\n<p>Couchbase Lite can be used in several deployment modes.<\/p>\n<ul>\n<li><strong>Option 1<\/strong>: It can be used as a standalone cross-platform embedded database on a device<\/li>\n<li><strong>Option 2<\/strong>: It can be used in conjunction with\u00a0a remote Sync Gateway that would allow\u00a0it to sync data across devices. This case can be extended to include the full Couchbase stack with the Couchbase Server. From the perspective of Couchbase Lite on the device, it should not really matter if there is a Couchbase Server or not since Couchbase Lite will interface with the remote Sync Gateway.<\/li>\n<li><strong>Option 3<\/strong>: It can be used in\u00a0a P2P mode<\/li>\n<\/ul>\n<p>We will focus on Option 1 here.<\/p>\n<h4>Native API<\/h4>\n<p>Couchbase Lite exposes a native API for iOS, Android and Windows that allows the Apps\u00a0to easily interface with the Couchbase platform. As an App Developer, you do not have to worry about the internals of\u00a0 the Couchbase Lite embedded database, but you can instead focus on building your awesome app . The native API allows you to interact with the Couchbase Lite framework just as you would interact with other platform frameworks\/ subsystems. Again,\u00a0we will be discussing Couchbase Mobile v1.4 in this blog post.\u00a0You can get a\u00a0full listing of the APIs\u00a0on our<a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/references\/couchbase-lite\/couchbase-lite\/index.html\"> Couchbase Developer<\/a> site.<\/p>\n<h3>Integration<\/h3>\n<p>There are many options to integrate Couchbase Lite framework into your iOS App. It is probably the simplest to use Dependency Management Systems like <a href=\"https:\/\/cocoapods.org\">Cocoapods<\/a> or <a href=\"https:\/\/github.com\/Carthage\/Carthage\">Carthage<\/a>, but if you prefer, there is the option to manually include the framework into your app project . Check out our <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/installation\/ios\/index.html?language=ios\">Couchbase Mobile Getting Started Guide<\/a>\u00a0for the various integration options.<\/p>\n<p><strong>Note<\/strong> that in case of a Swift app, after importing the framework, you will have to create a Bridging Header (if your app doesn\u2019t already have one) and import the following files<\/p>\n<pre class=\"wrap:true scroll:true lang:swift decode:true\" title=\"Bridging Header\">#import &lt;CouchbaseLite\/CouchbaseLite.h&gt;\r\n#import &lt;CouchbaseLiteListener\/CBLListener.h&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h3>Demo App<\/h3>\n<p>Please download the Demo Xcode project from this <a href=\"https:\/\/github.com\/couchbaselabs\/couchbase-lite-ios-starterapp\">Github repo<\/a> . We will use this app as an example in the rest of the blog.<\/p>\n<pre class=\"lang:default decode:true \">git clone git@github.com:couchbaselabs\/couchbase-lite-ios-starterapp.git<\/pre>\n<p>&nbsp;<\/p>\n<p>This app uses Cocoapods to integrate the Couchbase Lite framework and is intended to familiarize you with the basics of using Couchbase Lite framework.\u00a0Once downloaded, build and run the App. Play around with the app.You can use this app as a starting point and extend it to test the other APIs.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5680 size-full\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/04\/cblitedemo-compressor.gif\" alt=\"\" width=\"329\" height=\"600\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>Basic Workflow<\/h3>\n<h4><strong>Creating a Local Database<\/strong><\/h4>\n<p>Open the\u00a0<em>DBMainMenuViewController.swift<\/em> file and locate the\u00a0<em>createDBWithName<\/em> function.<\/p>\n<p>This will create a database with specified name in the default path (\/Library\/Application Support). You can specify a different directory when you instantiate the <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/references\/couchbase-lite\/couchbase-lite\/manager\/manager\/index.html\">CBLManager<\/a> class.<\/p>\n<pre class=\"wrap:true lang:swift decode:true \" title=\"Create Database\">do {\r\n    \/\/ 1: Set Database Options\r\n    let options = CBLDatabaseOptions()\r\n    options.storageType = kCBLSQLiteStorage\r\n    options.create = true\r\n\r\n     \/\/ 2: Create a DB if it does not exist else return handle to existing one\r\n     try cbManager.openDatabaseNamed(name.lowercased(), with: options)\r\n}\r\ncatch {\r\n\/\/ handle error\r\n}\r\n<\/pre>\n<ol>\n<li style=\"text-align: left\">Create CBLDatabaseOptions\u00a0object to associate with the database. For instance, you can set the encryption key to use with your database using the encryptionKey property. Explore the other options on <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/references\/couchbase-lite\/couchbase-lite\/manager\/database-options\/index.html\">CBLDatabaseOptions<\/a> class.<\/li>\n<li style=\"text-align: left\">Database Names must to be lowercase. The sample app will automatically lowercase the names . If successful, a new local database will be created if it does not exist. If it exists, a handle to existing database will be returned.<\/li>\n<\/ol>\n<h4><strong>Listing the Databases<\/strong><\/h4>\n<p>This is very straightforward.\u00a0Open the <em>DBListTableViewController.swift<\/em> file. \u00a0The <em>allDatabaseNames<\/em> property on <em>CBLManager<\/em> lists the databases that were created.<\/p>\n<h4><strong>Adding a New Document to a Database<\/strong><\/h4>\n<p>Open the\u00a0<em>DocListTableViewController.swift<\/em> file and locate the\u00a0<em>createDocWithName<\/em> function.<\/p>\n<pre class=\"wrap:true lang:swift decode:true\" title=\"adding document\">do {\r\n            \/\/ 1: Create Document with unique Id\r\n            let doc = self.db?.createDocument()\r\n             \r\n            \/\/ 2: Construct user properties Object\r\n            let userProps = [DocumentUserProperties.name.rawValue:name,DocumentUserProperties.overview.rawValue:overview]\r\n           \r\n            \/\/ 3: Add a new revision with specified user properties\r\n            let _ = try doc?.putProperties(userProps)            \r\n        }\r\n        catch  {\r\n         \/\/ handle error            \r\n        }<\/pre>\n<ol>\n<li>As a result of this call, a\u00a0Document is created with a unique Id<\/li>\n<li>You can specify a set of user properties as &lt;key:value&gt; pairs. There is an alternative in which you can use <em>CBLDocumentModel<\/em> object to specify your application data. The <em>CBLDocumentModel <\/em>is only available for\u00a0the iOS\u00a0platform<em>.\u00a0<\/em>We will use &lt;key:value&gt; properties in our example<\/li>\n<\/ol>\n<p>This creates new revision of the document with the specified user properties<\/p>\n<h4><strong>Listing Documents in Database<\/strong><\/h4>\n<p>Open the\u00a0<em>DocListTableViewController.swift<\/em> file and locate the\u00a0<em>getAllDocumentForDatabase<\/em>\u00a0function<\/p>\n<pre class=\"wrap:true lang:swift decode:true\" title=\"list documents\">do {\r\n\u00a0 \u00a0 \u00a0 guard let dbName = dbName else {\r\n\u00a0 \u00a0 \u00a0     return\r\n\u00a0 \u00a0 \u00a0 \u00a0}\r\n\u00a0 \u00a0 \u00a0 \u00a0\/\/ 1. Get handle to DB with specified name\r\n\u00a0 \u00a0 \u00a0  self.db = try cbManager.existingDatabaseNamed(dbName)\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n       \/\/ 2. Create Query to fetch all documents. You can set a number of properties\r\n       \/\/ on the query object\r\n\u00a0 \u00a0 \u00a0 \u00a0liveQuery = self.db?.createAllDocumentsQuery().asLive()\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0  guard let liveQuery = liveQuery else {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0return\r\n\u00a0 \u00a0 \u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0 \u00a0\/\/ 3: You can optionally set a number of properties on the query object.\r\n\u00a0 \u00a0 \u00a0 \u00a0\/\/ Explore other properties on the query object\r\n\u00a0 \u00a0 \u00a0 \u00a0liveQuery.limit = UInt(UINT32_MAX) \/\/ All documents\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0 \u00a0\/\/ \u00a0 query.postFilter =\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0  \/\/4. Start observing for changes to the database\r\n\u00a0 \u00a0 \u00a0 \u00a0self.addLiveQueryObserverAndStartObserving()\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0 \u00a0\/\/ 5: Run the query to fetch documents asynchronously\r\n\u00a0 \u00a0 \u00a0 liveQuery.runAsync({ (enumerator, error) in\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0switch error {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  case nil:\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ 6: The \"enumerator\" is of type CBLQueryEnumerator and\r\n             \/\/ is an enumerator for the results\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  self.docsEnumerator = enumerator\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 default: \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 })\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 \u00a0 \u00a0 catch\u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ handle error\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n<\/pre>\n<ol>\n<li>Get handle to database with specified name<\/li>\n<li>Create a <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/references\/couchbase-lite\/couchbase-lite\/query\/query\/index.html\">CBLQuery<\/a> object. This Query is used to fetch all documents. You can create a regular query object or a \u201clive\u201d query object. The \u201clive\u201d query object is of type <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/references\/couchbase-lite\/couchbase-lite\/query\/live-query\/index.html\">CBLLiveQuery<\/a> that\u00a0 automatically refreshes everytime the database changes in a way that affects the query results<\/li>\n<li>The query object \u00a0has\u00a0a number of properties that can be tweaked in order to customize the results. Try modifying the properties and seeing the effect on results<\/li>\n<li>You will have to explicitly add an observer to the Live Query object be notified of changes to the database. We will discuss this more on section on &#8220;Observing Changes to Documents In Database&#8221;.<strong>\u00a0<\/strong>Don\u2019t forget to remove the observer and stop observing changes when you no longer need it!<\/li>\n<li>\u00a0Execute the query asynchronously. You can also do it synchronously if you prefer , but its probably recommended to do it async if the data sets are large.<\/li>\n<li>Once the query executes successfully, you get a <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/references\/couchbase-lite\/couchbase-lite\/query\/query-enumerator\/index.html\">CBLQueryEnumerator<\/a> object. The query enumerator allows you to enumerate the results. It lends itself very well as a data source for the Table View that displays the results<\/li>\n<\/ol>\n<h4><strong>Editing an Existing Document <\/strong><\/h4>\n<p><strong>\u00a0<\/strong>Open the\u00a0<em>DocListTableViewController.swift<\/em> file and locate the\u00a0<em>updateDocWithName\u00a0<\/em>function.<\/p>\n<pre class=\"wrap:true lang:swift decode:true\" title=\"editing document\">do {\r\n\u00a0 \u00a0 \u00a0 \u00a0\/\/ 1: Get the document associated with the row\r\n\u00a0 \u00a0 \u00a0  let doc = self.docAtIndex(index)\r\n\u00a0\u00a0\r\n\u00a0 \u00a0 \u00a0 \u00a0\/\/ 2: Construct user properties Object with updated values\r\n\u00a0 \u00a0 \u00a0 \u00a0var userProps = [DocumentUserProperties.name.rawValue:name,DocumentUserProperties.overview.rawValue:overview]\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0 \u00a0\/\/ 3: If a previous revision of document exists, make sure to specify that.\r\n       \/\/ SInce its an update, it should exist!\r\n\u00a0 \u00a0 \u00a0 if let revId = doc?.currentRevisionID\u00a0 {\r\n\u00a0\u00a0  \u00a0 \u00a0 \u00a0 \u00a0 userProps[\"_rev\"] = revId\r\n\u00a0 \u00a0 \u00a0 }\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0 \/\/ 4: Add a new revision with specified user properties\r\n\u00a0 \u00a0 \u00a0 let savedRev = try doc?.putProperties(userProps)\r\n\u00a0 }\r\n\u00a0 catch\u00a0 {\r\n\u00a0        \/\/ handle error\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0  }\r\n\r\n\u00a0fileprivate func docAtIndex(_ index:Int) -&gt; CBLDocument? {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \/\/ 1. Get the CBLQueryRow object at specified index\r\n\u00a0 \u00a0 \u00a0 \u00a0 let queryRow = self.docsEnumerator?.row(at: UInt(index))\r\n\u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0 \u00a0 \/\/ 2: Get the document associated with the row\r\n\u00a0 \u00a0 \u00a0 \u00a0 let doc = queryRow?.document\u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0 \u00a0 return doc\r\n }\r\n<\/pre>\n<ol>\n<li>Get handle to document that needs to be edited. The <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/references\/couchbase-lite\/couchbase-lite\/query\/query-enumerator\/index.html\">CBLQueryEnumerator<\/a> can be can be queried to fetch handle to the document at selected Index<\/li>\n<li>Update the user properties as &lt;key:value&gt; pairs. There is an alternative \u00a0in which you can use <em>CBLDocumentModel<\/em> object to specify your application data. This is only available on iOS. We will use &lt;key:value&gt; properties in our example.<\/li>\n<li>Updates to the document will require a revisionId to explicitly indicate the revision of the document that needs to be updated. This is specified using \u201c<em>_rev<\/em>\u201d key. This is required for conflict resolution. You can find more details <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/current\/guides\/couchbase-lite\/native-api\/revision\/index.html?language=ios\">here<\/a>.\u00a0This creates a new revision of the document with the specified user properties<\/li>\n<\/ol>\n<h4><strong>Deleting an Existing Document <\/strong><\/h4>\n<p><strong>\u00a0<\/strong>Open the\u00a0<em>DocListTableViewController.swift<\/em> file and locate the\u00a0<em>deleteDocAtIndex<\/em>\u00a0function.<\/p>\n<pre class=\"wrap:true lang:swift decode:true\" title=\"delete document\">do {\r\n \u00a0 \u00a0 \u00a0 \/\/ 1: Get the document associated with the row\r\n\u00a0 \u00a0 \u00a0 \u00a0let doc = self.docAtIndex(index)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0 \u00a0 \u00a0\/\/ 2: Delete the document\r\n\u00a0 \u00a0 \u00a0 \u00a0try doc?.delete()\r\n\u00a0\u00a0 }\r\n\u00a0 \u00a0catch\u00a0 {\r\n\u00a0\u00a0\u00a0 \u00a0 \u00a0\/\/ Handle error\r\n\u00a0 \u00a0}\r\n<\/pre>\n<ol>\n<li>Get handle to document that needs to be edited. The CBLQueryEnumerator can be can be queried to fetch handle to the document at selected Index<\/li>\n<li>Delete the document. This deletes all revisions of document<\/li>\n<\/ol>\n<h4><strong>Observing Changes to Documents in Database<\/strong><\/h4>\n<p>Open the\u00a0<em>DocListTableViewController.swift<\/em> file and locate the\u00a0<em>addLiveQueryObserverAndStartObserving<\/em>\u00a0function<\/p>\n<pre class=\"wrap:true lang:swift decode:true \" title=\"live query observer\">\u00a0\u00a0 \/\/ 1. iOS Specific. Add observer to the live Query object\r\n\u00a0 \u00a0 \u00a0 \u00a0 liveQuery.addObserver(self, forKeyPath: \"rows\", options: NSKeyValueObservingOptions.new, context: nil)\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0\r\n\u00a0 \u00a0\/\/ 2. Start observing changes\r\n\u00a0 \u00a0 \u00a0 \u00a0 liveQuery.start()\r\n<\/pre>\n<ol>\n<li>In order to be notified of changes to the database\u00a0that affect the Query results, add an observer to the Live Query object . This is a case where the Swift\/ Obj C versions differ from other mobile platforms. If you are developing on other platforms, you can call the <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/references\/couchbase-lite\/couchbase-lite\/query\/live-query\/index.html\">addChangeListener<\/a> API on the Live Query object. However, \u00a0in Couchbase Lite 1.4, this\u00a0API is unsupported on\u00a0the iOS platforms and we will instead leverage iOS\u2019s Key-Value-Observer pattern \u00a0to be notified of changes.<strong>\u00a0<\/strong>\u00a0Add a KVO observer to the Live Query object to start observing changes to the \u201crows\u201d property on Live Query object<\/li>\n<li>Start observing changes<\/li>\n<\/ol>\n<p>Whenever there is a change to the database that affects the \u201crows\u201d property of the LiveQuery object, your app will be notified of changes. When you receive the notification of change, you can update your UI, which in this case would be reloading the tableview.<\/p>\n<pre class=\"wrap:true lang:swift decode:true\">override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {\r\n\u00a0 \u00a0 \u00a0 \u00a0 if keyPath == \"rows\" {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 self.docsEnumerator = self.liveQuery?.rows\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 tableView.reloadData()\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 }\r\n<\/pre>\n<h4><\/h4>\n<h4><strong>Deleting a\u00a0Database<\/strong><\/h4>\n<p>Open the <em>DBListTableViewController.swift<\/em>\u00a0\u00a0file and locate the\u00a0<em>deleteDatabaseAtIndex<\/em>\u00a0function.<\/p>\n<pre class=\"wrap:true lang:swift decode:true\" title=\"Create Database\"> do {\r\n        \/\/ 1.  Get handle to database if exists\r\n        let db = try cbManager.existingDatabaseNamed(dbToDelete)\r\n                    \r\n        \/\/ 2. Delete the database\r\n        try db.delete()\r\n                    \r\n        \/\/ 3. update local bookkeeping\r\n        self.dbNames?.remove(at: indexPath.row)\r\n\r\n        \/\/ 4. Update UI\r\n        tableView.deleteRows(at: [indexPath], with: .automatic)\r\n    }\r\n    catch {\r\n         \/\/ handle error\r\n     }<\/pre>\n<p>Deletion of a database is handled through a simple delete() call on the database.<\/p>\n<h3>Conclusion<\/h3>\n<p>As you can see, it is pretty straightforward to integrate a standalone version of\u00a0Couchbase Lite into your new or existing iOS App. You can download the sample app discussed in this post from <a href=\"https:\/\/github.com\/couchbaselabs\/couchbase-lite-ios-starterapp\">Github repo<\/a> and try exploring the various interfaces.\u00a0\u00a0If you have further questions, feel free to reach out to me at Twitter <a href=\"https:\/\/twitter.com\/rajagp\">@rajagp<\/a> or email me <a href=\"mailto:priya.rajagopal@couchbase.com\">priya.rajagopal@couchbase.com<\/a>.<\/p>\n<p>The <a href=\"https:\/\/www.couchbase.com\/forums\/c\/mobile\/\">Couchbase Mobile Dev Forums<\/a> is another great place to get your mobile related questions answered . Also, checkout out the <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/whatsnew.html?language=ios\">Couchbase Developer Portal<\/a> for more on Couchbase Mobile.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post looks at\u00a0 how you can get started with\u00a0Couchbase Lite in\u00a0your iOS App. Couchbase Lite is an embedded JSON database that can work standalone, in a P2P network, or with a\u00a0Sync Gateway as a remote endpoint. While we will [&hellip;]<\/p>\n","protected":false},"author":1423,"featured_media":3217,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1815,7667,1810,1816,9410],"tags":[1536,1909],"ppma_author":[8948],"class_list":["post-3205","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials","category-couchbase-lite","category-couchbase-mobile","category-couchbase-server","category-objective-c","tag-ios","tag-swift"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.7.1 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Getting Started with Couchbase Lite in your iOS App : Part1 - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"Post discusses getting started with Couchbase Lite in your iOS App. Couchbase Lite is an embedded JSON database that supports multiple configurations\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting Started with Couchbase Lite in your iOS App : Part1\" \/>\n<meta property=\"og:description\" content=\"Post discusses getting started with Couchbase Lite in your iOS App. Couchbase Lite is an embedded JSON database that supports multiple configurations\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-04-10T17:15:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:37:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/CBLite_standalone_featured_Image_blog1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"741\" \/>\n\t<meta property=\"og:image:height\" content=\"399\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Priya Rajagopal, Senior Director, Product Management\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rajagp\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Priya Rajagopal, Senior Director, Product Management\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/\"},\"author\":{\"name\":\"Priya Rajagopal, Senior Director, Product Management\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c2da90e57717ee4970c48a87a131ac2c\"},\"headline\":\"Getting Started with Couchbase Lite in your iOS App : Part1\",\"datePublished\":\"2017-04-10T17:15:32+00:00\",\"dateModified\":\"2025-06-14T04:37:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/\"},\"wordCount\":1521,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/CBLite_standalone_featured_Image_blog1.png\",\"keywords\":[\"ios\",\"swift\"],\"articleSection\":[\"Best Practices and Tutorials\",\"Couchbase Lite\",\"Couchbase Mobile\",\"Couchbase Server\",\"Objective-C\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/\",\"name\":\"Getting Started with Couchbase Lite in your iOS App : Part1 - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/CBLite_standalone_featured_Image_blog1.png\",\"datePublished\":\"2017-04-10T17:15:32+00:00\",\"dateModified\":\"2025-06-14T04:37:13+00:00\",\"description\":\"Post discusses getting started with Couchbase Lite in your iOS App. Couchbase Lite is an embedded JSON database that supports multiple configurations\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/CBLite_standalone_featured_Image_blog1.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/CBLite_standalone_featured_Image_blog1.png\",\"width\":741,\"height\":399},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getting Started with Couchbase Lite in your iOS App : Part1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c2da90e57717ee4970c48a87a131ac2c\",\"name\":\"Priya Rajagopal, Senior Director, Product Management\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/4b50a54778b979d8c345b036ab138734\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/acfb2349788955262cd069497a9e7bdb0e97c26326f2e55811e7c1174e9ef1be?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/acfb2349788955262cd069497a9e7bdb0e97c26326f2e55811e7c1174e9ef1be?s=96&d=mm&r=g\",\"caption\":\"Priya Rajagopal, Senior Director, Product Management\"},\"description\":\"Priya Rajagopal is a Senior Director of Product Management at Couchbase responsible for developer platforms for the cloud and the edge. She has been professionally developing software for over 20 years in several technical and product leadership positions, with 10+ years focused on mobile technologies. As a TISPAN IPTV standards delegate, she was a key contributor to the IPTV standards specifications. She has 22 patents in the areas of networking and platform security.\",\"sameAs\":[\"https:\/\/x.com\/rajagp\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/priya-rajagopalcouchbase-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Getting Started with Couchbase Lite in your iOS App : Part1 - The Couchbase Blog","description":"Post discusses getting started with Couchbase Lite in your iOS App. Couchbase Lite is an embedded JSON database that supports multiple configurations","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/","og_locale":"en_US","og_type":"article","og_title":"Getting Started with Couchbase Lite in your iOS App : Part1","og_description":"Post discusses getting started with Couchbase Lite in your iOS App. Couchbase Lite is an embedded JSON database that supports multiple configurations","og_url":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/","og_site_name":"The Couchbase Blog","article_published_time":"2017-04-10T17:15:32+00:00","article_modified_time":"2025-06-14T04:37:13+00:00","og_image":[{"width":741,"height":399,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/CBLite_standalone_featured_Image_blog1.png","type":"image\/png"}],"author":"Priya Rajagopal, Senior Director, Product Management","twitter_card":"summary_large_image","twitter_creator":"@rajagp","twitter_misc":{"Written by":"Priya Rajagopal, Senior Director, Product Management","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/"},"author":{"name":"Priya Rajagopal, Senior Director, Product Management","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c2da90e57717ee4970c48a87a131ac2c"},"headline":"Getting Started with Couchbase Lite in your iOS App : Part1","datePublished":"2017-04-10T17:15:32+00:00","dateModified":"2025-06-14T04:37:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/"},"wordCount":1521,"commentCount":2,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/CBLite_standalone_featured_Image_blog1.png","keywords":["ios","swift"],"articleSection":["Best Practices and Tutorials","Couchbase Lite","Couchbase Mobile","Couchbase Server","Objective-C"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/","url":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/","name":"Getting Started with Couchbase Lite in your iOS App : Part1 - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/CBLite_standalone_featured_Image_blog1.png","datePublished":"2017-04-10T17:15:32+00:00","dateModified":"2025-06-14T04:37:13+00:00","description":"Post discusses getting started with Couchbase Lite in your iOS App. Couchbase Lite is an embedded JSON database that supports multiple configurations","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/CBLite_standalone_featured_Image_blog1.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/04\/CBLite_standalone_featured_Image_blog1.png","width":741,"height":399},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-lite-embedded-in-ios-app-part1\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Getting Started with Couchbase Lite in your iOS App : Part1"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c2da90e57717ee4970c48a87a131ac2c","name":"Priya Rajagopal, Senior Director, Product Management","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/4b50a54778b979d8c345b036ab138734","url":"https:\/\/secure.gravatar.com\/avatar\/acfb2349788955262cd069497a9e7bdb0e97c26326f2e55811e7c1174e9ef1be?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/acfb2349788955262cd069497a9e7bdb0e97c26326f2e55811e7c1174e9ef1be?s=96&d=mm&r=g","caption":"Priya Rajagopal, Senior Director, Product Management"},"description":"Priya Rajagopal is a Senior Director of Product Management at Couchbase responsible for developer platforms for the cloud and the edge. She has been professionally developing software for over 20 years in several technical and product leadership positions, with 10+ years focused on mobile technologies. As a TISPAN IPTV standards delegate, she was a key contributor to the IPTV standards specifications. She has 22 patents in the areas of networking and platform security.","sameAs":["https:\/\/x.com\/rajagp"],"url":"https:\/\/www.couchbase.com\/blog\/author\/priya-rajagopalcouchbase-com\/"}]}},"authors":[{"term_id":8948,"user_id":1423,"is_guest":0,"slug":"priya-rajagopalcouchbase-com","display_name":"Priya Rajagopal, Senior Director, Product Management","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/acfb2349788955262cd069497a9e7bdb0e97c26326f2e55811e7c1174e9ef1be?s=96&d=mm&r=g","author_category":"","last_name":"Rajagopal, Senior Director, Product Management","first_name":"Priya","job_title":"","user_url":"","description":"Priya Rajagopal is a Senior Director of Product Management at Couchbase responsible for developer platforms for the cloud and the edge. She has been professionally developing software for over 20 years in several technical and product leadership positions, with 10+ years focused on mobile technologies. As a TISPAN IPTV standards delegate, she was a key contributor to the IPTV standards specifications. She has 22 patents in the areas of networking and platform security."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/3205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/1423"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=3205"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/3205\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/3217"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=3205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=3205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=3205"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=3205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}