Swiftpack.co - marinofelipe/CurrencyText as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by marinofelipe.
marinofelipe/CurrencyText 3.0.0
Currency text field formatter available for UIKit and SwiftUI πŸ’ΆβœοΈ
⭐️ 159
πŸ•“ 2 weeks ago
iOS
.package(url: "https://github.com/marinofelipe/CurrencyText.git", from: "3.0.0")

Build status Coverate status Swift Platform Swift Package Manager CocoaPods Compatible Twitter

CurrencyText provides lightweight libraries for formating text field text as currency, available for both UIKit and SwiftUI.

Its main core, the CurrencyFormatter class, can also be used a part from text fields to format any value that can be monetary represented.

If you need to present currency formatted text or allow users to input currency data, CurrencyText is going to help you do it in a readable and configurable matter.

Documentation

For details on how to use CurrencyText libraries please refer to the docs.

Installation

Swift Package Manager

To install it using Swift Package Manager, just add this repository through Xcode built-in Swift Packages, or by manually adding it to your Package.swift Package's dependencies:

dependencies: [
    .package(
    	url: "https://github.com/marinofelipe/CurrencyText.git", 
    	.upToNextMinor(from: .init(2, 1, 0)
    )
]

.target(
    name: "MyTarget",
    dependencies: [
    	// Can be imported to consume the formatter in insolation
        .target(name: "CurrencyFormatter"),

        // UIKit library - Provide access to "CurrencyFormatter" and "CurrencyUITextFieldDelegate" targets
        .target(name: "CurrencyText"),

        // SwiftUI library - Provide access to "CurrencyFormatter" and "CurrencyTextField" targets
        .target(name: "CurrencyTextSwiftUI")
    ],
    ...
)

Install via CocoaPods

To integrate CurrencyText using CocoaPods, specify it, one or more of its sub-specs in your Podfile:

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
     pod 'CurrencyText'

     # sub-specs

     # pod 'CurrencyText/CurrencyFormatter'
     # pod 'CurrencyText/CurrencyUITextField'
     # pod 'CurrencyText/CurrencyTextField'
end

Contributing

Contributions and feedbacks are always welcome. Please feel free to fork, follow, open issues and pull requests. The issues, milestones, and what we are currently working on can be seen in the main Project.

Special Thanks

To @malcommac for his awesome work with SwiftRichString and SwiftDate, that inspired me when creating this project. Also to myanalysis for contributing so much by finding issues and giving nice suggestions.

Copyright

CurrencyText is released under the MIT license. See LICENSE for details.

Felipe Marino: felipemarino91@gmail.com, @_marinofelipe

GitHub

link
Stars: 159
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

SwiftUI CurrencyFormater binding
2 weeks ago

Breaking

Change CurrencyTextFieldConfiguration.formatter to be a @Binding property, which aims to propagate state changes when the formatter is updated, like on formatter.currency changes.

When bumping to this release, users will have to update their CurrencyTextField usages passing a projected value for their formatters, prefixed with $.

CurrencyTextField(
    configuration: .init(
    // ...
    formatter: $currencyFormatter

In order to update the bound formatter, it must be re-initialized with the desired properties, since the view update is only triggered when the Binding changes, in that case the formatter instance itself:

CurrencyTextField(
Picker(
    "Change currency",
    selection: $currency
) {
    ForEach(
       [
           Currency.euro,
           Currency.dollar,
           Currency.brazilianReal,
           Currency.yen
       ],
       id: \.self
    ) {
        Text($0.rawValue).tag($0)
    }
}
.pickerStyle(.segmented)
.onChange(of: currency) { newValue in
     currencyFormatter = .init {
         $0.currency = newValue
         // other props
     }
}

For a full example, one case check the SwiftUIExampleView.swift on the Example app target, available in the CurrencyText.xcworkspace.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics