Skip to content

Commit

Permalink
Merge pull request #6 from 4ndrey/master
Browse files Browse the repository at this point in the history
optimize images loading
  • Loading branch information
deanrock authored Jan 18, 2017
2 parents 2ce9fff + c8ae148 commit 1d33e04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@
},
{
"name": "Kazakhstan",
"dial_code": "+77",
"dial_code": "+7",
"code": "KZ"
},
{
Expand Down
16 changes: 8 additions & 8 deletions MRCountryPicker/Classes/SwiftCountryPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ struct Country {
var code: String?
var name: String?
var phoneCode: String?
var flag: UIImage?

init(code: String?, name: String?, phoneCode: String?, flag: UIImage?) {
var flag: UIImage? {
guard let code = self.code else { return nil }
return UIImage(named: "SwiftCountryPicker.bundle/Images/\(code.uppercased())", in: Bundle(for: MRCountryPicker.self), compatibleWith: nil)
}

init(code: String?, name: String?, phoneCode: String?) {
self.code = code
self.name = name
self.phoneCode = phoneCode
self.flag = flag
}
}

Expand Down Expand Up @@ -97,10 +99,8 @@ open class MRCountryPicker: UIPickerView, UIPickerViewDelegate, UIPickerViewData
guard let code = countryObj["code"] as? String, let phoneCode = countryObj["dial_code"] as? String, let name = countryObj["name"] as? String else {
return countries
}

let flag = UIImage(named: "SwiftCountryPicker.bundle/Images/\(code.uppercased())", in: Bundle(for: type(of: self)), compatibleWith: nil)

let country = Country(code: code, name: name, phoneCode: phoneCode, flag: flag)

let country = Country(code: code, name: name, phoneCode: phoneCode)
countries.append(country)
}

Expand Down

0 comments on commit 1d33e04

Please sign in to comment.