Skip to content

Commit 53a43c1

Browse files
authored
Bluehawkify ios (#490)
* Update for beta.5 * Bluehawk-annotate ProjectsViewController * Annotate WelcomeViewController * Annotate TasksViewController * Annotate ManageTeamViewController * Bluehawk trials * Update iOS tutorial text WIP
1 parent 775ac86 commit 53a43c1

File tree

9 files changed

+485
-1094
lines changed

9 files changed

+485
-1094
lines changed

source/includes/steps-tutorial-ios-swift.yaml

Lines changed: 225 additions & 909 deletions
Large diffs are not rendered by default.

tutorial/swift-ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ target 'Task Tracker' do
66
use_frameworks!
77

88
# Pods for Task Tracker
9-
pod 'RealmSwift', '=10.0.0-beta.2'
9+
pod 'RealmSwift', '=10.0.0-beta.5'
1010
end

tutorial/swift-ios/Podfile.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
PODS:
2-
- Realm (10.0.0-beta.2):
3-
- Realm/Headers (= 10.0.0-beta.2)
4-
- Realm/Headers (10.0.0-beta.2)
5-
- RealmSwift (10.0.0-beta.2):
6-
- Realm (= 10.0.0-beta.2)
2+
- Realm (10.0.0-beta.5):
3+
- Realm/Headers (= 10.0.0-beta.5)
4+
- Realm/Headers (10.0.0-beta.5)
5+
- RealmSwift (10.0.0-beta.5):
6+
- Realm (= 10.0.0-beta.5)
77

88
DEPENDENCIES:
9-
- RealmSwift (= 10.0.0-beta.2)
9+
- RealmSwift (= 10.0.0-beta.5)
1010

1111
SPEC REPOS:
1212
trunk:
1313
- Realm
1414
- RealmSwift
1515

1616
SPEC CHECKSUMS:
17-
Realm: 211e32e680c354c9b1a2bdc0e3aeb01c25849641
18-
RealmSwift: f9043abf9b6821ad5c3032c2a36b5ddfc90b4ce3
17+
Realm: e30d3a77421b1b64932ce5843ba7d08afad749fd
18+
RealmSwift: 80488a4f1388b2c5681066f0f26757989034edfb
1919

20-
PODFILE CHECKSUM: 49c6d560e0596c57f9cf8b64cefb18b9737acb7f
20+
PODFILE CHECKSUM: 3644fa6ee99421f58a8dbba6a48b678d22974695
2121

2222
COCOAPODS: 1.9.1

tutorial/swift-ios/Task Tracker/ManageTeamViewController.swift

Lines changed: 50 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ class ManageTeamViewController: UIViewController, UITableViewDelegate, UITableVi
7373
removeTeamMember(email: members[indexPath.row].name)
7474
}
7575

