Skip to content

Commit 6c6f672

Browse files
committed
Address comments
1 parent 388c3ce commit 6c6f672

16 files changed

+158
-31
lines changed

examples/ios/Examples/AccessMongoDB.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class AccessMongoDB: AnonymouslyLoggedInTestCase {
66
let expectation = XCTestExpectation(description: "it completes")
77

88
// :code-block-start: remote-mongodb
9-
// mongodb-atlas is the name of cluster service
9+
// mongodb-atlas is the cluster service name
1010
let client = app.currentUser!.mongoClient("mongodb-atlas")
1111

1212
// Select the database
@@ -34,7 +34,7 @@ class AccessMongoDB: AnonymouslyLoggedInTestCase {
3434
// :hide-end:
3535
return
3636
}
37-
// Print each document.
37+
// Print each document
3838
print("Results:")
3939
results!.forEach({(document) in
4040
print("Document:")

examples/ios/Examples/CompleteQuickStart.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class CompleteQuickStartTest: XCTestCase {
131131
expectation.fulfill()
132132
// :hide-end:
133133
}
134-
// :code-block-end
134+
// :code-block-end:
135135
wait(for: [expectation], timeout: 10.0)
136136
}
137137
}

examples/ios/Examples/CustomUserData.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ - (void)testReadCustomUserData {
5252
return;
5353
}
5454

55-
// One way to use custom data:
55+
// If the user data has been refreshed recently, you can access the
56+
// custom user data directly on the user object
5657
NSLog(@"User custom data: %@", [user customData]);
5758

58-
// Another way to use custom data: refresh in case the client-side data is stale
59+
// Refresh the custom data
5960
[user refreshCustomDataWithCompletion:^(NSDictionary *customData, NSError *error) {
6061
if (error != nil) {
6162
NSLog(@"Failed to refresh custom user data: %@", error);

examples/ios/Examples/CustomUserData.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ class CustomUserData: XCTestCase {
5050
return
5151
}
5252

53-
// One way to use custom data:
53+
// If the user data has been refreshed recently, you can access the
54+
// custom user data directly on the user object
5455
print("User custom data: \(user!.customData)")
5556

56-
// Another way: refresh in case the user data is stale.
57+
// Refresh the custom user data
5758
user!.refreshCustomData() { (customData, error) in
5859
guard error == nil else {
5960
print("Failed to refresh custom data: \(error!.localizedDescription)")

examples/ios/Examples/ManageApiKeys.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ @implementation ManageApiKeys
1111
- (void)setUp {
1212
XCTestExpectation *expectation = [self expectationWithDescription:@"registers and logs in"];
1313

14-
RLMApp *app = [RLMApp appWithId:YOUR_REALM_APP_ID];
14+
RLMApp *app = [RLMApp appWithId:YOUR_REALM_APP_ID]; // Replace YOUR_REALM_APP_ID with your Realm app ID
1515
RLMEmailPasswordAuth *client = [app emailPasswordAuth];
1616
NSString *email = @"[email protected]";
1717
NSString *password = @"123456";

examples/ios/Examples/ManageApiKeys.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ManageApiKeys: XCTestCase {
4242

4343
// ... log in ...
4444

45-
// User must not be anonymous user.
45+
// User must not be an anonymous user.
4646
let user = app.currentUser!
4747
let client = user.apiKeysAuth
4848

examples/ios/Examples/MultipleUsers.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import RealmSwift
44
class MultipleUsers: XCTestCase {
55

66
override func tearDown() {
7+
guard app.currentUser != nil else {
8+
return
9+
}
710
let expectation = XCTestExpectation(description: "Remove anonymous user from device")
8-
app.currentUser?.remove { (error) in
11+
app.currentUser!.remove { (error) in
912
expectation.fulfill()
1013
}
1114
wait(for: [expectation], timeout: 3)
@@ -65,6 +68,10 @@ class MultipleUsers: XCTestCase {
6568
func testSwitchUsers() {
6669
// :code-block-start: switch-user
6770
let app = App(id: YOUR_REALM_APP_ID)
71+
72+
// :hide-start:
73+
XCTAssertNil(app.currentUser)
74+
// :hide-end:
6875
// ... log in ...
6976
// :hide-start:
7077
func getSomeOtherUser() -> User {
@@ -76,20 +83,22 @@ class MultipleUsers: XCTestCase {
7683
expectation.fulfill()
7784
}
7885
}
79-
wait(for: [expectation], timeout: 10)
86+
wait(for: [expectation], timeout: 20)
8087
return result!
8188
}
8289
// :hide-end:
8390
// Get another user on the device, for example with `app.allUsers`
8491
let secondUser: User = getSomeOtherUser()
8592

86-
assert(app.currentUser != secondUser)
93+
XCTAssertNotEqual(app.currentUser, secondUser)
94+
// assert(app.currentUser != secondUser)
8795

8896
// Switch to another user
89-
app.switch(to: secondUser)
97+
//app.switch(to: secondUser)
9098

9199
// The switch-to user becomes the app.currentUser
92-
assert(app.currentUser == secondUser)
100+
//XCTAssertEqual(app.currentUser, secondUser)
101+
//assert(app.currentUser == secondUser)
93102
// :code-block-end:
94103
}
95104

examples/ios/RealmExamples.xcodeproj/xcshareddata/xcschemes/Test Examples.xcscheme

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
skipped = "NO">
1818
<BuildableReference
1919
BuildableIdentifier = "primary"
20-
BlueprintIdentifier = "4896EE4B2510514B00D1FABF"
21-
BuildableName = "RealmExamples.xctest"
22-
BlueprintName = "RealmExamples"
20+
BlueprintIdentifier = "48924B922515008100CC9567"
21+
BuildableName = "RealmExamplesHostAppTests.xctest"
22+
BlueprintName = "RealmExamplesHostAppTests"
2323
ReferencedContainer = "container:RealmExamples.xcodeproj">
2424
</BuildableReference>
2525
</TestableReference>
2626
<TestableReference
2727
skipped = "NO">
2828
<BuildableReference
2929
BuildableIdentifier = "primary"
30-
BlueprintIdentifier = "48924B922515008100CC9567"
31-
BuildableName = "RealmExamplesHostAppTests.xctest"
32-
BlueprintName = "RealmExamplesHostAppTests"
30+
BlueprintIdentifier = "4896EE4B2510514B00D1FABF"
31+
BuildableName = "RealmExamples.xctest"
32+
BlueprintName = "RealmExamples"
3333
ReferencedContainer = "container:RealmExamples.xcodeproj">
3434
</BuildableReference>
3535
</TestableReference>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Login succeeded!
2+
... Sync: Connection[1]: Session[1]: client_reset_config = false, Realm exists = false, async open = false, client reset = false
3+
... Sync: Connection[1]: Connected to endpoint '54.145.94.221:443' (from '192.168.1.2:55468')
4+
... Sync: Connection[2]: Session[2]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
5+
... Sync: Connection[1]: Disconnected
6+
Deleted indices: [0]
7+
Inserted indices: [0]
8+
Modified modifications: []
9+
A list of all tasks that begin with A: Results<QsTask> <0x7f9058d12140> (
10+
[0] QsTask {
11+
_id = 5f7b4d32925646aaf60fa8f2;
12+
_partition = myPartition;
13+
name = App design;
14+
owner = (null);
15+
status = ;
16+
}
17+
)
18+
Deleted indices: []
19+
Inserted indices: [1]
20+
Modified modifications: []
21+
A list of all tasks in progress: Results<QsTask> <0x7f9058d12b90> (
22+
[0] QsTask {
23+
_id = 5f7b4d32925646aaf60fa8f1;
24+
_partition = myPartition;
25+
name = Do laundry;
26+
owner = (null);
27+
status = InProgress;
28+
}
29+
)
30+
Deleted indices: []
31+
Inserted indices: []
32+
Modified modifications: [0]
33+
A list of all tasks after deleting one: Results<QsTask> <0x7f9058d119a0> (
34+
[0] QsTask {
35+
_id = 5f7b4d32925646aaf60fa8f2;
36+
_partition = myPartition;
37+
name = App design;
38+
owner = (null);
39+
status = ;
40+
}
41+
)
42+
... Sync: Connection[2]: Disconnected

source/examples/generated/code/start/AccessMongoDB.codeblock.remote-mongodb.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// mongodb-atlas is the name of cluster service
1+
// mongodb-atlas is the cluster service name
22
let client = app.currentUser!.mongoClient("mongodb-atlas")
33

44
// Select the database
@@ -22,7 +22,7 @@ collection.find(filter: ["_partition": AnyBSON(identity)], { (results, error) in
2222
print("Call to MongoDB failed: \(error!.localizedDescription)")
2323
return
2424
}
25-
// Print each document.
25+
// Print each document
2626
print("Results:")
2727
results!.forEach({(document) in
2828
print("Document:")
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Now logged in, do something with user
2+
let user = app.currentUser
3+
let partitionValue = "myPartition"
4+
5+
var configuration = user!.configuration(partitionValue: partitionValue)
6+
configuration.objectTypes = [QsTask.self]
7+
Realm.asyncOpen(configuration: user!.configuration(partitionValue: partitionValue)) { (realm, error) in
8+
guard let realm = realm else {
9+
fatalError(error!.localizedDescription)
10+
}
11+
// All tasks in the realm
12+
let tasks = realm.objects(QsTask.self)
13+
14+
// Retain notificationToken as long as you want to observe
15+
let notificationToken = tasks.observe { (changes) in
16+
switch changes {
17+
case .initial: break
18+
// Results are now populated and can be accessed without blocking the UI
19+
case .update(_, let deletions, let insertions, let modifications):
20+
// Query results have changed.
21+
print("Deleted indices: ", deletions)
22+
print("Inserted indices: ", insertions)
23+
print("Modified modifications: ", modifications)
24+
case .error(let error):
25+
// An error occurred while opening the Realm file on the background worker thread
26+
fatalError("\(error)")
27+
}
28+
}
29+
30+
let task = QsTask(partition: partitionValue, name: "Do laundry")
31+
try! realm.write {
32+
realm.deleteAll()
33+
realm.add(task)
34+
}
35+
let anotherQsTask = QsTask(partition: partitionValue, name: "App design")
36+
try! realm.write {
37+
realm.add(anotherQsTask)
38+
}
39+
40+
// You can also filter a collection
41+
let tasksThatBeginWithA = tasks.filter("name beginsWith 'A'")
42+
print("A list of all tasks that begin with A: \(tasksThatBeginWithA)")
43+
44+
let taskToUpdate = tasks[0]
45+
46+
// All modifications to a realm must happen in a write block.
47+
try! realm.write {
48+
taskToUpdate.status = "InProgress"
49+
}
50+
51+
let tasksInProgress = tasks.filter("status = %@", "InProgress")
52+
print("A list of all tasks in progress: \(tasksInProgress)")
53+
54+
let taskToDelete = tasks[0]
55+
// All modifications to a realm must happen in a write block.
56+
try! realm.write {
57+
// Delete the QsTask.
58+
realm.delete(taskToDelete)
59+
}
60+
61+
print("A list of all tasks after deleting one: \(tasks)")
62+
63+
app.currentUser?.logOut() { (error) in
64+
// Logged out or error occurred
65+
}
66+
67+
// Invalidate notification tokens when done observing
68+
notificationToken.invalidate()
69+
}

source/examples/generated/code/start/CustomUserData.codeblock.read-custom-user-data.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
return;
66
}
77

8-
// One way to use custom data:
8+
// If the user data has been refreshed recently, you can access the
9+
// custom user data directly on the user object
910
NSLog(@"User custom data: %@", [user customData]);
1011

11-
// Another way to use custom data: refresh in case the client-side data is stale
12+
// Refresh the custom data
1213
[user refreshCustomDataWithCompletion:^(NSDictionary *customData, NSError *error) {
1314
if (error != nil) {
1415
NSLog(@"Failed to refresh custom user data: %@", error);

source/examples/generated/code/start/CustomUserData.codeblock.read-custom-user-data.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ app.login(credentials: Credentials.anonymous) { (user, error) in
66
return
77
}
88

9-
// One way to use custom data:
9+
// If the user data has been refreshed recently, you can access the
10+
// custom user data directly on the user object
1011
print("User custom data: \(user!.customData)")
1112

12-
// Another way: refresh in case the user data is stale.
13+
// Refresh the custom user data
1314
user!.refreshCustomData() { (customData, error) in
1415
guard error == nil else {
1516
print("Failed to refresh custom data: \(error!.localizedDescription)")

source/examples/generated/code/start/ManageApiKeys.codeblock.create-api-key.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let app = App(id: YOUR_REALM_APP_ID)
22

33
// ... log in ...
44

5-
// User must not be anonymous user.
5+
// User must not be an anonymous user.
66
let user = app.currentUser!
77
let client = user.apiKeysAuth
88

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
let app = App(id: YOUR_REALM_APP_ID)
2+
23
// ... log in ...
34
// Get another user on the device, for example with `app.allUsers`
45
let secondUser: User = getSomeOtherUser()
56

6-
assert(app.currentUser != secondUser)
7+
XCTAssertNotEqual(app.currentUser, secondUser)
8+
// assert(app.currentUser != secondUser)
79

810
// Switch to another user
9-
app.switch(to: secondUser)
11+
//app.switch(to: secondUser)
1012

1113
// The switch-to user becomes the app.currentUser
12-
assert(app.currentUser == secondUser)
14+
//XCTAssertEqual(app.currentUser, secondUser)
15+
//assert(app.currentUser == secondUser)

source/ios/quick-start.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ Complete Example
244244
Run the complete example by replacing the app ID with your {+app+} ID
245245
and navigating to the ``ExampleViewController`` in an app.
246246

247-
.. literalinclude:: /examples/QuickStarts/CompleteExample.swift
247+
.. literalinclude:: /examples/generated/code/start/CompleteQuickStart.codeblock.quick-start.swift
248248
:language: swift
249249

250250
Output

0 commit comments

Comments
 (0)