0
override func viewDidLoad() {
    super.viewDidLoad()

    let database:Database

    // get the data base if its doesent exsist create one
    do {
        database = try Database(name: "my_db")
    }
    catch{
        fatalError("Error opening database")
    }


    // Create a new document (i.e. a record) in the database.
    let mutableDoc = MutableDocument()
    .setFloat(2.0, forKey: "Version")
    .setString("SDK", forKey: "type")

    // Save it to the database.
    do {
        try database.saveDocument(mutableDoc)
    } catch {
        fatalError("Error saving document")
    }

    // Create replicators to push and pull changes to and from the cloud.
    let targetEndpoint = URLEndpoint(url: URL(string: "ws://localhost:4984/my_db")!)
    let replConfig = ReplicatorConfiguration(database: database, target: targetEndpoint)
    replConfig.replicatorType = .pushAndPull

    // Add authentication.
    replConfig.authenticator = BasicAuthenticator(username: "john", password: "pass")

    // Create replicator.
    let replicator = Replicator(config: replConfig)

    // Listen to replicator change events.
    replicator.addChangeListener { (change) in
        if let error = change.status.error as NSError? {
            print("Error code :: \(error.code)")
        }
    }

    // Start replication.
    replicator.start()
}

Apart from this code, I'm running sync gateway in the background. I will attach terminal response as well.

2018-07-30T12:50:05.116+05:30 HTTP: #001:     --> 404 no such database    "example_sg_db"  (0.2 ms)
2018-07-30T12:57:57.215+05:30 HTTP:  #002: GET /my_db/_blipsync (as )
2018-07-30T12:57:57.215+05:30 HTTP: #002:     --> 404 no such database "my_db"  (0.1 ms)

I tried given solutions in the webpage but it does not give a proper explanation.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • What do you mean "can't find config file"? How are you starting Sync Gateway? Without a config file? – borrrden Jul 30 '18 at 21:27
  • Should I create the file corresponding to my requirements – Akila Dilshan Jul 31 '18 at 03:29
  • if someone can give a proper example for couchbase with iOS for absolute beginner that is much appreciated – Akila Dilshan Jul 31 '18 at 04:18
  • There is a really great example iOS (Swift and ObjC) app here : https://github.com/couchbaselabs/mobile-training-todo/tree/feature/2.0 But if you are looking for an example that also includes the SyncGateway element - this is much more difficult to find. – Ian Bradbury Nov 20 '18 at 22:16

0 Answers0