Extendy - A set of useful string extensions.

Related tags

Utility Extendy
Overview

Extendy

A set of useful string extensions.

Cocoapods Cocoapods Cocoapods platforms

Requirements

  • iOS 11.0+
  • Swift 5+

Installation

CocoaPods

Extendy is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Extendy', '~> 1.1'

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding Extendy as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/NovichenkoAnton/Extendy.git", .upToNextMajor(from: "1.1"))
]

Usage

String

  1. Apply masks for the string in specific range. The range compatible with CountableRange, ClosedRange, PartialRangeFrom, PartialRangeThrough, PartialRangeUpTo.
let cardNumber = "1234567890123456"
let masked = cardNumber.maskSubstring(in: 6...13, with: "*")
print(masked!) //"123456********56"
  1. Convert String to Double. If String is not compatible with Double the function will return 0.00.
let amount = "100,12"
print(amount.toDouble()) //100.12

let anotherAmount = "1 200,10"
print(anotherAmount.toDouble()) //1200.1 
  1. You can apply specific format for strings
let sum = "1234"
let formattedSum = sum.ext.applyFormat(.sum)
print(formattedSum) //"1 234,00"

Supported formats

enum Format {
  case sum(minFractionDigits: Int = 2, maxFractionDigits: Int = 2)
  case creditCard
  case iban
  case custom(formatter: NumberFormatter)
}
  1. Validate a number of credit card by Luhn algorithm.

  2. Validate the string with specific pattern

"https://www.google.com".validate(with: .website) //true
  1. Simple date formatter (from one format to another)
let dateTime = "2019-11-22 13:33"

let resultTime = dateTime.ext.convertDate(from: "yyyy-MM-dd HH:mm", to: "h:mm") //"1:33"
  1. Get query items from String that corresponds to URL type. Works for URLs with cyrillic domain names.
let stringURL = "https://test.com?foo=1&bar=abc"

let queryItems = stringURL.queryItems()! //["foo": "1", "bar": "abc"]

NSMutableAttributedString

  1. You can append two attributed strings with +
let part1 = "123"
let part2 = "456"

myLabel.attributedText = part1.attributed + part2.attributed
  1. Apply attributes for mutable string
let string = "Some text"

label.attributedText = string.attributed.applyAttributes([
  .color(color: .red),
  .font(font: .systemFont(ofSize: 32, weight: .bold)),
  .crossed(width: 1, color: .black),
  .underline(style: .single, color: .blue)
])

screenshot1

  1. Apply styles for string
let sum = "1000,22"

label.attributedText = sum.attributed.applyStyle(.sum(integerAttrs: [
  .color(color: UIColor.red),
  .font(font: UIFont.systemFont(ofSize: 32, weight: .bold)),
  .underline(style: .double, color: .black)
], fractionAttrs: [
  .color(color: UIColor.green),
  .font(font: UIFont.systemFont(ofSize: 24, weight: .medium)),
], currencyMark: "$"))

screenshot2

You might also like...
DGLabelSize - Functions that calculate the size of uilabel based on different string lengths
DGLabelSize - Functions that calculate the size of uilabel based on different string lengths

DGLabelSize Functions that calculate the size of uilabel based on different stri

BFKit is a collection of useful classes and categories to develop Apps faster.

Swift Version • What does it do • Language support • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog •

A Collection of useful Swift property wrappers to make coding easier

Swift Property Wrappers A Collection of useful Swift property wrappers to make c

A collection of useful result builders for Swift and Foundation value types

Swift Builders A collection of useful result builders for Swift and Foundation value types. Motivation Arrays, dictionaries, and other collection-base

Extensions giving Swift's Codable API type inference super powers 🦸‍♂️🦹‍♀️
Extensions giving Swift's Codable API type inference super powers 🦸‍♂️🦹‍♀️

Welcome to Codextended — a suite of extensions that aims to make Swift’s Codable API easier to use by giving it type inference-powered capabilities an

A handy collection of more than 500 native Swift extensions to boost your productivity.

SwifterSwift is a collection of over 500 native Swift extensions, with handy methods, syntactic sugar, and performance improvements for wide range of

A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.

ZamzamKit ZamzamKit is a Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and othe

🌤 Swift Combine extensions for asynchronous CloudKit record processing

Swift Combine extensions for asynchronous CloudKit record processing. Designed for simplicity.

SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

Owner
Anton Novichenko
iOS developer
Anton Novichenko
Useful Swift code samples, extensions, functionalities and scripts to cherry-pick and use in your projects

SwiftyPick ?? ?? Useful Swift code samples, extensions, functionalities and scripts to cherry-pick and use in your projects. Purpose The idea behind t

Manu Herrera 19 May 12, 2022
Useful extensions for my Swift code

UIViewController extensions presentAlert(withTitle title: String, message : String) presentAlertDialog(withTitle title: String, message : String, acti

Bogdan Grafonsky 1 Oct 17, 2021
Personally useful Swift Extensions for iOS Development

Useful-Swift-Extensions Personally useful Swift Extensions for iOS Development; cobbled together from a variety of development projects and StackOverf

Nick Arner 5 Dec 13, 2021
Useful functions and extensions for sorting in Swift

SwiftSortUtils Motivation This library takes a shot at making comparing and sorting in Swift more pleasant. It also allows you to reuse your old NSSor

Daniel Strittmatter 60 Sep 9, 2022
Handy Combine extensions on NSObject, including Set.

Storable Description If you're using Combine, you've probably encountered the following code more than a few times. class Object: NSObject { var c

hcrane 23 Dec 13, 2022
This package will contain the standard encodings/decodings/hahsing used by the String Conversion Tool app.

This package will contain the standard encodings/decodings/hahsing used by the String Conversion Tool app. It will also, however, contain extra encoding/decoding methods (new encoding/decoding)

Gleb 0 Oct 16, 2021
Taking a string containing a csv file and split it into records (aka lines) containing fields of data (aka Array of SubStrings)

Swift .csv parser Taking a string containing a csv file and split it into records (aka lines) containing fields of data (aka Array of SubStrings). Par

Matthias 0 Dec 29, 2021
Decode a string encoded in Base64 into an https link and launch it in Google Chrome

Decode a string encoded in Base64 into an https link and launch it in Google Chr

Jerry 0 Jan 2, 2022
EmbeddedStringsKit: Representation localized string in code

EmbeddedStringsKit Representation localized string in code Usage public struct L

Muukii 1 Jul 13, 2022
ParserCombinators - String Parser Construction Kit

ParserCombinators provides a set of elementary building blocks for deriving stru

Marcel Tesch 0 Jan 7, 2022