Я работаю в Swift, чтобы попытаться создать представление списка, в котором будут показаны все транзакции, связанные со всеми учетными записями с использованием Plaid API. Но когда я запускаю это, я ничего не получаю. Я пробовал несколько разных вещей, но ничего не помогает.
import UIKit
class TransactionViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
let communicator = ServerCommunicator()
var transactions: [Transaction] = []
override func viewDidLoad() {
super.viewDidLoad()
title = "Transactions"
tableView.dataSource = self
tableView.delegate = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "TransactionCell")
fetchTransactions()
}
private func fetchTransactions() {
communicator.callMyServer(path: "/server/transactions/get", httpMethod: .get) { (result: Result) in
DispatchQueue.main.async {
switch result {
case .success(let fetchedTransactions):
print("Fetched transactions: \(fetchedTransactions)") // Debug: Print fetched transactions
self.transactions = fetchedTransactions
self.tableView.reloadData()
case .failure(let error):
print("Failed to fetch transactions: \(error)") // Debug: Print error if fetch fails
}
}
}
}
// MARK: - UITableViewDataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("Number of transactions: \(transactions.count)") // Debug: Print number of rows in the table
return transactions.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TransactionCell", for: indexPath)
let transaction = transactions[indexPath.row]
// Debug: Print transaction data for each row
print("Transaction at index \(indexPath.row): \(transaction.date), \(transaction.description), $\(transaction.amount)")
cell.textLabel?.text = "\(transaction.date): \(transaction.description) - $\(transaction.amount)"
cell.detailTextLabel?.text = transaction.accountName
return cell
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... -plaid-api