@@ -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[]
@@ -1416,7 +1416,7 @@ - (instancetype) init {
1416
1416
self = [super init ];
1417
1417
if (self) {
1418
1418
// tag::message-endpoint[]
1419
- CBLDatabase *database = [[CBLDatabase alloc ] initWithName: @" dbname" error: nil ];
1419
+ CBLDatabase *database = [[CBLDatabase alloc ] initWithName: @" dbname" error: &error ];
1420
1420
1421
1421
// The delegate must implement the `CBLMessageEndpointDelegate` protocol.
1422
1422
NSString * id = @" " ;
@@ -1515,7 +1515,7 @@ @implementation PassivePeerConnection {
1515
1515
1516
1516
- (void )startListener {
1517
1517
// tag::listener[]
1518
- CBLDatabase *database = [[CBLDatabase alloc ] initWithName: @" mydb" error: nil ];
1518
+ CBLDatabase *database = [[CBLDatabase alloc ] initWithName: @" mydb" error: &error ];
1519
1519
1520
1520
CBLMessageEndpointListenerConfiguration *config =
1521
1521
[[CBLMessageEndpointListenerConfiguration alloc ] initWithDatabase: database
@@ -1586,38 +1586,38 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
1586
1586
// QUERY RESULT SET HANDLING EXAMPLES
1587
1587
1588
1588
// tag::query-syntax-all[]
1589
+ CBLDatabase *db = [[CBLDatabase alloc ] initWithName: @" hotels" error: &error];
1590
+
1589
1591
CBLQuery *listQuery;
1590
1592
1591
1593
*listQuery = [CBLQueryBuilder select: @[[CBLQuerySelectResult all ]]
1592
- from: [CBLQueryDataSource database: dbName ] // <.>
1594
+ from: [CBLQueryDataSource database: db] ] // <.>
1593
1595
1594
1596
// end::query-syntax-all[]
1595
1597
1596
1598
1597
1599
// tag::query-access-all[]
1598
- CBLMutableArray* matches = [[CBLMutableArray alloc ] init ];
1600
+ NSMutableArray * matches = [[NSMutableArray alloc ] init ]; // add to native dictionary
1601
+ CBLQueryResultSet* resultset = [listQuery execute: &error];
1599
1602
1600
- CBLQueryResultSet* resultset = [listQuery execute: &error];
1601
-
1602
- for (CBLQueryResult *result in resultset) {
1603
+ for (CBLQueryResult *result in resultset.allResults) { // access the resultSet.allResults
1603
1604
1604
- CBLDictionary *match = [result valueForKey: @dbName ];
1605
+ CBLDictionary *match = [result valueAtIndex: 0 ];
1605
1606
1606
- [matches addDictionary: *match] // <.>
1607
- // NSLog(@"document name :: %@", [match stringForKey:@"name"]);
1607
+ [matches addObject: [match toDictionary ]];
1608
1608
1609
- // <.>
1610
- *docid = [match stringForKey: @" id" ]
1611
- *name = [match stringForKey: @" name" ]
1612
- *type = [match stringForKey: @" type" ]
1613
- *city = [match stringForKey: @" city" ]
1614
-
1615
- } // end for
1609
+ NSLog (@" id = %@ " , [match stringForKey: @" id" ]);
1610
+ NSLog (@" name = %@ " , [match stringForKey: @" name" ]);
1611
+ NSLog (@" type = %@ " , [match stringForKey: @" type" ]);
1612
+ NSLog (@" city = %@ " , [match stringForKey: @" city" ]);
1613
+ } // end for
1616
1614
1617
1615
// end::query-access-all[]
1618
1616
1619
1617
1620
1618
// tag::query-syntax-props[]
1619
+ CBLDatabase *db = [[CBLDatabase alloc ] initWithName: @" hotels" error: &error];
1620
+
1621
1621
CBLQuery *listQuery;
1622
1622
1623
1623
CBLQuerySelectResult *id = [CBLQuerySelectResult expression: [CBLQueryMeta id ]];
@@ -1629,41 +1629,38 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
1629
1629
CBLQuerySelectResult *city = [CBLQuerySelectResult property: @" city" ];
1630
1630
1631
1631
*listQuery = [CBLQueryBuilder select: @[id , type, name, city]
1632
- from: [CBLQueryDataSource database: dbName ]] // <.>
1632
+ from: [CBLQueryDataSource database: db ]] // <.>
1633
1633
1634
1634
// end::query-syntax-props[]
1635
1635
1636
1636
// tag::query-access-props[]
1637
- CBLDictionary *match;
1637
+ NSMutableArray * matches = [[ NSMutableArray alloc ] init ]; // save to native array
1638
1638
1639
- CBLMutableArray* matches = [[CBLMutableArray alloc ] init ];
1639
+ CBLQueryResultSet* resultset = [listQuery execute: &error ];
1640
1640
1641
- CBLQueryResultSet* resultset = [listQuery execute: &error];
1641
+ for (CBLQueryResult *result in resultset.allResults) { // all results
1642
1642
1643
- for (CBLQueryResult *result in resultset) {
1644
-
1645
- *match = [result toDictionary ];
1643
+ [matches addObject: [result toDictionary ]];
1646
1644
1647
- [matches addDictionary: *match] // <.>
1645
+ NSLog (@" id = %@ " , [result stringForKey: @" id" ]);
1646
+ NSLog (@" name = %@ " , [result stringForKey: @" name" ]);
1647
+ NSLog (@" type = %@ " , [result stringForKey: @" type" ]);
1648
+ NSLog (@" city = %@ " , [result stringForKey: @" city" ]);
1648
1649
1649
- // <.>
1650
- *docid = [match stringForKey: @" id" ]
1651
- *name = [match stringForKey: @" name" ]
1652
- *type = [match stringForKey: @" type" ]
1653
- *city = [match stringForKey: @" city" ]
1654
-
1655
- } // end for
1650
+ } // end for
1656
1651
1657
1652
// end::query-access-props[]
1658
1653
1659
1654
1660
1655
1661
1656
// tag::query-syntax-count-only[]
1657
+ CBLDatabase *db = [[CBLDatabase alloc ] initWithName: @" hotels" error: &error];
1658
+
1662
1659
CBLQuerySelectResult *count =
1663
1660
[CBLQuerySelectResult expression: [CBLQueryFunction count: [CBLQueryExpression all ]]];
1664
1661
1665
1662
*listQuery = [CBLQueryBuilder select: @[count]
1666
- from: [CBLQueryDataSource database: dbName ]] // <.>
1663
+ from: [CBLQueryDataSource database: db ]] // <.>
1667
1664
1668
1665
// end::query-syntax-count-only[]
1669
1666
@@ -1686,12 +1683,14 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
1686
1683
1687
1684
1688
1685
// tag::query-syntax-id[]
1686
+ CBLDatabase *db = [[CBLDatabase alloc ] initWithName: @" hotels" error: &error];
1687
+
1689
1688
CBLQuery *listQuery;
1690
1689
1691
1690
CBLQuerySelectResult *id = [CBLQuerySelectResult expression: [CBLQueryMeta id ]];
1692
1691
1693
1692
*listQuery = [CBLQueryBuilder select: @[id ]
1694
- from: [CBLQueryDataSource database: dbName ]]
1693
+ from: [CBLQueryDataSource database: db ]]
1695
1694
1696
1695
// end::query-syntax-id[]
1697
1696
@@ -1722,11 +1721,12 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
1722
1721
// tag::query-syntax-pagination[]
1723
1722
int thisOffset = 0 ;
1724
1723
int thisLimit = 20 ;
1724
+ CBLDatabase *db = [[CBLDatabase alloc ] initWithName: @" hotels" error: &error];
1725
1725
1726
1726
CBLQuery* listQuery =
1727
1727
[CBLQueryBuilder
1728
1728
select: @[[CBLQuerySelectResult all ]]
1729
- from: [CBLQueryDataSource database: this_Db ]
1729
+ from: [CBLQueryDataSource database: db ]
1730
1730
limit: [CBLQueryLimit
1731
1731
limit: [CBLQueryExpression integer: thisLimit]
1732
1732
offset: [CBLQueryExpression integer: thisOffset]]
0 commit comments