Skip to content

Commit

Permalink
DOC-8513 -- Apply objc code feedback (#470) (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibsoln authored Jun 3, 2021
1 parent 48f7483 commit 92c3fa5
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions modules/objc/examples/code_snippets/SampleCodeTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ - (void) dontTestBatchOperations {
[doc setValue:@"user" forKey:@"type"];
[doc setValue:[NSString stringWithFormat:@"user %d", i] forKey:@"name"];
[doc setBoolean:NO forKey:@"admin"];
[database saveDocument:doc error:nil];
[database saveDocument:doc error: &error];
}
}];
// end::batch[]
Expand Down Expand Up @@ -1430,7 +1430,7 @@ - (instancetype) init {
self = [super init];
if (self) {
// tag::message-endpoint[]
CBLDatabase *database = [[CBLDatabase alloc] initWithName:@"dbname" error:nil];
CBLDatabase *database = [[CBLDatabase alloc] initWithName:@"dbname" error: &error];

// The delegate must implement the `CBLMessageEndpointDelegate` protocol.
NSString* id = @"";
Expand Down Expand Up @@ -1529,7 +1529,7 @@ @implementation PassivePeerConnection {

- (void)startListener {
// tag::listener[]
CBLDatabase *database = [[CBLDatabase alloc] initWithName:@"mydb" error:nil];
CBLDatabase *database = [[CBLDatabase alloc] initWithName:@"mydb" error: &error];

CBLMessageEndpointListenerConfiguration *config =
[[CBLMessageEndpointListenerConfiguration alloc] initWithDatabase:database
Expand Down Expand Up @@ -1600,38 +1600,38 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
// QUERY RESULT SET HANDLING EXAMPLES

// tag::query-syntax-all[]
CBLDatabase *db = [[CBLDatabase alloc] initWithName:@"hotels" error: &error];

CBLQuery *listQuery;

*listQuery = [CBLQueryBuilder select:@[[CBLQuerySelectResult all]]
from:[CBLQueryDataSource database:dbName] // <.>
from:[CBLQueryDataSource database:db]] // <.>

// end::query-syntax-all[]


// tag::query-access-all[]
CBLMutableArray* matches = [[CBLMutableArray alloc] init];
NSMutableArray* matches = [[NSMutableArray alloc] init]; // add to native dictionary
CBLQueryResultSet* resultset = [listQuery execute:&error];

CBLQueryResultSet* resultset = [listQuery execute:&error];

for (CBLQueryResult *result in resultset) {
for (CBLQueryResult *result in resultset.allResults) { // access the resultSet.allResults

CBLDictionary *match = [result valueForKey:@dbName];
CBLDictionary *match = [result valueAtIndex: 0];

[matches addDictionary: *match] // <.>
// NSLog(@"document name :: %@", [match stringForKey:@"name"]);
[matches addObject: [match toDictionary]];

// <.>
*docid = [match stringForKey:@"id"]
*name = [match stringForKey:@"name"]
*type = [match stringForKey:@"type"]
*city = [match stringForKey:@"city"]

} // end for
NSLog(@"id = %@", [match stringForKey:@"id"]);
NSLog(@"name = %@", [match stringForKey:@"name"]);
NSLog(@"type = %@", [match stringForKey:@"type"]);
NSLog(@"city = %@", [match stringForKey:@"city"]);
} // end for

// end::query-access-all[]


// tag::query-syntax-props[]
CBLDatabase *db = [[CBLDatabase alloc] initWithName:@"hotels" error: &error];

CBLQuery *listQuery;

CBLQuerySelectResult *id = [CBLQuerySelectResult expression:[CBLQueryMeta id]];
Expand All @@ -1643,41 +1643,38 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
CBLQuerySelectResult *city = [CBLQuerySelectResult property:@"city"];

*listQuery = [CBLQueryBuilder select:@[id, type, name, city]
from:[CBLQueryDataSource database:dbName]] // <.>
from:[CBLQueryDataSource database:db]] // <.>

// end::query-syntax-props[]

// tag::query-access-props[]
CBLDictionary *match;
NSMutableArray* matches = [[NSMutableArray alloc] init]; // save to native array

CBLMutableArray* matches = [[CBLMutableArray alloc] init];
CBLQueryResultSet* resultset = [listQuery execute:&error];

CBLQueryResultSet* resultset = [listQuery execute:&error];
for (CBLQueryResult *result in resultset.allResults) { // all results

for (CBLQueryResult *result in resultset) {

*match = [result toDictionary];
[matches addObject: [result toDictionary]];

[matches addDictionary: *match] // <.>
NSLog(@"id = %@", [result stringForKey:@"id"]);
NSLog(@"name = %@", [result stringForKey:@"name"]);
NSLog(@"type = %@", [result stringForKey:@"type"]);
NSLog(@"city = %@", [result stringForKey:@"city"]);

// <.>
*docid = [match stringForKey:@"id"]
*name = [match stringForKey:@"name"]
*type = [match stringForKey:@"type"]
*city = [match stringForKey:@"city"]

} // end for
} // end for

// end::query-access-props[]



// tag::query-syntax-count-only[]
CBLDatabase *db = [[CBLDatabase alloc] initWithName:@"hotels" error: &error];

CBLQuerySelectResult *count =
[CBLQuerySelectResult expression:[CBLQueryFunction count: [CBLQueryExpression all]]];

*listQuery = [CBLQueryBuilder select:@[count]
from:[CBLQueryDataSource database:dbName]] // <.>
from:[CBLQueryDataSource database:db]] // <.>

// end::query-syntax-count-only[]

Expand All @@ -1700,12 +1697,14 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl


// tag::query-syntax-id[]
CBLDatabase *db = [[CBLDatabase alloc] initWithName:@"hotels" error: &error];

CBLQuery *listQuery;

CBLQuerySelectResult *id = [CBLQuerySelectResult expression:[CBLQueryMeta id]];

*listQuery = [CBLQueryBuilder select:@[id]
from:[CBLQueryDataSource database:dbName]]
from:[CBLQueryDataSource database:db]]

// end::query-syntax-id[]

Expand Down Expand Up @@ -1736,11 +1735,12 @@ - (void)close:(nullable NSError *)error completion:(nonnull void (^)(void))compl
// tag::query-syntax-pagination[]
int thisOffset = 0;
int thisLimit = 20;
CBLDatabase *db = [[CBLDatabase alloc] initWithName:@"hotels" error: &error];

CBLQuery* listQuery =
[CBLQueryBuilder
select: @[[CBLQuerySelectResult all]]
from: [CBLQueryDataSource database: this_Db]
from: [CBLQueryDataSource database: db]
limit: [CBLQueryLimit
limit: [CBLQueryExpression integer: thisLimit]
offset: [CBLQueryExpression integer: thisOffset]]
Expand Down

0 comments on commit 92c3fa5

Please sign in to comment.