您可以使用 Swift Package Manager 来安装 DEPhoneNumberFormatter,只需将以下依赖项添加到您的 Package.swift 文件中
.package(url: "https://github.com/Darkngs/DEPhoneNumberFormatter.git", from: "2.0.0"),
或者,您可以直接将 DEPhoneNumberFormatter.swift 和 DEPhoneNumberTextField.swift 源文件添加到您的项目中。
// NANP countries
let phoneNumberFormatter = DEPhoneNumberFormatter()
print(phoneNumberFormatter.number(from: "1"))
print(phoneNumberFormatter.number(from: "12"))
print(phoneNumberFormatter.number(from: "123"))
print(phoneNumberFormatter.number(from: "1234"))
print(phoneNumberFormatter.number(from: "12345"))
print(phoneNumberFormatter.number(from: "123456"))
print(phoneNumberFormatter.number(from: "1234567"))
print(phoneNumberFormatter.number(from: "12345678"))
print(phoneNumberFormatter.number(from: "123456789"))
print(phoneNumberFormatter.number(from: "1234567890"))
(1
(12
(123
(123) 4
(123) 45
(123) 456
(123) 456-7
(123) 456-78
(123) 456-789
(123) 456-7890
let textField = DEPhoneNumberTextField()
textField.setup()