// model

class TestModelUser: CBLModel {

    var userName:NSString?

}


// create

        let userModel:TestModelUser = TestModelUser(newDocumentInDatabase: 
db)

        userModel.userName = "test user name 10"

        userModel.setValue(NSStringFromClass(TestModelUser), ofProperty: 
"type")

        let saved = userModel.save(&error)

        if saved {

            println("saved")

        }else{

            if let err:NSError = error {

                println(err.localizedDescription)

            }

        }


// retrive

        let dbView:CBLView = db.viewNamed("userView")

        dbView.setMapBlock({ (document, emit) -> Void in

            emit(document["_id"], document)

            if let docType = document["type"] as? String {

                if docType == NSStringFromClass(TestModelUser) {

                    emit(document["_id"], document)

                }

            }

            }, version: "5")

        

        let queryResult1:CBLQueryEnumerator = db.viewNamed("userView").
createQuery().run(&error)

        for row:CBLQueryRow in queryResult1.allObjects as [CBLQueryRow] {

            let user:TestModelUser = TestModelUser(forDocument: row.document
)

            if let uName = user.userName {

                println(uName)

            }

        }


There is some documents, but "user.userName" is always nil, what did I 
wrong?

Maybe there is another way to save properties of a model?

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/6fa449ff-0bb2-4def-b15d-e6e169845378%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to