Pre-built database


    Starting with Prebuilt Database

    In this section, you will learn how to bundle a pre-built Couchbase Lite database in an application. It can be a lot more efficient to bundle static or semi-static content database in your application and install it on the first launch. Even if some of the content changes on the server after you create the app, the app’s first pull replication will bring the database up to date. Here, you will use a pre-built database that contains only airport and hotel documents. The code below moves the pre-built database from the bundled location to the Application Support directory.

    Open the file DatabaseManager.swift and navigate to the openOrCreateDatabaseForUser method.

    This method first checks if a database file already exists. If it doesn’t exist it loads the database from the app bundle.

     if Database.exists(kDBName, inDirectory: userFolderPath) == false {
      // Load prebuilt database from App Bundle and copy over to Applications support path
      if let prebuiltPath = Bundle.main.path(forResource: kDBName, ofType: "cblite2") {
           try Database.copy(fromPath: prebuiltPath, toDatabase: "\(kDBName)", config: options)

    Try it out

    • Log into the Travel Sample Mobile app as “demo” user and password as “password”

    • Tap on "+`" button to make a flight reservation

    • In the “From” airport textfield, enter “San”

    • Confirm that the first item in the dropdown list of "San Diego Intl"

      ios prebuilt