Skip to content

Bluehawkify ios #490

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

Merged
merged 7 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,134 changes: 225 additions & 909 deletions source/includes/steps-tutorial-ios-swift.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tutorial/swift-ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ target 'Task Tracker' do
use_frameworks!

# Pods for Task Tracker
pod 'RealmSwift', '=10.0.0-beta.2'
pod 'RealmSwift', '=10.0.0-beta.5'
end
18 changes: 9 additions & 9 deletions tutorial/swift-ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
PODS:
- Realm (10.0.0-beta.2):
- Realm/Headers (= 10.0.0-beta.2)
- Realm/Headers (10.0.0-beta.2)
- RealmSwift (10.0.0-beta.2):
- Realm (= 10.0.0-beta.2)
- Realm (10.0.0-beta.5):
- Realm/Headers (= 10.0.0-beta.5)
- Realm/Headers (10.0.0-beta.5)
- RealmSwift (10.0.0-beta.5):
- Realm (= 10.0.0-beta.5)

DEPENDENCIES:
- RealmSwift (= 10.0.0-beta.2)
- RealmSwift (= 10.0.0-beta.5)

SPEC REPOS:
trunk:
- Realm
- RealmSwift

SPEC CHECKSUMS:
Realm: 211e32e680c354c9b1a2bdc0e3aeb01c25849641
RealmSwift: f9043abf9b6821ad5c3032c2a36b5ddfc90b4ce3
Realm: e30d3a77421b1b64932ce5843ba7d08afad749fd
RealmSwift: 80488a4f1388b2c5681066f0f26757989034edfb

PODFILE CHECKSUM: 49c6d560e0596c57f9cf8b64cefb18b9737acb7f
PODFILE CHECKSUM: 3644fa6ee99421f58a8dbba6a48b678d22974695

COCOAPODS: 1.9.1
136 changes: 50 additions & 86 deletions tutorial/swift-ios/Task Tracker/ManageTeamViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ class ManageTeamViewController: UIViewController, UITableViewDelegate, UITableVi
removeTeamMember(email: members[indexPath.row].name)
}

