-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CBL-6269: Update Getting Started page for CBL iOS #917
base: release/3.2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
// | ||
// GettingStarted.m | ||
// threeBeta01prod | ||
// | ||
// Created by Ian Bridge on 04/10/2021. | ||
// Copyright (c) 2024 Couchbase, Inc. All rights reserved. | ||
// | ||
// Licensed under the Couchbase License Agreement (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// https://info.couchbase.com/rs/302-GJY-034/images/2017-10-30_License_Agreement.pdf | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "GettingStarted.h" | ||
#import <CouchbaseLite/CouchbaseLite.h> | ||
|
@@ -13,28 +22,31 @@ @implementation GettingStarted | |
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
// Do any additional setup after loading the view. | ||
// Get the database (and create it if it doesn’t exist). | ||
|
||
bool *testReplication; | ||
testReplication = false; | ||
|
||
|
||
[self getStartedWithReplication: false]; | ||
|
||
} | ||
- (void) getStartedWithReplication: (Boolean) replication { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this method for? Do we need any doc tags? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for iOS no, the whole file is a snippet. All GettingStarted platforms specify that replication is OPTIONAL, although there is no optional in place for that piece of code in any other platform. Plan is to have another PR with those changes as it will be easier to review by the team - no specific iOS code in that one. |
||
NSError *error; | ||
CBLDatabase *database = [[CBLDatabase alloc] initWithName:@"mydb" error:&error]; | ||
|
||
// Get the database (and create it if it doesn’t exist). | ||
CBLDatabase *database = [[CBLDatabase alloc] initWithName: @"mydb" error: &error]; | ||
CBLCollection *collection = [database defaultCollection: &error]; | ||
|
||
// Create a new document (i.e. a record) in the database. | ||
CBLMutableDocument *mutableDoc = [[CBLMutableDocument alloc] init]; | ||
[mutableDoc setFloat:2.0 forKey:@"version"]; | ||
[mutableDoc setString:@"SDK" forKey:@"type"]; | ||
|
||
// Save it to the database. | ||
[database saveDocument:mutableDoc error:&error]; | ||
[collection saveDocument: mutableDoc error: &error]; | ||
|
||
// Update a document. | ||
CBLMutableDocument *mutableDoc2 = [[database documentWithID:mutableDoc.id] toMutable]; | ||
[mutableDoc2 setString:@"Objective-C" forKey:@"language"]; | ||
[database saveDocument:mutableDoc2 error:&error]; | ||
CBLMutableDocument *mutableDoc2 = [[collection documentWithID: mutableDoc.id error: &error] toMutable]; | ||
[mutableDoc2 setString: @"Objective-C" forKey: @"language"]; | ||
[collection saveDocument: mutableDoc2 error: &error]; | ||
|
||
CBLDocument *document = [database documentWithID:mutableDoc2.id]; | ||
CBLDocument *document = [collection documentWithID: mutableDoc2.id error: &error]; | ||
// Log the document ID (generated by the database) | ||
// and properties | ||
NSLog(@"Document ID :: %@", document.id); | ||
|
@@ -43,27 +55,29 @@ - (void)viewDidLoad { | |
// Create a query to fetch documents of type SDK. | ||
CBLQueryExpression *type = [[CBLQueryExpression property:@"type"] equalTo:[CBLQueryExpression string:@"SDK"]]; | ||
CBLQuery *query = [CBLQueryBuilder select:@[[CBLQuerySelectResult all]] | ||
from:[CBLQueryDataSource database:database] | ||
from:[CBLQueryDataSource collection: collection] | ||
where:type]; | ||
|
||
// Run the query | ||
CBLQueryResultSet *result = [query execute:&error]; | ||
NSLog(@"Number of rows :: %lu", (unsigned long)[[result allResults] count]); | ||
|
||
if (testReplication) { | ||
if (replication) { | ||
|
||
// Create replicators to push and pull changes to and from the cloud. | ||
NSURL *url = [[NSURL alloc] initWithString:@"ws://localhost:4984/getting-started-db"]; | ||
CBLURLEndpoint *targetEndpoint = [[CBLURLEndpoint alloc] initWithURL:url]; | ||
CBLReplicatorConfiguration *replConfig = [[CBLReplicatorConfiguration alloc] initWithDatabase:database target:targetEndpoint]; | ||
CBLReplicatorConfiguration *replConfig = [[CBLReplicatorConfiguration alloc] initWithTarget:targetEndpoint]; | ||
replConfig.replicatorType = kCBLReplicatorTypePushAndPull; | ||
|
||
// Add authentication. | ||
replConfig.authenticator = [[CBLBasicAuthenticator alloc] initWithUsername:@"john" password:@"pass"]; | ||
|
||
// Create replicator (make sure to add an instance or static variable named _replicator) | ||
CBLReplicator *_replicator = [CBLReplicator alloc]; | ||
_replicator = [[CBLReplicator alloc] initWithConfig:replConfig]; | ||
|
||
// Add collection | ||
[replConfig addCollection: collection config: nil]; | ||
|
||
// Create replicator | ||
CBLReplicator *_replicator = [[CBLReplicator alloc] initWithConfig: replConfig]; | ||
|
||
// Listen to replicator change events. | ||
[_replicator addChangeListener:^(CBLReplicatorChange *change) { | ||
|
@@ -75,6 +89,8 @@ - (void)viewDidLoad { | |
// Start replication | ||
[_replicator start]; | ||
|
||
} else { | ||
NSLog(@"Not testing replication"); | ||
} | ||
} | ||
|
||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to have an empty line between methods.