Hi,
I am witnessing some strange behavior with the local views on CBL for iOS and I am unable to create multiple views.
In my initDataService function, I have this:
...
self.database = try CBLManager.sharedInstance().databaseNamed(username);
self.createViewOne();
...
createViewOne function:
private func createViewOne() -> Bool {
guard database != nil else { return false }
let view1: CBLView = self.database.viewNamed("viewOne");
view1.setMapBlock({(doc, emit) in
print("inside my first view");
if ("TYPE_A" == doc["type"] as! String) {
emit(doc["date"] as! String, doc);
}
}, version: "1");
return true;
}
This works just fine. However, if I add a second view, like this:
...
self.database = try CBLManager.sharedInstance().databaseNamed(username);
self.createViewOne();
self.createViewTwo();
...
and createViewTwo function looks like this:
private func createViewTwo() -> Bool {
guard database != nil else { return false }
let view2: CBLView = self.database.viewNamed("viewTwo");
view2.setMapBlock({(doc, emit) in
print("inside my second view");
if ("TYPE_B" == doc["type"] as! String) {
emit(doc["date"] as! String, doc);
}
}, version: "1");
return true;
}
When I run the app on a simulator, the second view is never created. The print statement is never run, even though I’ve verified with Couchbase Lite Viewer that the docs have in fact synced with the phone, and also, the view one works fine.
Also, if I get rid of creating a second view, but change the name of the first view, so that createViewOne function looks like this:
private func createViewOne() -> Bool {
guard database != nil else { return false }
let view1: CBLView = self.database.viewNamed("viewOneB"); //added a 'B' to make view name different
view1.setMapBlock({(doc, emit) in
print("inside my first view");
if ("TYPE_A" == doc["type"] as! String) {
emit(doc["date"] as! String, doc);
}
}, version: "1");
return true;
}
and I run it on the simulator, the app crashes with the following error:
2016-09-02 03:22:57.704 MyApp[99924:2908368] *** ASSERTION FAILED: _viewID > 0
2016-09-02 03:22:57.704 MyApp[99924:2908368] *** Assertion failure in -[CBL_SQLiteViewStorage mapTableName](), /Users/jenkins/jenkins/workspace/couchbase-lite-ios-builds/couchbase-lite-ios/Source/CBL_SQLiteViewStorage.m:226
2016-09-02 03:22:57.708 MyApp[99924:2908368] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_viewID > 0'
In between each test on the simulator, I am deleting the app from the device. I’ve tried resetting the content & settings on the simulator also.
I’ll note that I am using a custom proxy between the CBL on the iOS device and the Sync Gateway. I’m also using v1.3 of iOS CBL.
This error is new as I’ve successfully created multiple views before upgrading to 1.3. Any help is appreciated.
Thanks in advance.
EDIT*** I will put together steps to reproduce from scratch once at office.