Skip to content
Permalink
f111f7a80a
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
67 lines (57 sloc) 2.53 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] = []
var account: Account?
override func awake(withContext context: Any?) {
super.awake(withContext: context)
guard let data = context as? [String: Any],
let trans = data["transactions"] as? [Transaction],
let acct = data["acct"] as? Account else {
NSLog("Error receiving context containing transactions in TransactionsInterfaceController")
return
}
account = acct
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) {
guard let acct = account else { return }
let transaction = transactions[rowIndex]
let context: [String: Any] = ["transaction": transaction,
"merchant": transaction.merchantID,
"date": transaction.date,
"amount": transaction.amount,
"acct": acct]
pushController(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))
}
}
}
}