I’m a full beginner with everything map/reduce, and I’m trying to do something really simple in my iOS app in Swift.
I would like to create a view with all the documents whose “type” property has a certain value (in this case “pixync”)
So In my AppDelegate’s didFinishLaunchingWithOptions, I have the following code:
func setupCouchbase() {
let manager = CBLManager.sharedInstance()
if manager == nil {
println("Cannot create Manager instance")
} else {
var error:NSError? = nil
let database = manager.databaseNamed("pixync", error: &error)
if database == nil {
println("Cannot create or get database pixync because \(error?.debugDescription)")
} else {
var pixyncsView = database.viewNamed("pixyncs")
pixyncsView.setMapBlock({ (doc, emit) -> Void in
if doc["type"] as? String == "pixync" {
emit(doc["title"], doc)
}
}, version: "1")
}
}
}
Now when I set a breakpoint on the first line of the map block, add some documents and then query the view with the following code, my breakpoint is never hit, and the query doesn’t have any result:
if let database = CBLManager.sharedInstance().databaseNamed("pixync", error: &error) {
if let query = database.viewNamed("pixyncs").createQuery() {
var enumerator = query.run(&error)
for var i:UInt = 0; i < UInt(enumerator.count); i++ {
println(enumerator.rowAtIndex(i))
}
}
}
Obviously, I’m doing something wrong here, but again, I’m completely new to map/reduce so I’m lost.