Skip to content

Commit 1d33e04

Browse files
authored
Merge pull request #6 from 4ndrey/master
optimize images loading
2 parents 2ce9fff + c8ae148 commit 1d33e04

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

MRCountryPicker/Assets/SwiftCountryPicker.bundle/Data/countryCodes.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@
546546
},
547547
{
548548
"name": "Kazakhstan",
549-
"dial_code": "+77",
549+
"dial_code": "+7",
550550
"code": "KZ"
551551
},
552552
{

MRCountryPicker/Classes/SwiftCountryPicker.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ struct Country {
99
var code: String?
1010
var name: String?
1111
var phoneCode: String?
12-
var flag: UIImage?
13-
14-
init(code: String?, name: String?, phoneCode: String?, flag: UIImage?) {
12+
var flag: UIImage? {
13+
guard let code = self.code else { return nil }
14+
return UIImage(named: "SwiftCountryPicker.bundle/Images/\(code.uppercased())", in: Bundle(for: MRCountryPicker.self), compatibleWith: nil)
15+
}
16+
17+
init(code: String?, name: String?, phoneCode: String?) {
1518
self.code = code
1619
self.name = name
1720
self.phoneCode = phoneCode
18-
self.flag = flag
1921
}
2022
}
2123

@@ -97,10 +99,8 @@ open class MRCountryPicker: UIPickerView, UIPickerViewDelegate, UIPickerViewData
9799
guard let code = countryObj["code"] as? String, let phoneCode = countryObj["dial_code"] as? String, let name = countryObj["name"] as? String else {
98100
return countries
99101
}
100-
101-
let flag = UIImage(named: "SwiftCountryPicker.bundle/Images/\(code.uppercased())", in: Bundle(for: type(of: self)), compatibleWith: nil)
102-
103-
let country = Country(code: code, name: name, phoneCode: phoneCode, flag: flag)
102+
103+
let country = Country(code: code, name: name, phoneCode: phoneCode)
104104
countries.append(country)
105105
}
106106

0 commit comments

Comments
 (0)