Skip to content

Commit 666cdf0

Browse files
committed
optimize images loading
1 parent 2ce9fff commit 666cdf0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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)