CurrencyProviding
is a SwiftUI library that allows users to select a currency for an application.
The selected currency will be used for icons, strings, and text fields throughout the application.
- iOS: 17.0 or later.
You can install CurrencyProviding
using the Swift Package Manager.
- In Xcode, select "File" > "Add Package Dependencies".
- Copy & paste the following into the "Search or Enter Package URL" search bar.
https://github.com/JamesSedlacek/CurrencyProviding.git
- Xcode will fetch the repository & the "CurrencyProviding" library will be added to your project.
- Add
CurrencyProviding
to your project.
import CurrencyProviding
import SwiftUI
struct ContentView: View {
@State private var currencyProvider: CurrencyProvider = .init()
var body: some View {
VStack {
Text("Hello, world!")
}
.environment(currencyProvider)
}
}
- Add
CurrencyPicker
to the settings screen in your project.
import CurrencyProviding
import SwiftUI
struct SettingsView {
var body: some View {
VStack {
CurrencyPicker()
}
}
}
- Use
CurrencyProvider
for Icons, Strings, and TextFields.
import CurrencyProviding
import SwiftUI
struct ExampleView: View {
@Environment(CurrencyProvider.self)
private var currencyProvider
@State private var someNumber: Decimal = 0
private var decimalToCurrencyString: String {
currencyProvider.text(for: someNumber)
}
var body: some View {
VStack {
CurrencyTextField(value: $someNumber)
currencyProvider.icon(withCircle: true)
}
}
}