Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SWF-10 Resolve swiftlint warnings, configure table for accounts
- created function to populate with “dummy” accounts
- created function to configure each row in table
- implemented `contextForSegue` function to allow us to “pass” the selected account to the next interface controller
  • Loading branch information
ahm11003 committed Mar 7, 2019
1 parent 4f91010 commit 3a44e11
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
Expand Up @@ -9,7 +9,6 @@
import WatchKit
import Foundation


class AccountDetailsInterfaceController: WKInterfaceController {

override func awake(withContext context: Any?) {
Expand Down
Expand Up @@ -9,17 +9,18 @@
import WatchKit
import Foundation


class AccountTableInterfaceController: WKInterfaceController {
var accounts: [Account] = []
var acctDict: [String: Account] = [:]

@IBOutlet weak var accountTable: WKInterfaceTable!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
accountTable.setNumberOfRows(5, withRowType: "account")
// Configure interface objects here.

populateDemoDate()
configureRows()
}



override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
Expand All @@ -30,4 +31,33 @@ class AccountTableInterfaceController: WKInterfaceController {
super.didDeactivate()
}

override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) {
acctDict["acct"] = accounts[rowIndex]
}

override func contextForSegue(withIdentifier segueIdentifier: String) -> Any? {
if segueIdentifier == "showAccountDetails" {
return acctDict
}

return nil
}

private func configureRows() {
accountTable.setNumberOfRows(accounts.count, withRowType: "account")

for index in 0..<accountTable.numberOfRows {
if let row = accountTable.rowController(at: index) as? AccountCell {
row.accountName.setText(accounts[index].accountNumber)
}
}
}

private func populateDemoDate() {
//swiftlint:disable line_length
accounts.append(Account(accountNumber: "TD Bank", limit: 500.00, transactions: [], paymentDueDate: Date(), cycleEndDate: Date()))
accounts.append(Account(accountNumber: "Care Credit", limit: 10000.00, transactions: [], paymentDueDate: Date(), cycleEndDate: Date()))
accounts.append(Account(accountNumber: "People's Bank", limit: 500.00, transactions: [], paymentDueDate: Date(), cycleEndDate: Date()))
accounts.append(Account(accountNumber: "Bank of America", limit: 10000.00, transactions: [], paymentDueDate: Date(), cycleEndDate: Date()))
}
}

0 comments on commit 3a44e11

Please sign in to comment.