Created
July 17, 2018 10:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)") | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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