Tuesday, 15 April 2014

swift couchebase lite CBLModel document properties not saved -



swift couchebase lite CBLModel document properties not saved -

i seek create cblmodel object , save in couchbase lite. document saved without error, when retrieve document database properties of document nil.

// model

class testmodeluser: cblmodel { var username:nsstring? }

// create , save

let usermodel:testmodeluser = testmodeluser(newdocumentindatabase: db) usermodel.username = "test user name 10" usermodel.setvalue(nsstringfromclass(testmodeluser), ofproperty: "type") allow saved = usermodel.save(&error) if saved { println("saved") }else{ if allow err:nserror = error { println(err.localizeddescription) } }

// retrive

let dbview:cblview = db.viewnamed("userview") dbview.setmapblock({ (document, emit) -> void in emit(document["_id"], document) if allow doctype = document["type"] as? string { if doctype == nsstringfromclass(testmodeluser) { emit(document["_id"], document) } } }, version: "5") allow queryresult1:cblqueryenumerator = db.viewnamed("userview").createquery().run(&error) row:cblqueryrow in queryresult1.allobjects [cblqueryrow] { allow user:testmodeluser = testmodeluser(fordocument: row.document) if allow uname = user.username { println(uname) } }

and user.username nil, maybe there way save document?

solved.

document property should have @nsmanaged modifier:

class usermodel: cblmodel { @nsmanaged var username:nsstring? }

thanks jens (https://forums.couchbase.com/t/swift-couchebase-lite-save-cblmodel-document-problem/2054).

swift couchbase-lite

No comments:

Post a Comment