Skip to content

Instantly share code, notes, and snippets.

Last active July 30, 2018 10:38
What would you like to do?
Retrieve a Ledger in Amatino Swift - A double-entry accounting library for iOS & MacOS
// Amatino Swift:
// Double entry accounting API
try Ledger.retrieve(
session: session,
entity: starkIndustries,
account: cashAccount,
callback: { (error: Error?, balance: Balance?) in
guard error == nil else {
// Handle error, e.g. 404 account not found, 403
// you are not authorised to view the account
guard let cashLedger: Ledger = ledger else {
// Should never happen, but practicing safe nil
// unwrapping is good feng shui
// Do cool stuff with cashLedger. For example, we can
// iterate over all the LedgerRows it contains:
for line in cashLedger {
print('Running balance: (\line.balance)')
// Ledgers are paginated in batches of 500 rows. To
// get the next 500 rows, we call .nextPage():
try! cashLedger.nextPage() { (error, rows) in
guard let newRows: [LedgerRow] = rows else {
// Handle errors
for line in newRows {
print('Running balance: (\line.balance)')
// The newly retrieved rows are now available in
// the original `cashLedger` as well.
Copy link

The parameters passed to Ledger.retrieve() may be found in the following gists:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment