Skip to content

Commit 53992fd

Browse files
committed
* Made countries array a public variable and now can be accessed through CountryListManager shared instance.
1 parent a8bd205 commit 53992fd

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Diff for: CountryPicker/CountryPicker/Classes/CountryInfo/Country.swift

+8
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,12 @@ public class Country: NSObject {
4242
self.name = name
4343
self.localeId = localeId
4444
}
45+
46+
public override var description: String {
47+
return "\n{\n index: \(self.index),\n"
48+
+ " country: \(self.name),\n"
49+
+ " isoCountryCode: \(self.isoCountryCode),\n"
50+
+ " localeId: \(self.localeId),\n"
51+
+ " flagImageName: \(self.flagImageName!)\n}"
52+
}
4553
}

Diff for: CountryPicker/CountryPicker/Classes/CountryInfo/CountryListManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class CountryListManager {
1616
// MARK: -
1717
var countryListReady: Bool
1818
var ommitedCountriesArr: [String] = [] // Some countries have to be omitted because they don't have Flags
19-
var countries: [Country] = []
19+
public var countries: [Country] = []
2020
var countryFlagImageArr: [String] = []
2121

2222
// Initialization

Diff for: CountryPickerDemo/CountryPickerDemo/ViewController.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ class ViewController: UIViewController {
2727

2828
// TextFieldDelegate
2929
countryTxtFld.delegate = self
30+
31+
// fetch a list of countries
32+
let countryListManager = CountryListManager.shared
33+
let countriesArr = countryListManager.countries
34+
print("Countries: \(String(describing: countriesArr))")
3035
}
3136
}
3237

33-
extension ViewController : CountryPickerTableViewControllerDelegate {
38+
extension ViewController: CountryPickerTableViewControllerDelegate {
3439

3540
func didSelectCountry(country: Country?) {
3641
if country != nil {
@@ -41,7 +46,7 @@ extension ViewController : CountryPickerTableViewControllerDelegate {
4146
}
4247
}
4348

44-
extension ViewController : UITextFieldDelegate {
49+
extension ViewController: UITextFieldDelegate {
4550

4651
func textFieldDidBeginEditing(_ textField: UITextField) {
4752
textField.resignFirstResponder()

0 commit comments

Comments
 (0)