Skip to content
Permalink
c1383b37ca
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
48 lines (41 sloc) 1.93 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)
for i in 0..<5 {
transactions.append(Transaction(type: .purchase, amount: 50.00 * Double(i), merchantID: "WalMart Store 1245\(i)", date: Calendar.current.date(byAdding: .day, value: -i, to: Date()) ?? Date()))
transactions.append(Transaction(type: .reimbursement, amount: 12.5 * Double(i), merchantID: "Thank You", date: Calendar.current.date(byAdding: .day, value: -i, to: Date()) ?? Date()))
}
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()
}
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].type == .purchase ? UIColor.red : UIColor.green)
}
}
}
}