Back to the Couchbase homepageCouchbase logo
Couchbase Developer

  • Docs

    • Integrations
    • SDKs
    • Mobile SDKs

    • AI Developer
    • Backend
    • Full-stack
    • Mobile
    • Ops / DBA

    • Data Modeling
    • Scalability

  • Tutorials

    • Developer Community
    • Ambassador Program
  • Sign In
  • Try Free

XCode Playground: Exploring Couchbase Lite Query API

  • Use Swift Playgrounds to explore and get familiar with the Couchbase Lite Query API
  • Get a brief introduction to Swift Playgrounds and learn how you can use them to explore different facets of iOS development
  • View a video of the tutorial

Introduction

The Xcode Playground can be used to test out the key capabilities of Query interface in Couchbase Lite 2.x.

While the Xcode playground demonstrates the queries in swift, given the unified nature of the QueryBuilder API across the various Couchbase Lite platforms, barring language specific idioms, you should be able to map the queries to any of the other platform languages supported in Couchbase Lite.

So, even if you are not a Swift developer, you should be able to leverage the Xcode playground for API exploration. This tutorial makes no assumptions about your familiarity with Swift or iOS Development so even if you are a complete newbie to iOS development, you should be able to follow along this step-by-step guide.

Prerequisites

  • iOS (Swift)
  • Xcode 12+
  • Swift 5.1+

Installation

  • Clone the repo from GitHub by running the following command from the terminal
  git clone https://github.com/couchbaselabs/couchbase-lite-ios-api-playground
  • We will use Carthage to download and install CouchbaseLite. If you do not have Carthage, please follow instructions here to install Carthage on your MacOS

  • Switch to folder containing the Cartfile

  cd /path/to/couchbase-lite-ios-api-playground/carthage 
  • Download Couchbase Lite using Carthage . The version of Couchbase Lite used is specified in the Cartfile
  carthage update --platform ios --no-build

Exploring the Project

  • Open the CBLQueryTestBed.xcworkspace using Xcode12 or above.
  cd /path/to/couchbase-lite-ios
  
  open CBLQueryTestBed.xcworkspace/
  
  • You should see a bunch of playground pages in your project explorer. Start with the "ToC" page.
  • Check Render Documentation checkbox in the Utilities Window to turn on rendering of the playground pages

Xcode Playground for Couchbase Lite Query API

  • From the "ToC" page, you can navigate to any of the other playground pages. Each playground page exercises a set of queries against the "travel-sample.cblite" database

Build and Run

  • Navigate to playground page that you want to run
  • Select the CBLTestBed scheme with simulator target. This must be the active scheme
  • Do a clean of build using Cmd-Shift-K. You may have to do that for every page
  • Run the playground. This will automatically build the dependent frameworks. Be patient- this will take a minute or so to build

TROUBLESHOOTING TIPS:

  • Supporting third party frameworks within xcode playgrounds is quite glitchy and it could take couple of build attempts to resolve the dependencies. If you see an error about "Couldn't lookup symbols", just re-run the playground

Build and Run Xcode Playground

Learn More

Congratulations on completing this tutorial!

This tutorial walked you through the steps to set up an Xcode playground for testing the Query API in Couchbase Lite 2.x. As a next step, try expanding the playground to include additional queries against a different dataset . Check out the following links for further details on the Query API including a Xcode playground for testing the APIs.

Further Reading

  • Fundamentals of the Couchbase Lite 2.0 Query API
  • Handling Arrays in Queries
  • Couchbase Lite 2.0 Full Text Search API
  • Couchbase Lite 2.0 JOIN Query

Demo

You can watch a video recording of this tutorial here


This tutorial is part of a Couchbase Learning Path:
Contents
Couchbase home page link

3250 Olcott Street
Santa Clara, CA 95054
United States

  • company
  • about
  • leadership
  • news & press
  • investor relations
  • careers
  • events
  • legal
  • contact us
  • support
  • Developer portal
  • Documentation
  • Forums
  • PROFESSIONAL SERVICES
  • support login
  • support policy
  • training
  • quicklinks
  • blog
  • downloads
  • get started
  • resources
  • why nosql
  • pricing
  • follow us
  • Social Media Link for FacebookFacebook
  • Social Media Link for TwitterTwitter
  • Social Media Link for LinkedInLinkedIn
  • Social Media Link for Youtubeyoutube
  • Social Media Link for GitHubGithub
  • Social Media Link for Stack OverflowStack Overflow
  • Social Media Link for Discorddiscord

© 2025 Couchbase, Inc. Couchbase and the Couchbase logo are registered trademarks of Couchbase, Inc. All third party trademarks (including logos and icons) referenced by Couchbase, Inc. remain the property of their respective owners.

Terms of UsePrivacy PolicyCookie PolicySupport PolicyDo Not Sell My Personal InformationMarketing Preference Center