Skip to content
Permalink
99e5d215fe
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
62 lines (51 sloc) 2.32 KB
//
// TransactionsInterfaceController.swift
// SynchronyFinancial WatchKit Extension
//
// Created by Alan Maynard on 3/20/19.
// Copyright © 2019 Alan Maynard. All rights reserved.
//
import WatchKit
import Foundation
class TransactionsInterfaceController: WKInterfaceController {
@IBOutlet weak var transactionsTable: WKInterfaceTable!
var transactions: [Transaction] = []
override func awake(withContext context: Any?) {
super.awake(withContext: context)
guard let data = context as? [String: [Transaction]], let trans = data["transactions"] else {
NSLog("Error receiving context containing transactions in TransactionsInterfaceController")
return
}
transactions = trans
configureRows()
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) {
let transaction = transactions[rowIndex]
let context: [String: Any] = ["transaction": transaction,
"merchant": transaction.merchantID,
"date": transaction.date,
"amount": transaction.amount]
presentController(withName: "TransactionDetails", context: context)
}
private func configureRows() {
// first sort our demo data in descending date order
transactions.sort(by: { $0.date > $1.date })
transactionsTable.setNumberOfRows(transactions.count, withRowType: "transactionCell")
for index in 0..<transactionsTable.numberOfRows {
if let row = transactionsTable.rowController(at: index) as? TransactionCell {
row.transactionLabel.setText(transactions[index].merchantID)
row.valueLabel.setText(String(format: "$%.2f", transactions[index].amount))
row.valueLabel.setTextColor(transactions[index].isPending == true ? UIColor.yellow :
(transactions[index].type == .purchase ? UIColor.red : UIColor.green))
}
}
}
}