Update CBL Document, sample code seems outdated - for CBL iOS Swift 3

For updating document to CBL, I am using sample code at:
https://developer.couchbase.com/documentation/mobile/1.4/guides/couchbase-lite/native-api/document/index.html

specifically, following sample Swift code:

let doc = database.documentWithID(myDocID)

var error: NSError?

doc.update({ (newRev) -> Bool in
newRev[“title”] = title
newRev[“notes”] = notes
return true
}, error: &error)

if error != nil {
self.handleError(error)
}

Xcode gives error message saying:“Extra argument ‘error’ in call”.

Also, Xcode suggest first line to be:
let doc = database.document(withID: myDocID)

So, could someone post up-to-date swift code for this?

Also, I am not quite sure what are the typical errors that this update method can incur, could someone provide sample error-handling code for typical error scenarios?

Many Thanks !

Please file ticket directly against the Documentation page. Look for “Feedback on Page” button.

That said, I don’t know if our plan is to keep examples up-to-date with every release of swift, especially for Couchbase Lite v1.4 release . Our focus is on 2.0 release. Any reason why you are not using 2.0 ? Keeping the examples up-to-date may not be practical given how often swift changes.

The goal of the documentation is to provide enough reference material so you can easily identify the APIs to use.

As you should have already discovered, Xcode provides enough compile time support (incl. auto complete ) to easily identify updates and changes to the API.

(Will let @jamiltz, @amarantha comment on the documentation )

Hi Priya,

Thanks for the answer. Regarding using version 1.4 instead of 2.0, I am just afraid of using latest version of anything for serious projects :slight_smile:

Yes, I was aware of Xcode compile time support features, but I was hoping for more detailed and thorough documentation, especially for an important class like CBLDocument, so that I have the confidence that I know what I am doing. I did googled class reference for CBLDocument, it directed me to the following link, but I don’t see update method there:

http://docs.couchbase.com/mobile/2.0/couchbase-lite-objc/db003/Classes/CBLDocument.html

So yes, if someone could direct me to the right documentation, that would be much appreciated.

Thanks again!

I am just afraid of using latest version of anything for serious projects :slight_smile:

I understand the hesitation. CBL 2.0 has gone through 23 Developer Preview releases over the past year and a beta before it went GA. So I think you should be able to confidently start using it. In fact, if you are just starting out, that’s the version I would recommend. Besides, it’s being actively developed so you can avail the cool features that future releases would bring.
In comparison, we are not building out new features in 1.4 and at some point you’d probably would want to move to 2.0 and with the brand new API, that would be a complete rewrite of the database interaction layer.

I did googled class reference for CBLDocument, it directed me to the following link, but I don’t see update method there:

I am assuming you are looking for the 2.0 documentation (@jamiltz - looks like that link is still broken ?) . The API has completely changed as I indicated above so you won’t see the update API.

This is docs link : CouchbaseLite Reference

Here are some sample tutorials :
Couchbase Capella for Mobile Developers

I think you can start with the simple ToDo one. There is a query playground there that should be a good starting point to explore queries.

The User Profile ones are good if you are completely unfamiliar with Couchbase Mobile. I will be developing couple more swift tutorials to add to User profile series but I think there is plenty in there to get you going.

The Travel Sample is an elaborate one.