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.
CallingCodesKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'CallingCodesKit'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)
}
}
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")
}
}
}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()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.
imranrasheeddeveloper, [email protected]
CallingCodesKit is available under the MIT license. See the LICENSE file for more info.
