diff --git a/Jenkinsfile b/Jenkinsfile index 27ccfdbe..2edd32f3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { stage("Validate C#") { agent { label 's61113u16 (litecore)' } steps { - sh 'jenkins/dotnet_build.sh 3.2.0 1.0.0' + sh 'jenkins/dotnet_build.sh 3.2.1 1.0.0' } } stage("Validate C") { @@ -21,7 +21,7 @@ pipeline { stage("Validate iOS") { agent { label 'mobile-builder-ios-pull-request' } steps { - sh 'jenkins/ios.sh 3.2.0 1.0.0' + sh 'jenkins/ios.sh 3.2.1 1.0.0' } } } diff --git a/jenkins/ios.sh b/jenkins/ios.sh index 688ff237..8ddf9ea9 100755 --- a/jenkins/ios.sh +++ b/jenkins/ios.sh @@ -1,42 +1,30 @@ #!/bin/bash -e -if [[ "$#" -ne 2 ]]; then - echo "Usage: $0 " - exit 1 -fi +cbl_version=$1 +vs_version=$2 -THIS_DIR=$( dirname -- $(realpath "$0"); ) -CBL_VERSION="$1" -VS_VERSION="$2" +dir=$( dirname -- $(realpath "$0"); ) # Get latest good CBL iOS EE build for given version -CBL_URL="http://proget.build.couchbase.com:8080/api/open_latestbuilds?product=couchbase-lite-ios&version=${CBL_VERSION}" +CBL_URL="http://proget.build.couchbase.com:8080/api/open_latestbuilds?product=couchbase-lite-ios&version=${cbl_version}" # Grab the redirect url CBL_SOURCE_URL=$(curl -s -L -o /dev/null -w '%{url_effective}' "${CBL_URL}") -# Extract version and build number -CBL_BUILD_NUMBER=$(basename "${CBL_SOURCE_URL}") - -# Construct version with build number -CBL_BUILD="${CBL_VERSION}-${CBL_BUILD_NUMBER}" - # Get latest good VS extension build for given version -VS_URL="http://proget.build.couchbase.com:8080/api/open_latestbuilds?product=couchbase-lite-ios-vector-search&version=${VS_VERSION}" +VS_URL="http://proget.build.couchbase.com:8080/api/open_latestbuilds?product=couchbase-lite-ios-vector-search&version=${vs_version}" + # Grab the redirect url - workaround until url is fixed VS_SOURCE_URL=$(curl -s -L -o /dev/null -w '%{url_effective}' "${VS_URL}") -# Extract version and build number -VS_BUILD_NUMBER=$(basename "${VS_SOURCE_URL}") - -# Construct version with build number -VS_BUILD="${VS_VERSION}-${VS_BUILD_NUMBER}" +cbl_build=$(curl -s "http://proget.build.couchbase.com:8080/api/get_version?product=couchbase-lite-ios&version=$cbl_version&ee=true" | jq .BuildNumber) +vs_build=$(curl -s "http://proget.build.couchbase.com:8080/api/get_version?product=couchbase-lite-ios-vector-search&version=$vs_version&ee=true" | jq .BuildNumber) -for PLATFORM in "swift" "objc" +for PLATFORM in "objc" "swift" do echo $PLATFORM - pushd "${THIS_DIR}/../modules/${PLATFORM}/examples" + pushd "${dir}/../modules/${PLATFORM}/examples" # In case script fails mid-way, cleanup on start if [ -d "downloaded" ]; then @@ -46,12 +34,12 @@ do pushd downloaded # Get CBL - CBL_PACKAGE_NAME="couchbase-lite-${PLATFORM}_xc_enterprise_${CBL_BUILD}.zip" + CBL_PACKAGE_NAME="couchbase-lite-${PLATFORM}_xc_enterprise_${cbl_version}-${cbl_build}.zip" wget "$CBL_SOURCE_URL$CBL_PACKAGE_NAME" unzip -o $CBL_PACKAGE_NAME -d "../Frameworks/" # Get VS extension - VS_PACKAGE_NAME="couchbase-lite-vector-search-${VS_BUILD}-apple.zip" - wget "$VS_SOURCE_URL/$VS_PACKAGE_NAME" + VS_PACKAGE_NAME="couchbase-lite-vector-search-${vs_version}-apple.zip" + wget "$VS_SOURCE_URL$VS_PACKAGE_NAME" unzip -o $VS_PACKAGE_NAME -d "../Frameworks/" # Check if download was successful if [ $? -eq 0 ]; then diff --git a/modules/objc/examples/code_snippets.xcodeproj/project.pbxproj b/modules/objc/examples/code_snippets.xcodeproj/project.pbxproj index 325116e0..2c86026d 100644 --- a/modules/objc/examples/code_snippets.xcodeproj/project.pbxproj +++ b/modules/objc/examples/code_snippets.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 1A508E74273A3887007EABB2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1A508E66273A3887007EABB2 /* Assets.xcassets */; }; - 1A508E76273A3887007EABB2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A508E68273A3887007EABB2 /* ViewController.m */; }; 1A508E77273A3887007EABB2 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1A508E69273A3887007EABB2 /* LaunchScreen.storyboard */; }; 1A508E78273A3887007EABB2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1A508E6B273A3887007EABB2 /* Main.storyboard */; }; 1A508E79273A3887007EABB2 /* GettingStarted.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A508E6D273A3887007EABB2 /* GettingStarted.m */; }; @@ -42,14 +41,12 @@ 1A354CEC273B5A54001A20BE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 1A508E64273A3887007EABB2 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 1A508E66273A3887007EABB2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 1A508E68273A3887007EABB2 /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 1A508E6A273A3887007EABB2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 1A508E6C273A3887007EABB2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 1A508E6D273A3887007EABB2 /* GettingStarted.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GettingStarted.m; sourceTree = ""; }; 1A508E6E273A3887007EABB2 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 1A508E6F273A3887007EABB2 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 1A508E70273A3887007EABB2 /* SampleCodeTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SampleCodeTest.m; sourceTree = ""; }; - 1A508E72273A3887007EABB2 /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 4001A1B82BB343120067B507 /* code-snippets.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "code-snippets.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 4001A1BA2BB344790067B507 /* CouchbaseLiteVectorSearch.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = CouchbaseLiteVectorSearch.xcframework; path = Frameworks/CouchbaseLiteVectorSearch.xcframework; sourceTree = ""; }; 4001A1BB2BB344790067B507 /* CouchbaseLite.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = CouchbaseLite.xcframework; path = Frameworks/CouchbaseLite.xcframework; sourceTree = ""; }; @@ -75,7 +72,6 @@ 1A354CEC273B5A54001A20BE /* Info.plist */, 1A508E64273A3887007EABB2 /* AppDelegate.h */, 1A508E66273A3887007EABB2 /* Assets.xcassets */, - 1A508E68273A3887007EABB2 /* ViewController.m */, 1A508E69273A3887007EABB2 /* LaunchScreen.storyboard */, 1A508E6B273A3887007EABB2 /* Main.storyboard */, 1A508E6D273A3887007EABB2 /* GettingStarted.m */, @@ -83,7 +79,6 @@ 1A508E6F273A3887007EABB2 /* AppDelegate.m */, 1A508E70273A3887007EABB2 /* SampleCodeTest.m */, AE96AF0B2BF24E36000253DF /* VectorSearch.m */, - 1A508E72273A3887007EABB2 /* ViewController.h */, 1A354CEB273B5996001A20BE /* GettingStarted.h */, ); path = code_snippets; @@ -186,7 +181,6 @@ 1A508E79273A3887007EABB2 /* GettingStarted.m in Sources */, 1A508E7B273A3887007EABB2 /* AppDelegate.m in Sources */, 1A508E7C273A3887007EABB2 /* SampleCodeTest.m in Sources */, - 1A508E76273A3887007EABB2 /* ViewController.m in Sources */, AE96AF0C2BF24E36000253DF /* VectorSearch.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/modules/objc/examples/code_snippets/GettingStarted.m b/modules/objc/examples/code_snippets/GettingStarted.m index e3fa3c81..8375e716 100644 --- a/modules/objc/examples/code_snippets/GettingStarted.m +++ b/modules/objc/examples/code_snippets/GettingStarted.m @@ -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 @@ -13,13 +22,16 @@ @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 { 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]; @@ -27,14 +39,14 @@ - (void)viewDidLoad { [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"); } } diff --git a/modules/objc/examples/code_snippets/ViewController.h b/modules/objc/examples/code_snippets/ViewController.h deleted file mode 100644 index 903f3df8..00000000 --- a/modules/objc/examples/code_snippets/ViewController.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ViewController.h -// code-snippets -// -// Created by James Nocentini on 18/02/2019. -// Copyright © 2019 couchbase. All rights reserved. -// - -#import - -@interface ViewController : UIViewController - - -@end - diff --git a/modules/objc/examples/code_snippets/ViewController.m b/modules/objc/examples/code_snippets/ViewController.m deleted file mode 100644 index c4d40adb..00000000 --- a/modules/objc/examples/code_snippets/ViewController.m +++ /dev/null @@ -1,23 +0,0 @@ -// -// ViewController.m -// code-snippets -// -// Created by James Nocentini on 18/02/2019. -// Copyright © 2019 couchbase. All rights reserved. -// - -#import "ViewController.h" - -@interface ViewController () - -@end - -@implementation ViewController - -- (void)viewDidLoad { - [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. -} - - -@end diff --git a/modules/swift/examples/code_snippets.xcodeproj/project.pbxproj b/modules/swift/examples/code_snippets.xcodeproj/project.pbxproj index 2eeedb05..f60a7e24 100644 --- a/modules/swift/examples/code_snippets.xcodeproj/project.pbxproj +++ b/modules/swift/examples/code_snippets.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 1A354D0E273B643F001A20BE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A354D01273B643F001A20BE /* ViewController.swift */; }; 1A354D0F273B643F001A20BE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1A354D02273B643F001A20BE /* Assets.xcassets */; }; 1A354D10273B643F001A20BE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1A354D03273B643F001A20BE /* LaunchScreen.storyboard */; }; 1A354D11273B643F001A20BE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1A354D05273B643F001A20BE /* Main.storyboard */; }; @@ -17,6 +16,7 @@ 4001A1B52BB33AB60067B507 /* CouchbaseLiteVectorSearch.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4001A1B22BB33AB60067B507 /* CouchbaseLiteVectorSearch.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4001A1B62BB33AB60067B507 /* CouchbaseLiteSwift.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4001A1B32BB33AB60067B507 /* CouchbaseLiteSwift.xcframework */; }; 4001A1B72BB33AB60067B507 /* CouchbaseLiteSwift.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4001A1B32BB33AB60067B507 /* CouchbaseLiteSwift.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + AE5F25412CA7039A00AAB7F4 /* Getting-Started.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE5F25402CA7039A00AAB7F4 /* Getting-Started.swift */; }; AEE304BF2BADBAB500C12A19 /* VectorSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE304BE2BADBAB500C12A19 /* VectorSearch.swift */; }; /* End PBXBuildFile section */ @@ -36,7 +36,6 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 1A354D01273B643F001A20BE /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 1A354D02273B643F001A20BE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 1A354D04273B643F001A20BE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 1A354D06273B643F001A20BE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -45,6 +44,7 @@ 1A354D0D273B643F001A20BE /* SampleCodeTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleCodeTest.swift; sourceTree = ""; }; 4001A1B22BB33AB60067B507 /* CouchbaseLiteVectorSearch.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = CouchbaseLiteVectorSearch.xcframework; path = Frameworks/CouchbaseLiteVectorSearch.xcframework; sourceTree = ""; }; 4001A1B32BB33AB60067B507 /* CouchbaseLiteSwift.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = CouchbaseLiteSwift.xcframework; path = Frameworks/CouchbaseLiteSwift.xcframework; sourceTree = ""; }; + AE5F25402CA7039A00AAB7F4 /* Getting-Started.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Getting-Started.swift"; sourceTree = ""; }; AEE304BE2BADBAB500C12A19 /* VectorSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VectorSearch.swift; sourceTree = ""; }; BE826F0B22130841002C4924 /* code-snippets.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "code-snippets.app"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -65,7 +65,7 @@ 1A354D00273B643F001A20BE /* code_snippets */ = { isa = PBXGroup; children = ( - 1A354D01273B643F001A20BE /* ViewController.swift */, + AE5F25402CA7039A00AAB7F4 /* Getting-Started.swift */, 1A354D02273B643F001A20BE /* Assets.xcassets */, 1A354D03273B643F001A20BE /* LaunchScreen.storyboard */, 1A354D05273B643F001A20BE /* Main.storyboard */, @@ -178,8 +178,8 @@ buildActionMask = 2147483647; files = ( 1A354D18273B643F001A20BE /* SampleCodeTest.swift in Sources */, - 1A354D0E273B643F001A20BE /* ViewController.swift in Sources */, AEE304BF2BADBAB500C12A19 /* VectorSearch.swift in Sources */, + AE5F25412CA7039A00AAB7F4 /* Getting-Started.swift in Sources */, 1A354D14273B643F001A20BE /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -332,7 +332,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 863R969N56; + DEVELOPMENT_TEAM = N2Q372V7W2; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Frameworks", @@ -356,7 +356,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 863R969N56; + DEVELOPMENT_TEAM = N2Q372V7W2; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Frameworks", diff --git a/modules/swift/examples/code_snippets/Getting-Started.swift b/modules/swift/examples/code_snippets/Getting-Started.swift index efc386ad..5bbfdce7 100644 --- a/modules/swift/examples/code_snippets/Getting-Started.swift +++ b/modules/swift/examples/code_snippets/Getting-Started.swift @@ -1,8 +1,18 @@ // -// ViewController.swift -// threeBeta01prod +// Getting-Started.swift // -// 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 UIKit @@ -14,53 +24,36 @@ class ViewController: UIViewController { super.viewDidLoad() // Do any additional setup after loading the view. - getStarted(testReplication: false) + try! getStartedWithReplication(replication: false) } - - func getStarted (testReplication: Bool) { + func getStartedWithReplication (replication: Bool) throws { // Get the database (and create it if it doesn’t exist). - let database: Database - do { - database = try Database(name: "mydb") - } catch { - fatalError("Error opening database") - } + let database = try Database(name: "mydb") + let collection = try database.defaultCollection() // Create a new document (i.e. a record) in the database. - let mutableDoc = MutableDocument() + var mutableDoc = MutableDocument() .setFloat(2.0, forKey: "version") .setString("SDK", forKey: "type") - // Save it to the database. - do { - try database.saveDocument(mutableDoc) - } catch { - fatalError("Error saving document") - } + // Save document to default collection. + try collection.save(document: mutableDoc) print("Created document id type \(mutableDoc.id)? with type = \(mutableDoc.string(forKey: "type")!)") - - + // Update a document. - if let mutableDoc = database.document(withID: mutableDoc.id)?.toMutable() { - mutableDoc.setString("Swift", forKey: "language") - do { - try database.saveDocument(mutableDoc) - - let document = database.document(withID: mutableDoc.id)! - // Log the document ID (generated by the database) - // and properties - print("Updated document id \(document.id), adding language \(document.string(forKey: "language")!)") - } catch { - fatalError("Error updating document") - } - } + mutableDoc = try collection.document(id: mutableDoc.id)!.toMutable() + mutableDoc.setString("Swift", forKey: "language") + try collection.save(document: mutableDoc) + let document = try collection.document(id: mutableDoc.id) + assert(document!.string(forKey: "language") == "Swift", + "Updated document id \(document!.id), adding language \(document!.string(forKey: "language")!)") // Create a query to fetch documents of type SDK. print("Querying Documents of type=SDK") let query = QueryBuilder .select(SelectResult.all()) - .from(DataSource.database(database)) + .from(DataSource.collection(collection)) .where(Expression.property("type").equalTo(Expression.string("SDK"))) // Run the query. @@ -71,15 +64,18 @@ class ViewController: UIViewController { fatalError("Error running the query") } - if testReplication { + if replication { // Create replicators to push and pull changes to and from the cloud. let targetEndpoint = URLEndpoint(url: URL(string: "ws://localhost:4984/getting-started-db")!) - var replConfig = ReplicatorConfiguration(database: database, target: targetEndpoint) + var replConfig = ReplicatorConfiguration(target: targetEndpoint) replConfig.replicatorType = .pushAndPull - + // Add authentication. replConfig.authenticator = BasicAuthenticator(username: "john", password: "pass") + // Add collection + replConfig.addCollection(collection) + // Create replicator (make sure to add an instance or static variable named replicator) let replicator = Replicator(config: replConfig) diff --git a/modules/swift/examples/code_snippets/SampleCodeTest.swift b/modules/swift/examples/code_snippets/SampleCodeTest.swift index 525d1ad7..4fd0a717 100644 --- a/modules/swift/examples/code_snippets/SampleCodeTest.swift +++ b/modules/swift/examples/code_snippets/SampleCodeTest.swift @@ -1,14 +1,12 @@ // // SampleCodeTest.swift -// CouchbaseLite // -// Copyright (c) 2018 Couchbase, Inc All rights reserved. +// Copyright (c) 2024 Couchbase, Inc. All rights reserved. // -// Licensed under the Apache License, Version 2.0 (the "License"); +// 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 -// -// http://www.apache.org/licenses/LICENSE-2.0 +// 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, diff --git a/modules/swift/examples/code_snippets/ViewController.swift b/modules/swift/examples/code_snippets/ViewController.swift deleted file mode 100644 index 3ec65bc4..00000000 --- a/modules/swift/examples/code_snippets/ViewController.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// ViewController.swift -// code-snippets -// -// Created by James Nocentini on 12/02/2019. -// Copyright © 2019 couchbase. All rights reserved. -// - -import UIKit - -class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. - } - - -} -