项目作者: iMac0de

项目描述 :
Currencies is a Swift framework that allows the iOS developers to use the currencies in a simplier way.
高级语言: Swift
项目地址: git://github.com/iMac0de/SimpleCurrencies.git
创建时间: 2018-04-16T10:05:01Z
项目社区:https://github.com/iMac0de/SimpleCurrencies

开源协议:MIT License

下载


SimpleCurrencies

SimpleCurrencies is a Swift framework that allows the iOS developers to use the currencies in a simplier way.

Requirements

  • iOS 8.0+
  • Swift 4.1+
  • Xcode 9.3+

Integration

CocoaPods (iOS 8.0+)

You can use CocoaPods to install SimpleCurrencies by adding it to your Podfile:

  1. platform :ios, '8.0'
  2. use_frameworks!
  3. target 'MyApp' do
  4. pod 'SimpleCurrencies', '~> 1.0'
  5. end

Usage

Initialization

  1. import SimpleCurrencies

Import the framework to the files where you want use the SimpleCurrencies capabilities.

Get all the currencies

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.

Get the current currency

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.

Get a currency for a specific code

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.

  1. SimpleCurrencies.currency(for: "EUR")

Convert a number to a string based on a currency

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:

  1. let currency = SimpleCurrencies.currency(for: "EUR")
  2. let value = SimpleCurrencies.format(currency: currency, value: 33.52)
  3. print(value) // will print 33,52 € if the current locale is French
  1. let value = SimpleCurrencies.format(for: "USD", value: 33.52)
  2. print(value) // will print 33,52 $US if the current locale is French

The Currency class

In order to retrieve the metadata of a currency, you will manipulate the SimpleCurrency class.

  1. public class SimpleCurrency {
  2. public var name: String
  3. public var symbol: String
  4. public var code: String
  5. public var codeNumber: Int?
  6. public var description: String
  7. }

Contribute

If you have any suggestion or problem, feel free to open an issue.