// :code-block-start: fetch-team-members
// Calls a Realm function to fetch the team members and adds them to the list
func fetchTeamMembers() {
// Start loading indicator
activityIndicator.startAnimating()
app.functions.getMyTeamMembers([]) { [weak self](result, error) in
// :hide-start:
app.currentUser()!.functions.getMyTeamMembers([]) { [weak self](result, error) in
DispatchQueue.main.sync {
guard self != nil else {
// This can happen if the view is dismissed
Expand All @@ -102,70 +104,47 @@ class ManageTeamViewController: UIViewController, UITableViewDelegate, UITableVi
self!.tableView.reloadData()
}
}
// :replace-with:
// // TODO: use the app's current user's functions object to call the getMyTeamMembers function
// // on the backend. Create Member objects to represent the result in the completion handler
// // and reload the table data to refresh the view.
// :hide-end:
}
// :code-block-end:

// :code-block-start: add-team-member
func addTeamMember(email: String) {
print("Adding member: \(email)")
activityIndicator.startAnimating()
app.functions.addTeamMember([AnyBSON(email)!], { [weak self] (result, realmError) in
// There are two kinds of errors:
// - The Realm function call itself failed (for example, due to network error)
// - The Realm function call succeeded, but our business logic within the function returned an error,
// (for example, email not found).
var errorMessage: String? = nil

if (realmError != nil) {
// Error from Realm (failed function call, network error...)
errorMessage = realmError!.localizedDescription
} else if let resultDocument = result?.documentValue {
// Check for user error. The addTeamMember function we defined returns an object
// with the `error` field set if there was a user error.
errorMessage = resultDocument["error"]??.stringValue
} else {
// The function call did not fail but the result was not a document.
// This is unexpected.
errorMessage = "Unexpected result returned from server"
}

// Log the success or failure to console.
if (errorMessage == nil) {
print("Successfully added user \(email)")
} else {
print("Failed to add user \(email): \(errorMessage!)")
}

// Now deal with the UI.
DispatchQueue.main.sync {
guard self != nil else {
return
}

// Always be sure to stop the activity indicator
self!.activityIndicator.stopAnimating()

// Present error message if any
guard errorMessage == nil else {
let alertController = UIAlertController(
title: "Error",
message: "\(errorMessage!)",
preferredStyle: .alert
);

alertController.addAction(UIAlertAction(title: "OK", style: .cancel))
self!.present(alertController, animated: true)
return
}

// Otherwise, fetch new team members list
self?.fetchTeamMembers()
}
})
// :hide-start:
app.currentUser()!.functions.addTeamMember([AnyBSON(email)!], self.onTeamMemberOperationComplete)
// :replace-with:
// // TODO: use the app's current user's functions object to call the addTeamMember function
// // on the backend with the given email converted to AnyBSON. Use `self.onTeamMemberOperationComplete`
// // as the completion handler.
// :hide-end:
}
// :code-block-end:

// :code-block-start: remove-team-member
func removeTeamMember(email: String) {
print("Removing member: \(email)")
activityIndicator.startAnimating()
app.functions.removeTeamMember([AnyBSON(email)!], { [weak self] (result, realmError) in
// :hide-start:
app.currentUser()!.functions.removeTeamMember([AnyBSON(email)!], self.onTeamMemberOperationComplete)
// :replace-with:
// // TODO: use the app's current user's functions object to call the removeTeamMember function
// // on the backend with the given email converted to AnyBSON. Use `self.onTeamMemberOperationComplete`
// // as the completion handler.
// :hide-end:
}
// :code-block-end:

private func onTeamMemberOperationComplete(result: AnyBSON?, realmError: Error?) {
DispatchQueue.main.sync {
// Always be sure to stop the activity indicator
activityIndicator.stopAnimating()

// There are two kinds of errors:
// - The Realm function call itself failed (for example, due to network error)
// - The Realm function call succeeded, but our business logic within the function returned an error,
Expand All @@ -184,39 +163,24 @@ class ManageTeamViewController: UIViewController, UITableViewDelegate, UITableVi
// This is unexpected.
errorMessage = "Unexpected result returned from server"
}

// Log the success or failure to console.
if (errorMessage == nil) {
print("Successfully removed user \(email)")
} else {
print("Failed to remove user \(email): \(errorMessage!)")
}

// Now deal with the UI.
DispatchQueue.main.sync {
guard self != nil else {
return
}

// Always be sure to stop the activity indicator
self!.activityIndicator.stopAnimating()
// Present error message if any
guard errorMessage == nil else {
print("Team operation failed: \(errorMessage!)")
let alertController = UIAlertController(
title: "Error",
message: errorMessage!,
preferredStyle: .alert
);

// Present error message if any
guard errorMessage == nil else {
let alertController = UIAlertController(
title: "Error",
message: "\(errorMessage!)",
preferredStyle: .alert
);

alertController.addAction(UIAlertAction(title: "OK", style: .cancel))
self!.present(alertController, animated: true)
return
}

// Otherwise, fetch new team members list
self?.fetchTeamMembers()
alertController.addAction(UIAlertAction(title: "OK", style: .cancel))
present(alertController, animated: true)
return
}
})

// Otherwise, fetch new team members list
print("Team operation successful")
fetchTeamMembers()
}
}
}
24 changes: 23 additions & 1 deletion tutorial/swift-ios/Task Tracker/Models.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Project.swift
// Models.swift
// Task Tracker
//
// Created by MongoDB on 2020-05-07.
Expand All @@ -9,32 +9,46 @@
import Foundation
import RealmSwift

// :code-block-start: user-model
class User: Object {
// :hide-start:
@objc dynamic var _id: String = ""
@objc dynamic var _partition: String = ""
@objc dynamic var name: String = ""
let memberOf = RealmSwift.List<Project>()
override static func primaryKey() -> String? {
return "_id"
}
// :replace-with:
// // TODO: Add User model (see SDKs panel in Realm UI)
// :hide-end:
}
// :code-block-end:

// :code-block-start: project-model
class Project: EmbeddedObject {
// :hide-start:
@objc dynamic var name: String? = nil
@objc dynamic var partition: String? = nil
convenience init(partition: String, name: String) {
self.init()
self.partition = partition
self.name = name
}
// :replace-with:
// // TODO: Add Project model (see SDKs panel in Realm UI)
// :hide-end:
}
// :code-block-end:

enum TaskStatus: String {
case Open
case InProgress
case Complete
}

// :code-block-start: task-model
// :hide-start:
class Task: Object {
@objc dynamic var _id: ObjectId = ObjectId.generate()
@objc dynamic var _partition: String = ""
Expand All @@ -60,6 +74,14 @@ class Task: Object {
self.name = name
}
}
// :replace-with:
// // TODO: Realm-ify Task model
// class Task {
// var name: String = ""
// var statusEnum: TaskStatus = .Open
// }
// :hide-end:
// :code-block-end:

struct Member {
let id: String
Expand Down
Loading