Skip to content

Instantly share code, notes, and snippets.

@hwjeremy
Created July 17, 2018 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hwjeremy/5e64b468e9830f38d5d2ef8ef565ddc9 to your computer and use it in GitHub Desktop.
Save hwjeremy/5e64b468e9830f38d5d2ef8ef565ddc9 to your computer and use it in GitHub Desktop.
Retrieve a Global Unit in Amatino Swift - A double-entry accounting library / framework for iOS & MacOS
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
GlobalUnit.retrieve(
unitId: 5, // The ID for U.S. dollars
session: session,
callback: { (error: Error?, unit: GlobalUnit?) in
guard error == nil else {
// Handle errors, e.g. a 404 for an unknown unit
}
guard let usd: GlobalUnit = unit else {
// Should never happen, but guarding against nil is
// good karma
}
// Do stuff with our shiny new unit
print("Retrieved Global Unit with code: \(usd.code)")
}
)
@hwjeremy
Copy link
Author

hwjeremy commented Jul 17, 2018

Global Units are units of account available across all Entities in Amatino. They are currently all currencies (E.g. USD, EUR, AUD) but will not necessarily be so in future. Hence the generic name.

The session instance used in this example may be seen in the Create Session gist

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