@@ -267,7 +267,7 @@ - (void) dontTestBatchOperations {
267
267
[doc setValue: @" user" forKey: @" type" ];
268
268
[doc setValue: [NSString stringWithFormat: @" user %d " , i] forKey: @" name" ];
269
269
[doc setBoolean: NO forKey: @" admin" ];
270
- [database saveDocument: doc error: nil ];
270
+ [database saveDocument: doc error: &error ];
271
271
}
272
272
}];
273
273
// end::batch[]
@@ -1430,7 +1430,7 @@ - (instancetype) init {
1430
1430
self = [super init ];
1431
1431
if (self) {
1432
1432
// tag::message-endpoint[]
1433
- CBLDatabase *database = [[CBLDatabase alloc ] initWithName: @" dbname" error: nil ];
1433
+ CBLDatabase *database = [[CBLDatabase alloc ] initWithName: @" dbname" error: &error ];
1434
1434
1435
1435
// The delegate must implement the `CBLMessageEndpointDelegate` protocol.
1436
1436
NSString * id = @" " ;
@@ -1529,7 +1529,7 @@ @implementation PassivePeerConnection {
1529
1529
1530
1530
- (void )startListener {
1531
1531
// tag::listener[]
1532
- CBLDatabase *database = [[CBLDatabase alloc ] initWithName: @" mydb" error: nil ];
1532
+ CBLDatabase *database = [[CBLDatabase alloc ] initWithName: @" mydb" error: &error ];
1533
1533
1534
1534
CBLMessageEndpointListenerConfiguration *config =
1535
1535
[[CBLMessageEndpointListenerConfiguration alloc ] initWithDatabase: database
@@ -1600,38 +1600,38 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
1600
1600
// QUERY RESULT SET HANDLING EXAMPLES
1601
1601
1602
1602
// tag::query-syntax-all[]
1603
+ CBLDatabase *db = [[CBLDatabase alloc ] initWithName: @" hotels" error: &error];
1604
+
1603
1605
CBLQuery *listQuery;
1604
1606
1605
1607
*listQuery = [CBLQueryBuilder select: @[[CBLQuerySelectResult all ]]
1606
- from: [CBLQueryDataSource database: dbName ] // <.>
1608
+ from: [CBLQueryDataSource database: db] ] // <.>
1607
1609
1608
1610
// end::query-syntax-all[]
1609
1611
1610
1612
1611
1613
// tag::query-access-all[]
1612
- CBLMutableArray* matches = [[CBLMutableArray alloc ] init ];
1614
+ NSMutableArray * matches = [[NSMutableArray alloc ] init ]; // add to native dictionary
1615
+ CBLQueryResultSet* resultset = [listQuery execute: &error];
1613
1616
1614
- CBLQueryResultSet* resultset = [listQuery execute: &error];
1615
-
1616
- for (CBLQueryResult *result in resultset) {
1617
+ for (CBLQueryResult *result in resultset.allResults) { // access the resultSet.allResults
1617
1618
1618
- CBLDictionary *match = [result valueForKey: @dbName ];
1619
+ CBLDictionary *match = [result valueAtIndex: 0 ];
1619
1620
1620
- [matches addDictionary: *match] // <.>
1621
- // NSLog(@"document name :: %@", [match stringForKey:@"name"]);
1621
+ [matches addObject: [match toDictionary ]];
1622
1622
1623
- // <.>
1624
- *docid = [match stringForKey: @" id" ]
1625
- *name = [match stringForKey: @" name" ]
1626
- *type = [match stringForKey: @" type" ]
1627
- *city = [match stringForKey: @" city" ]
1628
-
1629
- } // end for
1623
+ NSLog (@" id = %@ " , [match stringForKey: @" id" ]);
1624
+ NSLog (@" name = %@ " , [match stringForKey: @" name" ]);
1625
+ NSLog (@" type = %@ " , [match stringForKey: @" type" ]);
1626
+ NSLog (@" city = %@ " , [match stringForKey: @" city" ]);
1627
+ } // end for
1630
1628
1631
1629
// end::query-access-all[]
1632
1630
1633
1631
1634
1632
// tag::query-syntax-props[]
1633
+ CBLDatabase *db = [[CBLDatabase alloc ] initWithName: @" hotels" error: &error];
1634
+
1635
1635
CBLQuery *listQuery;
1636
1636
1637
1637
CBLQuerySelectResult *id = [CBLQuerySelectResult expression: [CBLQueryMeta id ]];
@@ -1643,41 +1643,38 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
1643
1643
CBLQuerySelectResult *city = [CBLQuerySelectResult property: @" city" ];
1644
1644
1645
1645
*listQuery = [CBLQueryBuilder select: @[id , type, name, city]
1646
- from: [CBLQueryDataSource database: dbName ]] // <.>
1646
+ from: [CBLQueryDataSource database: db ]] // <.>
1647
1647
1648
1648
// end::query-syntax-props[]
1649
1649
1650
1650
// tag::query-access-props[]
1651
- CBLDictionary *match;
1651
+ NSMutableArray * matches = [[ NSMutableArray alloc ] init ]; // save to native array
1652
1652
1653
- CBLMutableArray* matches = [[CBLMutableArray alloc ] init ];
1653
+ CBLQueryResultSet* resultset = [listQuery execute: &error ];
1654
1654
1655
- CBLQueryResultSet* resultset = [listQuery execute: &error];
1655
+ for (CBLQueryResult *result in resultset.allResults) { // all results
1656
1656
1657
- for (CBLQueryResult *result in resultset) {
1658
-
1659
- *match = [result toDictionary ];
1657
+ [matches addObject: [result toDictionary ]];
1660
1658
1661
- [matches addDictionary: *match] // <.>
1659
+ NSLog (@" id = %@ " , [result stringForKey: @" id" ]);
1660
+ NSLog (@" name = %@ " , [result stringForKey: @" name" ]);
1661
+ NSLog (@" type = %@ " , [result stringForKey: @" type" ]);
1662
+ NSLog (@" city = %@ " , [result stringForKey: @" city" ]);
1662
1663
1663
- // <.>
1664
- *docid = [match stringForKey: @" id" ]
1665
- *name = [match stringForKey: @" name" ]
1666
- *type = [match stringForKey: @" type" ]
1667
- *city = [match stringForKey: @" city" ]
1668
-
1669
- } // end for
1664
+ } // end for
1670
1665
1671
1666
// end::query-access-props[]
1672
1667
1673
1668
1674
1669
1675
1670
// tag::query-syntax-count-only[]
1671
+ CBLDatabase *db = [[CBLDatabase alloc ] initWithName: @" hotels" error: &error];
1672
+
1676
1673
CBLQuerySelectResult *count =
1677
1674
[CBLQuerySelectResult expression: [CBLQueryFunction count: [CBLQueryExpression all ]]];
1678
1675
1679
1676
*listQuery = [CBLQueryBuilder select: @[count]
1680
- from: [CBLQueryDataSource database: dbName ]] // <.>
1677
+ from: [CBLQueryDataSource database: db ]] // <.>
1681
1678
1682
1679
// end::query-syntax-count-only[]
1683
1680
@@ -1700,12 +1697,14 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
1700
1697
1701
1698
1702
1699
// tag::query-syntax-id[]
1700
+ CBLDatabase *db = [[CBLDatabase alloc ] initWithName: @" hotels" error: &error];
1701
+
1703
1702
CBLQuery *listQuery;
1704
1703
1705
1704
CBLQuerySelectResult *id = [CBLQuerySelectResult expression: [CBLQueryMeta id ]];
1706
1705
1707
1706
*listQuery = [CBLQueryBuilder select: @[id ]
1708
- from: [CBLQueryDataSource database: dbName ]]
1707
+ from: [CBLQueryDataSource database: db ]]
1709
1708
1710
1709
// end::query-syntax-id[]
1711
1710
@@ -1736,11 +1735,12 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
1736
1735
// tag::query-syntax-pagination[]
1737
1736
int thisOffset = 0 ;
1738
1737
int thisLimit = 20 ;
1738
+ CBLDatabase *db = [[CBLDatabase alloc ] initWithName: @" hotels" error: &error];
1739
1739
1740
1740
CBLQuery* listQuery =
1741
1741
[CBLQueryBuilder
1742
1742
select: @[[CBLQuerySelectResult all ]]
1743
- from: [CBLQueryDataSource database: this_Db ]
1743
+ from: [CBLQueryDataSource database: db ]
1744
1744
limit: [CBLQueryLimit
1745
1745
limit: [CBLQueryExpression integer: thisLimit]
1746
1746
offset: [CBLQueryExpression integer: thisOffset]]
0 commit comments