Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Bundle path issue for spm. #66

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions CountryPicker/Classes/CountryPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public struct Country {
}

public var flag: UIImage? {
#if SWIFT_PACKAGE
#if SWIFT_PACKAGE
let bundle = Bundle.module
#else
#else
let bundle = Bundle(for: CountryPicker.self)
#endif
#endif
return UIImage(named: flagName, in: bundle, compatibleWith: nil)
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public class CountryPicker: UIPickerView, UIPickerViewDelegate, UIPickerViewData
setupCountry()
}
}

//Countries list to be shown
private var countries: [Country] = Array(CountryPicker.countryNamesByCode())

Expand Down Expand Up @@ -164,7 +164,7 @@ public class CountryPicker: UIPickerView, UIPickerViewDelegate, UIPickerViewData
break
}
}

self.selectRow(row, inComponent: 0, animated: true)
let country = countries[row]
currentCountry = country
Expand All @@ -180,7 +180,11 @@ public class CountryPicker: UIPickerView, UIPickerViewDelegate, UIPickerViewData
/// - Returns: sorted array with all information phone, flag, name
private static func countryNamesByCode() -> Set<Country> {
var countries = Set<Country>()
#if SWIFT_PACKAGE
let frameworkBundle = Bundle.module
#else
let frameworkBundle = Bundle(for: self)
#endif
guard let jsonPath = frameworkBundle.path(forResource: "CountryPicker.bundle/Data/countryCodes", ofType: "json"), let jsonData = try? Data(contentsOf: URL(fileURLWithPath: jsonPath)) else {
return countries
}
Expand Down Expand Up @@ -249,7 +253,7 @@ public class CountryPicker: UIPickerView, UIPickerViewDelegate, UIPickerViewData
} else {
resultView = view as! CountryView
}

resultView.setup(countries[row])
if !showPhoneNumbers {
resultView.countryCodeLabel.isHidden = true
Expand Down