SimpleCurrencies is a Swift framework that allows the iOS developers to use the currencies in a simplier way.
- iOS 8.0+
- Swift 4.1+
- Xcode 9.3+
You can use CocoaPods to install SimpleCurrencies
by adding it to your Podfile
:
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
pod 'SimpleCurrencies', '~> 1.0'
end
import SimpleCurrencies
Import the framework to the files where you want use the SimpleCurrencies capabilities.
You are able to retrieve all the currencies available on the iOS device by calling SimpleCurrencies.all. This class variable will return an array of SimpleCurrency objects.
You can also get the current currency selected by default in the iOS device mapped as a SimpleCurrency object. In order to do this, just call SimpleCurrencies.current.
If you want to retrieve a currency as a SimpleCurrency object, you can call the class function SimpleCurrencies.currency(for code: String) and it will return a SimpleCurrency object if the currency is found or nil.
SimpleCurrencies.currency(for: "EUR")
In order to display a price to the users, you can call one of the two format methods. Those methods will allow you to get a string based on a number and a SimpleCurrency object or a currency code and the current locale of the iOS device.
Example:
let currency = SimpleCurrencies.currency(for: "EUR")
let value = SimpleCurrencies.format(currency: currency, value: 33.52)
print(value) // will print 33,52 € if the current locale is French
let value = SimpleCurrencies.format(for: "USD", value: 33.52)
print(value) // will print 33,52 $US if the current locale is French
In order to retrieve the metadata of a currency, you will manipulate the SimpleCurrency class.
public class SimpleCurrency {
public var name: String
public var symbol: String
public var code: String
public var codeNumber: Int?
public var description: String
}
If you have any suggestion or problem, feel free to open an issue.