---
title: Build and Run
description: Build and run a starter app to validate your install of Couchbase
  Lite on Objective-C
pubDate: 2026-08-17T09:53:44.266Z
antora:
  editUrl: https://github.com/couchbase/docs-couchbase-lite/edit/release/3.0/modules/objc/pages/gs-build.adoc
  xref: xref:3.0@couchbase-lite:objc:gs-build.adoc[]
---

[Consult the llms.txt file for a full list of contents](/llms.txt)
[View original HTML](/couchbase-lite/3.0/objc/gs-build.html)

# Build and Run

> Description — _Build and run a starter app to validate your install of Couchbase Lite on Objective-C_  

## [](#quick-steps)Quick Steps

1. Within XCode, create a new Objective-C app project
2. Within the **ViewController.m** file, replace the boilerplate codein with that shown in [Example 1](#ex-starter-code). Note you can also get this from github.
3. Build and Run the code.  
You should see the document ID and property printed to the console, indicating that the document was successfully persisted to the database as shown in [Figure 1](#img-starter-code)

![getting started ios](_images/getting-started-ios.png) 

Figure 1\. Console log output

Example 1\. Get Started code example

This snippet demonstrates how to run basic CRUD operations, a simple Query and running bi-directional replications with Sync Gateway.

```objc
//
//  GettingStarted.m
//  threeBeta01prod
//
//  Created by Ian Bridge on 04/10/2021.
//

#import "GettingStarted.h"
#import <CouchbaseLite/CouchbaseLite.h>

@implementation GettingStarted

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // Get the database (and create it if it doesn’t exist).

    bool *testReplication;
    testReplication = false;

    NSError *error;
    CBLDatabase *database = [[CBLDatabase alloc] initWithName:@"mydb" error:&error];

    // Create a new document (i.e. a record) in the database.
    CBLMutableDocument *mutableDoc = [[CBLMutableDocument alloc] init];
    [mutableDoc setFloat:2.0 forKey:@"version"];
    [mutableDoc setString:@"SDK" forKey:@"type"];

    // Save it to the database.
    [database saveDocument:mutableDoc error:&error];

    // Update a document.
    CBLMutableDocument *mutableDoc2 = [[database documentWithID:mutableDoc.id] toMutable];
    [mutableDoc2 setString:@"Objective-C" forKey:@"language"];
    [database saveDocument:mutableDoc2 error:&error];

    CBLDocument *document = [database documentWithID:mutableDoc2.id];
    // Log the document ID (generated by the database)
    // and properties
    NSLog(@"Document ID :: %@", document.id);
    NSLog(@"Learning %@", [document stringForKey:@"language"]);

    // Create a query to fetch documents of type SDK.
    CBLQueryExpression *type = [[CBLQueryExpression property:@"type"] equalTo:[CBLQueryExpression string:@"SDK"]];
    CBLQuery *query = [CBLQueryBuilder select:@[[CBLQuerySelectResult all]]
                                          from:[CBLQueryDataSource database:database]
                                         where:type];

    // Run the query
    CBLQueryResultSet *result = [query execute:&error];
    NSLog(@"Number of rows :: %lu", (unsigned long)[[result allResults] count]);

    if (testReplication) {

        // Create replicators to push and pull changes to and from the cloud.
        NSURL *url = [[NSURL alloc] initWithString:@"ws://localhost:4984/getting-started-db"];
        CBLURLEndpoint *targetEndpoint = [[CBLURLEndpoint alloc] initWithURL:url];
        CBLReplicatorConfiguration *replConfig = [[CBLReplicatorConfiguration alloc] initWithDatabase:database target:targetEndpoint];
        replConfig.replicatorType = kCBLReplicatorTypePushAndPull;

        // Add authentication.
        replConfig.authenticator = [[CBLBasicAuthenticator alloc] initWithUsername:@"john" password:@"pass"];

        // Create replicator (make sure to add an instance or static variable named _replicator)
        CBLReplicator *_replicator = [CBLReplicator alloc];
        _replicator = [[CBLReplicator alloc] initWithConfig:replConfig];

        // Listen to replicator change events.
        [_replicator addChangeListener:^(CBLReplicatorChange *change) {
            if (change.status.error) {
                NSLog(@"Error code: %ld", change.status.error.code);
            }
        }];

        // Start replication
        [_replicator start];

    }
}


@end
```

Before synchronizing documents to Sync Gateway you will need to disable App Transport Security. In the Xcode navigator, right-click on **Info.plist** and open it as a source file.

![info plist](_images/info-plist.png) 

Append the following inside of the `<dict>` XML tags to disable ATS.

```xml
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
```

See: [Install Sync Gateway](#sync-gateway::get-started-install.adoc)

## [](#related-content)Related Content

###### [](#)

How to . . .

* [Prerequisites](gs-prereqs.md)
* [Install](gs-install.md)
* [Build and Run](gs-build.md)

###### [](#-2)

Learn more . . .

* [Databases](database.md)
* [Documents](document.md)
* [Blobs](blob.md)
* [Remote Sync Gateway](replication.md)
* [Handling Data Conflicts](conflict.md)

###### [](#-3)

Dive Deeper . . .

[Mobile Forum](https://forums.couchbase.com/c/mobile/14) | [Blog](https://blog.couchbase.com/) | [Tutorials](https://docs.couchbase.com/tutorials/)