Skip to content

Commit

Permalink
Fix SPM support.
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Oct 2, 2021
1 parent d48ebe4 commit 767a7da
Show file tree
Hide file tree
Showing 267 changed files with 670 additions and 69 deletions.
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.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>CountryPickerView.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
3 changes: 1 addition & 2 deletions CountryPickerView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ Pod::Spec.new do |spec|
spec.source = { :git => "https://github.com/kizitonwose/CountryPickerView.git", :tag => spec.version }
spec.source_files = "CountryPickerView/**/*.{swift}"
spec.resource_bundles = {
'CountryPickerView' => ['CountryPickerView/Assets/CountryPickerView.bundle/*',
'CountryPickerView/**/*.{xib}']
'CountryPickerView_CountryPickerView' => ['CountryPickerView/Resources/*']
}
spec.pod_target_xcconfig = { 'SWIFT_VERSION' => '5.0' }

Expand Down
542 changes: 534 additions & 8 deletions CountryPickerView.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions CountryPickerView/Bundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import class Foundation.Bundle

private class BundleFinder {}

// For some reason this extension for SPM is not geneated when we build the
// framework (CMD + B) but gets generated when the framework is used in a progect.
// Just add it manually with the "_" prefix so it does not clash with the one
// that gets generated when used in a project.
extension Foundation.Bundle {
/// Returns the resource bundle associated with the current Swift module.
static var _module: Bundle = {
// We also use this name for the cocopods bundle (see podspec) so same code is used for SPM and Cocoapods.
let bundleName = "CountryPickerView_CountryPickerView"

let candidates = [
// Bundle should be present here when the package is linked into an App.
Bundle.main.resourceURL,

// Bundle should be present here when the package is linked into a framework.
Bundle(for: BundleFinder.self).resourceURL,

// For command-line tools.
Bundle.main.bundleURL,
]

for candidate in candidates {
let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle")
if let bundle = bundlePath.flatMap(Bundle.init(url:)) {
return bundle
}
}
// This should be a fallback for Carthage.
return Bundle(for: CountryPickerView.self)
// fatalError("unable to find bundle named CountryPickerView_CountryPickerView")
}()
}
30 changes: 13 additions & 17 deletions CountryPickerView/CountryPickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public struct Country: Equatable {
return locale.localizedString(forRegionCode: code)
}
public var flag: UIImage {
return UIImage(named: "CountryPickerView.bundle/Images/\(code.uppercased())",
in: Bundle(for: CountryPickerView.self), compatibleWith: nil)!
// Cocoapods || SPM
return UIImage(named: "Images/\(code.uppercased())", in: Bundle._module, compatibleWith: nil) ??
UIImage.init(named: code.uppercased(), in: Bundle._module, compatibleWith: nil)!
}
}

Expand Down Expand Up @@ -171,27 +172,22 @@ public class CountryPickerView: NibView {

public let countries: [Country] = {
var countries = [Country]()
let bundle = Bundle(for: CountryPickerView.self)
guard let jsonPath = bundle.path(forResource: "CountryPickerView.bundle/Data/CountryCodes", ofType: "json"),
let jsonData = try? Data(contentsOf: URL(fileURLWithPath: jsonPath)) else {
return countries
}

if let jsonObjects = (try? JSONSerialization.jsonObject(with: jsonData, options: JSONSerialization
.ReadingOptions.allowFragments)) as? Array<Any> {

// Cocoapods || SPM
let path = Bundle._module.path(forResource: "Data/CountryCodes", ofType: "json") ??
Bundle._module.path(forResource: "CountryCodes", ofType: "json")
guard let jsonPath = path, let jsonData = try? Data(contentsOf: URL(fileURLWithPath: jsonPath)) else {
return countries
}
if let jsonObjects = (try? JSONSerialization.jsonObject(with: jsonData, options: .allowFragments)) as? Array<Any> {
for jsonObject in jsonObjects {

guard let countryObj = jsonObject as? Dictionary<String, Any> else {
continue
}

guard let name = countryObj["name"] as? String,
let code = countryObj["code"] as? String,
let phoneCode = countryObj["dial_code"] as? String else {
continue
let code = countryObj["code"] as? String,
let phoneCode = countryObj["dial_code"] as? String else {
continue
}

let country = Country(name: name, code: code, phoneCode: phoneCode)
countries.append(country)
}
Expand Down
11 changes: 1 addition & 10 deletions CountryPickerView/NibView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@ public class NibView: UIView {

fileprivate func loadViewFromNib() -> UIView {
let selfName = String(describing: type(of: self))
let podBundle = Bundle(for: type(of: self))
let nibBundleURL = podBundle.url(forResource: selfName, withExtension: "bundle")!
var nibBundle = Bundle(url: nibBundleURL)
// The framework crashes if installed via Carthage because the nib
// file does not exist in the nibBundle but rather in the podBundle.
// This is a workaround.
if nibBundle?.url(forResource: selfName, withExtension: "nib") == nil {
nibBundle = podBundle
}
let nib = UINib(nibName: selfName, bundle: nibBundle)
let nib = UINib(nibName: selfName, bundle: Bundle._module)
let nibView = nib.instantiate(withOwner: self, options: nil).first as! UIView
return nibView
}
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
004CA2FB1F705DD600B690B8 /* Sources */,
004CA2FC1F705DD600B690B8 /* Frameworks */,
004CA2FD1F705DD600B690B8 /* Resources */,
D073A94C45743AB4CB4D944D /* [CP] Embed Pods Frameworks */,
509720AE1FDEE189001244B0 /* Embed Frameworks */,
93906A0D2037B5BC9ACD5600 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -177,7 +177,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
D073A94C45743AB4CB4D944D /* [CP] Embed Pods Frameworks */ = {
93906A0D2037B5BC9ACD5600 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,97 @@
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
4 changes: 2 additions & 2 deletions CountryPickerViewDemo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
CountryPickerView: 9b093bfffb4b06a69ba6185a798cadbf863720e7
CountryPickerView: 680940ad6a502cda951dd1b82547b0c78a03ccd7

PODFILE CHECKSUM: 1cd5c4aa4d0640ed508d2a66a00ff43232db9ee3

COCOAPODS: 1.9.3
COCOAPODS: 1.10.1
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ let package = Package(
targets: [
.target(
name: "CountryPickerView",
path: "CountryPickerView"
path: "CountryPickerView",
resources: [
.process("Resources")]
)
]
)

0 comments on commit 767a7da

Please sign in to comment.