PhoneNumberKit alternatives and similar libraries
Based on the "Text" category.
Alternatively, view PhoneNumberKit alternatives based on common mentions on social networks and blogs.
-
YYText
Powerful text framework for iOS to display and edit rich text. -
Nimbus
The iOS framework that grows only as fast as its documentation -
ZSSRichTextEditor
A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view -
Twitter Text Obj
Twitter Text Libraries. This code is used at Twitter to tokenize and parse text to meet the expectations for what can be used on the platform. -
FontAwesomeKit
Icon font library for iOS. Currently supports Font-Awesome, Foundation icons, Zocial, and ionicons. -
libPhoneNumber-iOS
iOS port from libphonenumber (Google's phone number handling library) -
SwiftRichString
👩🎨 Elegant Attributed String composition in Swift sauce -
TwitterTextEditor
A standalone, flexible API that provides a full-featured rich text editor for iOS applications. -
RichEditorView
RichEditorView is a simple, modular, drop-in UIView subclass for Rich Text Editing. -
Down
Blazing fast Markdown / CommonMark rendering in Swift, built upon cmark. -
TextAttributes
An easier way to compose attributed strings -
FontAwesome.swift
Use FontAwesome in your Swift projects -
SwiftyMarkdown
Converts Markdown files and strings into NSAttributedStrings with lots of customisation options. -
SwiftString
A comprehensive, lightweight string extension for Swift -
Iconic
:art: Auto-generated icon font library for iOS, watchOS and tvOS -
MMMarkdown
An Objective-C framework for converting Markdown to HTML. -
CocoaMarkdown
Markdown parsing and rendering for iOS and OS X -
Atributika
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement. -
SwiftIconFont
Icons fonts for iOS (Font Awesome 5, Iconic, Ionicon, Octicon, Themify, MapIcon, MaterialIcon, Foundation 3, Elegant Icon, Captain Icon) -
FontBlaster
Programmatically load custom fonts into your iOS, macOS and tvOS app. -
Notepad
[iOS] A fully themeable markdown editor with live syntax highlighting. -
fuse-swift
A lightweight fuzzy-search library, with zero dependencies -
MarkdownKit
A simple and customizable Markdown Parser for Swift -
FormatterKit
stringWithFormat: for the sophisticated hacker set -
NSStringEmojize
A category on NSString to convert Emoji Cheat Sheet codes to their equivalent Unicode characters -
MarkdownTextView
Rich Markdown editing control for iOS -
Guitar
A Cross-Platform String and Regular Expression Library written in Swift. -
Mustard
🌭 Mustard is a Swift library for tokenizing strings when splitting by whitespace doesn't cut it. -
Translucid
Lightweight library to set an Image as text background. Written in swift. -
Heimdall
Heimdall is a wrapper around the Security framework for simple encryption/decryption operations. -
GoogleMaterialDesignIcons
Google Material Design Icons Font for iOS -
AttributedTextView
Easiest way to create an attributed UITextView (with support for multiple links and from html)
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of PhoneNumberKit or a related project?
README
PhoneNumberKit
Swift 5.3 framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.
Features
Features | |
---|---|
:phone: | Validate, normalize and extract the elements of any phone number string. |
:100: | Simple Swift syntax and a lightweight readable codebase. |
:checkered_flag: | Fast. 1000 parses -> ~0.4 seconds. |
:books: | Best-in-class metadata from Google's libPhoneNumber project. |
:trophy: | Fully tested to match the accuracy of Google's JavaScript implementation of libPhoneNumber. |
:iphone: | Built for iOS. Automatically grabs the default region code from the phone. |
📝 | Editable (!) AsYouType formatter for UITextField. |
:us: | Convert country codes to country names and vice versa |
Usage
Import PhoneNumberKit at the top of the Swift file that will interact with a phone number.
import PhoneNumberKit
All of your interactions with PhoneNumberKit happen through a PhoneNumberKit object. The first step you should take is to allocate one.
A PhoneNumberKit instance is relatively expensive to allocate (it parses the metadata and keeps it in memory for the object's lifecycle), you should try and make sure PhoneNumberKit is allocated once and deallocated when no longer needed.
let phoneNumberKit = PhoneNumberKit()
To parse a string, use the parse function. The region code is automatically computed but can be overridden if needed. PhoneNumberKit automatically does a hard type validation to ensure that the object created is valid, this can be quite costly performance-wise and can be turned off if needed.
do {
let phoneNumber = try phoneNumberKit.parse("+33 6 89 017383")
let phoneNumberCustomDefaultRegion = try phoneNumberKit.parse("+44 20 7031 3000", withRegion: "GB", ignoreType: true)
}
catch {
print("Generic parser error")
}
If you need to parse and validate a large amount of numbers at once, PhoneNumberKit has a special, lightning fast array parsing function. The default region code is automatically computed but can be overridden if needed. Here you can also ignore hard type validation if it is not necessary. Invalid numbers are ignored in the resulting array.
let rawNumberArray = ["0291 12345678", "+49 291 12345678", "04134 1234", "09123 12345"]
let phoneNumbers = phoneNumberKit.parse(rawNumberArray)
let phoneNumbersCustomDefaultRegion = phoneNumberKit.parse(rawNumberArray, withRegion: "DE", ignoreType: true)
PhoneNumber objects are immutable Swift structs with the following properties:
phoneNumber.numberString
phoneNumber.countryCode
phoneNumber.nationalNumber
phoneNumber.numberExtension
phoneNumber.type // e.g Mobile or Fixed
Formatting a PhoneNumber object into a string is also very easy
phoneNumberKit.format(phoneNumber, toType: .e164) // +61236618300
phoneNumberKit.format(phoneNumber, toType: .international) // +61 2 3661 8300
phoneNumberKit.format(phoneNumber, toType: .national) // (02) 3661 8300
PhoneNumberTextField
To use the AsYouTypeFormatter, just replace your UITextField with a PhoneNumberTextField (if you are using Interface Builder make sure the module field is set to PhoneNumberKit).
You can customize your TextField UI in the following ways
withFlag
will display the country code for thecurrentRegion
. TheflagButton
is displayed in theleftView
of the text field with it's size set based off your text size.withExamplePlaceholder
usesattributedPlaceholder
to show an example number for thecurrentRegion
. In addition whenwithPrefix
is set, the country code's prefix will automatically be inserted and removed when editing changes.
PhoneNumberTextField automatically formats phone numbers and gives the user full editing capabilities. If you want to customize you can use the PartialFormatter directly. The default region code is automatically computed but can be overridden if needed (see the example given below).
class MyGBTextField: PhoneNumberTextField {
override var defaultRegion: String {
get {
return "GB"
}
set {} // exists for backward compatibility
}
}
let textField = PhoneNumberTextField()
PartialFormatter().formatPartial("+336895555") // +33 6 89 55 55
You can also query countries for a dialing code or the dialing code for a given country
phoneNumberKit.countries(withCode: 33)
phoneNumberKit.countryCode(for: "FR")
Need more customization?
You can access the metadata powering PhoneNumberKit yourself, this enables you to program any behaviours as they may be implemented in PhoneNumberKit itself. It does mean you are exposed to the less polished interface of the underlying file format. If you program something you find useful please push it upstream!
phoneNumberKit.metadata(for: "AU")?.mobile?.exampleNumber // 412345678
[Preferred] Setting up with Swift Package Manager
The Swift Package Manager is now the preferred tool for distributing PhoneNumberKit.
From Xcode 11+ :
- Select File > Swift Packages > Add Package Dependency. Enter
https://github.com/marmelroy/PhoneNumberKit.git
in the "Choose Package Repository" dialog. - In the next page, specify the version resolving rule as "Up to Next Major" from "3.4.0".
- After Xcode checked out the source and resolving the version, you can choose the "PhoneNumberKit" library and add it to your app target.
For more info, read Adding Package Dependencies to Your App from Apple.
Alternatively, you can also add PhoneNumberKit to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/marmelroy/PhoneNumberKit", from: "3.4.0")
]
Setting up with Carthage
Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate PhoneNumberKit into your Xcode project using Carthage, specify it in your Cartfile
:
github "marmelroy/PhoneNumberKit"
Setting up with CocoaPods
pod 'PhoneNumberKit', :git => 'https://github.com/marmelroy/PhoneNumberKit'