76+
// :code-block-start: fetch-team-members
7677
// Calls a Realm function to fetch the team members and adds them to the list
7778
func fetchTeamMembers() {
7879
// Start loading indicator
7980
activityIndicator.startAnimating()
80-
app.functions.getMyTeamMembers([]) { [weak self](result, error) in
81+
// :hide-start:
82+
app.currentUser()!.functions.getMyTeamMembers([]) { [weak self](result, error) in
8183
DispatchQueue.main.sync {
8284
guard self != nil else {
8385
// This can happen if the view is dismissed
@@ -102,70 +104,47 @@ class ManageTeamViewController: UIViewController, UITableViewDelegate, UITableVi
102104
self!.tableView.reloadData()
103105
}
104106
}
107+
// :replace-with:
108+
// // TODO: use the app's current user's functions object to call the getMyTeamMembers function
109+
// // on the backend. Create Member objects to represent the result in the completion handler
110+
// // and reload the table data to refresh the view.
111+
// :hide-end:
105112
}
113+
// :code-block-end:
106114

115+
// :code-block-start: add-team-member
107116
func addTeamMember(email: String) {
108117
print("Adding member: \(email)")
109118
activityIndicator.startAnimating()
110-
app.functions.addTeamMember([AnyBSON(email)!], { [weak self] (result, realmError) in
111-
// There are two kinds of errors:
112-
// - The Realm function call itself failed (for example, due to network error)
113-
// - The Realm function call succeeded, but our business logic within the function returned an error,
114-
// (for example, email not found).
115-
var errorMessage: String? = nil
116-
117-
if (realmError != nil) {
118-
// Error from Realm (failed function call, network error...)
119-
errorMessage = realmError!.localizedDescription
120-
} else if let resultDocument = result?.documentValue {
121-
// Check for user error. The addTeamMember function we defined returns an object
122-
// with the `error` field set if there was a user error.
123-
errorMessage = resultDocument["error"]??.stringValue
124-
} else {
125-
// The function call did not fail but the result was not a document.
126-
// This is unexpected.
127-
errorMessage = "Unexpected result returned from server"
128-
}
129-
130-
// Log the success or failure to console.
131-
if (errorMessage == nil) {
132-
print("Successfully added user \(email)")
133-
} else {
134-
print("Failed to add user \(email): \(errorMessage!)")
135-
}
136-
137-
// Now deal with the UI.
138-
DispatchQueue.main.sync {
139-
guard self != nil else {
140-
return
141-
}
142-
143-
// Always be sure to stop the activity indicator
144-
self!.activityIndicator.stopAnimating()
145-
146-
// Present error message if any
147-
guard errorMessage == nil else {
148-
let alertController = UIAlertController(
149-
title: "Error",
150-
message: "\(errorMessage!)",
151-
preferredStyle: .alert
152-
);
153-
154-
alertController.addAction(UIAlertAction(title: "OK", style: .cancel))
155-
self!.present(alertController, animated: true)
156-
return
157-
}
158-
159-
// Otherwise, fetch new team members list
160-
self?.fetchTeamMembers()
161-
}
162-
})
119+
// :hide-start:
120+
app.currentUser()!.functions.addTeamMember([AnyBSON(email)!], self.onTeamMemberOperationComplete)
121+
// :replace-with:
122+
// // TODO: use the app's current user's functions object to call the addTeamMember function
123+
// // on the backend with the given email converted to AnyBSON. Use `self.onTeamMemberOperationComplete`
124+
// // as the completion handler.
125+
// :hide-end:
163126
}
127+
// :code-block-end:
164128

129+
// :code-block-start: remove-team-member
165130
func removeTeamMember(email: String) {
166131
print("Removing member: \(email)")
167132
activityIndicator.startAnimating()
168-
app.functions.removeTeamMember([AnyBSON(email)!], { [weak self] (result, realmError) in
133+
// :hide-start:
134+
app.currentUser()!.functions.removeTeamMember([AnyBSON(email)!], self.onTeamMemberOperationComplete)
135+
// :replace-with:
136+
// // TODO: use the app's current user's functions object to call the removeTeamMember function
137+
// // on the backend with the given email converted to AnyBSON. Use `self.onTeamMemberOperationComplete`
138+
// // as the completion handler.
139+
// :hide-end:
140+
}
141+
// :code-block-end:
142+
143+
private func onTeamMemberOperationComplete(result: AnyBSON?, realmError: Error?) {
144+
DispatchQueue.main.sync {
145+
// Always be sure to stop the activity indicator
146+
activityIndicator.stopAnimating()
147+
169148
// There are two kinds of errors:
170149
// - The Realm function call itself failed (for example, due to network error)
171150
// - The Realm function call succeeded, but our business logic within the function returned an error,
@@ -184,39 +163,24 @@ class ManageTeamViewController: UIViewController, UITableViewDelegate, UITableVi
184163
// This is unexpected.
185164
errorMessage = "Unexpected result returned from server"
186165
}
187-
188-
// Log the success or failure to console.
189-
if (errorMessage == nil) {
190-
print("Successfully removed user \(email)")
191-
} else {
192-
print("Failed to remove user \(email): \(errorMessage!)")
193-
}
194-
195-
// Now deal with the UI.
196-
DispatchQueue.main.sync {
197-
guard self != nil else {
198-
return
199-
}
200166

201-
// Always be sure to stop the activity indicator
202-
self!.activityIndicator.stopAnimating()
167+
// Present error message if any
168+
guard errorMessage == nil else {
169+
print("Team operation failed: \(errorMessage!)")
170+
let alertController = UIAlertController(
171+
title: "Error",
172+
message: errorMessage!,
173+
preferredStyle: .alert
174+
);
203175

204-
// Present error message if any
205-
guard errorMessage == nil else {
206-
let alertController = UIAlertController(
207-
title: "Error",
208-
message: "\(errorMessage!)",
209-
preferredStyle: .alert
210-
);
211-
212-
alertController.addAction(UIAlertAction(title: "OK", style: .cancel))
213-
self!.present(alertController, animated: true)
214-
return
215-
}
216-
217-
// Otherwise, fetch new team members list
218-
self?.fetchTeamMembers()
176+
alertController.addAction(UIAlertAction(title: "OK", style: .cancel))
177+
present(alertController, animated: true)
178+
return
219179
}
220-
})
180+
181+
// Otherwise, fetch new team members list
182+
print("Team operation successful")
183+
fetchTeamMembers()
184+
}
221185
}
222186
}

tutorial/swift-ios/Task Tracker/Models.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Project.swift
2+
// Models.swift
33
// Task Tracker
44
//
55
// Created by MongoDB on 2020-05-07.
@@ -9,32 +9,46 @@
99
import Foundation
1010
import RealmSwift
1111

12+
// :code-block-start: user-model
1213
class User: Object {
14+
// :hide-start:
1315
@objc dynamic var _id: String = ""
1416
@objc dynamic var _partition: String = ""
1517
@objc dynamic var name: String = ""
1618
let memberOf = RealmSwift.List<Project>()
1719
override static func primaryKey() -> String? {
1820
return "_id"
1921
}
22+
// :replace-with:
23+
// // TODO: Add User model (see SDKs panel in Realm UI)
24+
// :hide-end:
2025
}
26+
// :code-block-end:
2127

28+
// :code-block-start: project-model
2229
class Project: EmbeddedObject {
30+
// :hide-start:
2331
@objc dynamic var name: String? = nil
2432
@objc dynamic var partition: String? = nil
2533
convenience init(partition: String, name: String) {
2634
self.init()
2735
self.partition = partition
2836
self.name = name
2937
}
38+
// :replace-with:
39+
// // TODO: Add Project model (see SDKs panel in Realm UI)
40+
// :hide-end:
3041
}
42+
// :code-block-end:
3143

3244
enum TaskStatus: String {
3345
case Open
3446
case InProgress
3547
case Complete
3648
}
3749

50+
// :code-block-start: task-model
51+
// :hide-start:
3852
class Task: Object {
3953
@objc dynamic var _id: ObjectId = ObjectId.generate()
4054
@objc dynamic var _partition: String = ""
@@ -60,6 +74,14 @@ class Task: Object {
6074
self.name = name
6175
}
6276
}
77+
// :replace-with:
78+
// // TODO: Realm-ify Task model
79+
// class Task {
80+
// var name: String = ""
81+
// var statusEnum: TaskStatus = .Open
82+
// }
83+
// :hide-end:
84+
// :code-block-end:
6385

6486
struct Member {
6587
let id: String

0 commit comments

Comments
 (0)