-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(DOCSP-29399): Swift: Subscribe API documentation (#2823)
## Pull Request Info DO NOT MERGE until this feature ships. It depends on realm-swift PR #8244. After release: - [x] Update version number (`INSERT-VERSION-NUMBER-HERE`) on page with release version - [x] Add links to generated API documentation for new APIs - [x] Update SPM to the release version ### Jira - https://jira.mongodb.org/browse/DOCSP-29399 ### Staged Changes - [Manage Flexible Sync Subscriptions](https://docs-mongodbcom-staging.corp.mongodb.com/realm/docsworker-xlarge/DOCSP-29399/sdk/swift/sync/flexible-sync/) ### Reminder Checklist If your PR modifies the docs, you might need to also update some corresponding pages. Check if completed or N/A. - [x] Create Jira ticket for corresponding docs-app-services update(s), if any - [x] Checked/updated Admin API - [x] Checked/updated CLI reference ### Review Guidelines [REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md)
- Loading branch information
Showing
15 changed files
with
683 additions
and
72 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
import RealmSwift | ||
import XCTest | ||
|
||
func randomAlphanumericString(_ length: Int) -> String { | ||
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
let randomString = (0..<length).map{ _ in String(letters.randomElement()!) }.reduce("", +) | ||
return randomString | ||
} | ||
|
||
open class SwiftSyncTestCase: XCTestCase { | ||
let waiter = XCTWaiter() | ||
|
||
public func emailPasswordCredentials(app: App) -> Credentials { | ||
let email = "\(randomAlphanumericString(10))" | ||
let password = "abcdef" | ||
let credentials = Credentials.emailPassword(email: email, password: password) | ||
let ex = XCTestExpectation(description: "Should register in the user properly") | ||
app.emailPasswordAuth.registerUser(email: email, password: password, completion: { error in | ||
XCTAssertNil(error) | ||
ex.fulfill() | ||
}) | ||
waiter.wait(for: [ex], timeout: 40) | ||
return credentials | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...examples/generated/code/start/FlexibleSync.snippet.initialize-app-authenticate-user.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
let app = App(id: APPID) | ||
|
||
do { | ||
let credentials = emailPasswordCredentials(app: app) | ||
let user = try await app.login(credentials: credentials) | ||
var flexSyncConfig = user.flexibleSyncConfiguration() | ||
flexSyncConfig.objectTypes = [Task.self, Team.self] | ||
do { | ||
// Open the synced realm and manage Flexible Sync subscriptions | ||
} catch { | ||
print("Failed to open realm: \(error.localizedDescription)") | ||
// handle error | ||
} | ||
} catch { | ||
fatalError("Login failed: \(error.localizedDescription)") | ||
} |
9 changes: 9 additions & 0 deletions
9
...examples/generated/code/start/FlexibleSync.snippet.remove-all-unnamed-subscriptions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
let realm = try await Realm(configuration: flexSyncConfig) | ||
// Add 2 subscriptions, one named and one unnamed. | ||
let results = try await realm.objects(Team.self).where { $0.teamName == "Developer Education" }.subscribe(name: "team_developer_education") | ||
let results2 = try await realm.objects(Task.self).where { $0.completed == false }.subscribe() | ||
// Later, remove only the unnamed one | ||
let subscriptions = realm.subscriptions | ||
try await subscriptions.update { | ||
subscriptions.removeAll(unnamedOnly: true) | ||
} |
6 changes: 6 additions & 0 deletions
6
source/examples/generated/code/start/FlexibleSync.snippet.subscribe-api-unsubscribe.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
let realm = try await Realm(configuration: flexSyncConfig) | ||
let results = try await realm.objects(Task.self).where { $0.completed == false }.subscribe() | ||
// Go on to work with subscribed results. | ||
|
||
// Later... | ||
results.unsubscribe() |
5 changes: 5 additions & 0 deletions
5
...ples/generated/code/start/FlexibleSync.snippet.subscribe-to-results-on-custom-actor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let realm = try await Realm(configuration: flexSyncConfig, actor: CustomGlobalActor.shared) | ||
let results = try await realm.objects(Team.self) | ||
.where { $0.teamName == "Developer Education" } | ||
.subscribe(name: "team_developer_education") | ||
// Go on to work with subscribed results |
5 changes: 5 additions & 0 deletions
5
...amples/generated/code/start/FlexibleSync.snippet.subscribe-to-results-on-main-actor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let realm = try await Realm(configuration: flexSyncConfig, actor: MainActor.shared) | ||
let results = try await realm.objects(Team.self) | ||
.where { $0.teamName == "Developer Education" } | ||
.subscribe(name: "team_developer_education") | ||
// Go on to work with subscribed results |
4 changes: 4 additions & 0 deletions
4
source/examples/generated/code/start/FlexibleSync.snippet.subscribe-to-results-unnamed.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
let realm = try await Realm(configuration: flexSyncConfig) | ||
let results = try await realm.objects(Task.self) | ||
.where { $0.progressMinutes >= 60 }.subscribe() | ||
// Go on to work with subscribed results |
5 changes: 5 additions & 0 deletions
5
...e/examples/generated/code/start/FlexibleSync.snippet.subscribe-to-results-with-name.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let realm = try await Realm(configuration: flexSyncConfig) | ||
let results = try await realm.objects(Team.self) | ||
.where { $0.teamName == "Developer Education" } | ||
.subscribe(name: "team_developer_education") | ||
// Go on to work with subscribed results |
9 changes: 9 additions & 0 deletions
9
source/examples/generated/code/start/FlexibleSync.snippet.subscribe-wait-for-sync.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
let realm = try await Realm(configuration: flexSyncConfig) | ||
let results = try await realm.objects(Team.self) | ||
.where { $0.members.contains("Bob Smith") } | ||
.subscribe( | ||
name: "bob_smith_teams", | ||
waitForSync: .onCreation) | ||
// After waiting for sync, the results set contains all the objects | ||
// that match the query - in our case, 1 | ||
print("The number of teams that have Bob Smith as a member is \(results.count)") |
Oops, something went wrong.