{"id":15391230,"url":"https://github.com/pjechris/swiftphonenumber","last_synced_at":"2025-06-14T16:38:21.110Z","repository":{"id":80643012,"uuid":"295808365","full_name":"pjechris/SwiftPhoneNumber","owner":"pjechris","description":"Easily parse and format phone numbers","archived":false,"fork":false,"pushed_at":"2021-04-12T10:04:17.000Z","size":82,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T12:38:30.269Z","etag":null,"topics":["contacts","country-codes","country-flags","domain-driven-design","formatter","phonenumber","swift-package-manager"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pjechris.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-15T17:57:07.000Z","updated_at":"2023-02-06T22:33:47.000Z","dependencies_parsed_at":"2023-03-22T12:17:45.662Z","dependency_job_id":null,"html_url":"https://github.com/pjechris/SwiftPhoneNumber","commit_stats":{"total_commits":30,"total_committers":1,"mean_commits":30.0,"dds":0.0,"last_synced_commit":"b2cc34b2c0c09218ab50f94227d9812a08b6a612"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjechris%2FSwiftPhoneNumber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjechris%2FSwiftPhoneNumber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjechris%2FSwiftPhoneNumber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjechris%2FSwiftPhoneNumber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pjechris","download_url":"https://codeload.github.com/pjechris/SwiftPhoneNumber/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241225519,"owners_count":19930198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["contacts","country-codes","country-flags","domain-driven-design","formatter","phonenumber","swift-package-manager"],"created_at":"2024-10-01T15:10:24.706Z","updated_at":"2025-02-28T20:19:30.095Z","avatar_url":"https://github.com/pjechris.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftPhoneNumber\n\n![SPM](https://img.shields.io/static/v1?label=Swift%20PM\u0026message=%E2%9C%93\u0026color=24C28A\u0026labelColor=444444)\n[![Twitter Follow](https://img.shields.io/twitter/follow/pjechris.svg?label=Follow%20me)](https://twitter.com/pjechris)\n\nA simple domain-oriented library to handle phone numbers! Compatible with all platforms where Swift run (see Compatibility section for more information).\n\nGoal of the library is to be as simple to use as possible AND easy to add new functionalities such as Countries.\n\n*Contribution to complete missing countries is appreciated.*\n\n## Usage\n\nSwiftPhoneNumber allow you to build **only valid** numbers:\n```swift\nimport SwiftPhoneNumber\n\ndo {\n    let phoneNumber = try PhoneNumber(number: \"+33102030405\")\n    // OR\n    let phoneNumber = try PhoneNumber(number: \"+33102030405\", for: [.fra, .usa, ...])\n}\ncatch {\n\n}\n```\nOnce you have it, do whatever you want with it.\n\nSwiftPhoneNumber also provide a formatter for `UITextField`:\n\n```swift\nimport SwiftPhoneNumber\nimport SwiftPhoneNumber_UIKit\n\nclass ViewController: UIViewController {\n    @IBOutlet var textField: UITextField!\n\n    let delegate = TextFieldPhoneNumberDelegate()\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        textField.delegate = delegate\n    }\n}\n```\nYou can then get current input object directly from the delegate:\n\n```swift\n\n// nil if no input, an error if number is not valid otherwise a `PhoneNumber` object\ndelegate.value\n\n```\n\n\u003e try it out running our example SwiftPhoneNumberExample\n\n## Installation\n\nSwiftPhoneNumber can be installed throughout Swift Package Manager:\n\n```swift\n\nlet package = Package(\n    name: \"YourAwesomeProject\",\n    products: [],\n    dependencies: [\n        // remember to change version number to use latest available\n        .package(url: \"https://github.com/pjechris/SwiftPhoneNumber\", from: \"0.0\"),\n    ],\n    targets: [\n        name: \"YourTarget\",\n        dependencies: [\n            \"SwiftPhoneNumber\",\n            .product(\"SwiftPhoneNumber-UIKit\", package: \"SwiftPhoneNumber\") // \u003c- add this only if you want to have UITextField support\n        ]\n    ]\n```\n\n## Compatibility\n\nSwiftPhoneNumber should be able to run on any platform where Swift. That being said it has only been tested on iOS. If you find an incompatibility issue, pleas fill a bug.\n\n## Supported countries\n\nSee [Countries](Countries.md)\n\n## Participing\n\n### New country\nTo add a new country:\n\n- Add it to `Country.swift`. You'll have to provide info such name, flag emoji, iso codes.\n- Define phone metadata and a formatter (or reuse one existing)\n- Add those new data into `Country+Data`\n\n### PhoneNumberFormatter\n\n`PhoneNumberFormatter` is used to format a country. To create your own, you just have to make a new instance and pass 2 format style:\n- one for international formatting\n- one for national formatting.\n\nIf both are the same you can just pass one argument.\n\n```swift\n// Available interpolations are:\n// - .code to international/nationalcode\n// - a Int number that will take Int characters from subscriber number\nlet franceFormatter = PhoneNumberFormatter(\"\\(.code)\\(1) \\(2) \\(2) \\(2) \\(2)\")\n```\n\nWith a french number \"0102030405\" it would give \"01 02 03 04 05\"\n\n### TextFieldPhoneNumberDelegate\n\nSomething is wrong with our `TextFieldPhoneNumberDelegate`? Or maybe you want something more? Under the hood `TextFieldPhoneNumberDelegate` is just a `TextFieldFormatterDelegate` with a `InputFormatter` to define formatting rules:\n\n- How to clean the user input\n- How to convert it into a `PhoneNumber`\n- How to format the result (delegated to `PhoneNumberFormatter`)\n\nSo just define your own if you need to.\n\n\n## License\nThis project is released under the MIT License. Please see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpjechris%2Fswiftphonenumber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpjechris%2Fswiftphonenumber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpjechris%2Fswiftphonenumber/lists"}