Skip to content

Commit

Permalink
Updated version to '2.1.0', modified readme file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Orlov committed Jan 16, 2021
1 parent a8973d5 commit 47d7982
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion AnyFormatKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AnyFormatKit'
s.version = '2.0.6'
s.version = '2.1.0'
s.summary = 'Simple text formatting in Swift.'

s.description = <<-DESC
Expand Down
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

[![CI Status](http://img.shields.io/travis/luximetr/AnyFormatKit.svg?style=flat)](https://travis-ci.org/luximetr/AnyFormatKit)
[![Version](https://img.shields.io/cocoapods/v/AnyFormatKit.svg?style=flat)](http://cocoapods.org/pods/AnyFormatKit)
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![License](https://img.shields.io/cocoapods/l/AnyFormatKit.svg?style=flat)](http://cocoapods.org/pods/AnyFormatKit)
[![Platform](https://img.shields.io/cocoapods/p/AnyFormatKit.svg?style=flat)](http://cocoapods.org/pods/AnyFormatKit)
![Swift](https://img.shields.io/badge/%20in-swift%205.0-brightgreen.svg)
Expand All @@ -17,6 +16,9 @@ Text formatting framework written on Swift 5.0.
:performing_arts:| Convert string into formatted string and vice versa
:bicyclist:| Formatting text during typing
:hash:| Set format using '#' characters like '### ##-###'
:stuck_out_tongue:| Supporting emojis
:heavy_dollar_sign:| Formatting money amount
:parking:| Formatting with placeholders


## Example
Expand Down Expand Up @@ -59,6 +61,16 @@ Then, run the following command:
$ pod install
```

### Swift Package Manager
AnyFormatKit is available with [Swift Package Manager](https://swift.org/package-manager/).
Once you have your Swift package set up, than simply add AnyFormatKit to the `dependencies` value of your `Package.swift`

```swift
dependencies: [
.package(url: "https://github.com/luximetr/AnyFormatKit.git", .upToNextMajor(from: "2.1.0"))
]
```

## Usage

### Import
Expand Down Expand Up @@ -98,9 +110,23 @@ Unformatting
let formatter = DefaultTextFormatter(textPattern: "## ###-##")
formatter.unformat("99 888-77") // 9988877
```
### Formatting with PlaceholderTextFormatter

```swift
let phoneFormatter = PlaceholderTextFormatter(textPattern: "### (###) ###-##-##")
phoneFormatter.format("+123") // +12 (3##) ###-##-##
```

### Formatting with SumTextFormatter

```swift
let formatter = SumTextFormatter(textPattern: "#,###.##")
formatter.format("1234.13") // 1,234.13
```

### Formatting during typing

Code from example app
Using `DefaultTextInputFormatter` formatter

```swift
let formatter = DefaultTextInputFormatter(textPattern: "### (###) ###-##-##")
Expand All @@ -111,6 +137,28 @@ textView.text = result.formattedText
textView.setCursorLocation(result.caretBeginOffset)
```

Using `SumTextInputFormatter` formatter

```swift
let formatter = SumTextInputFormatter(textPattern: "#,###.##$")

// inside of UITextFieldDelegate shouldChangeTextIn method
let result = formatter.formatInput(currentText: textView.text, range: range, replacementString: text)
textView.text = result.formattedText
textView.setCursorLocation(result.caretBeginOffset)
```

Using `PlaceholderTextInputFormatter` formatter

```swift
let formatter = PlaceholderTextInputFormatter(textPattern: "#### #### #### ####")

// inside of UITextFieldDelegate shouldChangeTextIn method
let result = formatter.formatInput(currentText: textView.text, range: range, replacementString: text)
textView.text = result.formattedText
textView.setCursorLocation(result.caretBeginOffset)
```

## Author

luximetr, [email protected]
Expand Down

0 comments on commit 47d7982

Please sign in to comment.