Skip to content

Countries Calling Codes Use when Registring a phone number and want to get a country code Search Feature by code and By Country Name. Code will return you Country Name, Flag Image, dial code, and country code. lightweight and easy to use

License

Notifications You must be signed in to change notification settings

imranrasheeddeveloper/CallingCodesKit

Repository files navigation

CallingCodesKit

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first. The country code data is bundled with the framework so no additional setup is required.

Installation

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

pod 'CallingCodesKit'

Usage

Setup

import CallingCodesKit

class ViewController: UIViewController, callingCodeData
   
  {
    @IBOutlet weak var textLabel : UILabel!
    func countryCodeAndFlag(name: String, flag: String, code: String, dialCode: String) {
        textLabel.text = "\(flag) \(name) \(dialCode)"
    }
    @objc func callingCodeVC(){
        let vc = CallingCodesVC()
        vc.defaultCountryISOCode = "US" // show United States first
        vc.delegate = self
        navigationController?.pushViewController(vc, animated: true)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        let tap = UITapGestureRecognizer(target: self, action: #selector(callingCodeVC))
        textLabel.addGestureRecognizer(tap)    
    }
 }

SwiftUI

import SwiftUI
import CallingCodesKit

struct ContentView: View {
    @State private var selected: CountryCallingCode_Data?

    var body: some View {
        NavigationView {
            VStack {
                if let value = selected {
                    Text("\(value.flag ?? "") \(value.name ?? "") \(value.dialCode ?? "")")
                }
                NavigationLink("Select Country") {
                    CallingCodesListView(defaultCountryISOCode: "US") { country in
                        selected = country
                    }
                }
            }
            .navigationTitle("Example")
        }
    }
}

Programmatic Utilities

You can fetch calling code information without presenting any UI:

// Get all available countries
let allCountries = ContryJsonData.allCountries()

// Lookup by ISO code or dial code
let us = ContryJsonData.country(forISOCode: "US")
let plusOne = ContryJsonData.country(forDialCode: "+1")

// Country for the current device locale
let current = ContryJsonData.currentCountry()

Default Country

Both the view controller and the SwiftUI list let you specify a country that should appear at the top when presented. Simply set the defaultCountryISOCode property (or initializer parameter) to the desired ISO code.

Screenshot

IMG_9763

Author

imranrasheeddeveloper, [email protected]

License

CallingCodesKit is available under the MIT license. See the LICENSE file for more info.

About

Countries Calling Codes Use when Registring a phone number and want to get a country code Search Feature by code and By Country Name. Code will return you Country Name, Flag Image, dial code, and country code. lightweight and easy to use

Resources

License

Stars

Watchers

Forks

Packages

No packages published