Greeting, I am trying to use the following code with the most recent version of Couchbase Lite on iOS. The class MuscleGroup extends CBLModel.
class func findByName(name : String) -> [MuscleGroup] {
let query = MuscleGroupViews.muscleGroupByName.createQuery()
var error: NSError?
query.keys = [name]
var found = query.run(&error)
if (error != nil) {
println(error)
}
var result : [MuscleGroup] = []
for row in found.allObjects as [CBLQueryRow] {
print("-----> ")
println(row.document.properties)
result += MuscleGroup(document: row.document)
}
return result
}
When I try to run this the "result+= … " line fails with an error that says that the document already has a model. This happens if I have just created a new object of the MuscleGroup type but does not fail for any objects already in the database. So clearly I am doing something wrong. Can anyone give me any pointers on how one is supposed to use a view with CBLModel and return not the docuement objects but the model objects.
Thanks a bunch.