Skip to content

Instantly share code, notes, and snippets.

@quintonwall
Created March 23, 2015 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quintonwall/7df9fd3975ebb5ae4574 to your computer and use it in GitHub Desktop.
Save quintonwall/7df9fd3975ebb5ae4574 to your computer and use it in GitHub Desktop.
TaskListController completed class for Salesforce Wear Apple Watch webinar
//
// TaskListController.swift
// SalesforceWatch
//
// Created by Quinton Wall on 3/23/15.
// Copyright (c) 2015 Salesforce, Inc. All rights reserved.
//
import Foundation
import WatchKit
class TaskListController: WKInterfaceController {
@IBOutlet weak var resultsTable: WKInterfaceTable!
var results: NSArray!
override func willActivate() {
super.willActivate()
if (self.results == nil) {
self.getTaskList()
} else {
self.loadTableData(self.results)
}
}
private func getTaskList() {
let requestBundle = ["request-type" : "task-list"]
WKInterfaceController.openParentApplication(requestBundle, reply: { [unowned self](reply, error) -> Void in
if let reply = reply as? [String: NSArray] {
self.results = reply["results"]
self.loadTableData(self.results)
}
else {
println("no response")
}
})
}
private func loadTableData(results: NSArray) {
//withRowType needs to be the identifier you give the table in your storyboard
resultsTable.setNumberOfRows(results.count, withRowType: "TaskRows")
for (index, record) in enumerate(results) {
let row = resultsTable.rowControllerAtIndex(index) as TaskRowController
var s: NSDictionary = record as NSDictionary
row.priorityImage.setImageNamed("priority-"+(s["Priority"] as? String)!)
row.recordid = s["Id"] as? String
row.status.setText(s["Status"] as? String)
row.subject.setText(s["Subject"] as? String)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment