Skip to content

Commit 5acae56

Browse files
ollitapawtmoose
andauthored
Couple of fixes for xcode12 support (SwiftKickMobile#418)
* Add resources to Package.swift * Fix bundle search method * Search for CocoaPods bunlde * Remove redundant resources declaration * Streamline implementation a bit and return a fallback value Co-authored-by: Timothy Moose <tim@swiftkick.it>
1 parent f1c9e25 commit 5acae56

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ playground.xcworkspace
4747
*.pkey
4848
screenshots
4949
rvm.env
50+
.build

SwiftMessages.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Pod::Spec.new do |spec|
1515

1616
spec.subspec 'App' do |app|
1717
app.source_files = 'SwiftMessages/**/*.swift'
18-
app.resource_bundles = {'SwiftMessages' => ['SwiftMessages/Resources/**/*']}
18+
app.resource_bundles = {'SwiftMessages_SwiftMessages' => ['SwiftMessages/Resources/*.{xib,xcassets}']}
1919
end
2020

2121
spec.subspec 'AppExtension' do |ext|
2222
ext.source_files = 'SwiftMessages/**/*.swift'
2323
ext.exclude_files = 'SwiftMessages/**/SegueConvenienceClasses.swift'
24-
ext.resource_bundles = {'SwiftMessages' => ['SwiftMessages/Resources/**/*']}
24+
ext.resource_bundles = {'SwiftMessages_SwiftMessages' => ['SwiftMessages/Resources/**/*.{xib,xcassets}']}
2525

2626
# For app extensions, disabling code paths using unavailable API
2727
ext.pod_target_xcconfig = {

SwiftMessages/NSBundle+Utils.swift

+33-12
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,41 @@
88

99
import Foundation
1010

11+
private class BundleToken {}
12+
1113
extension Bundle {
14+
// This is copied method from SPM generated Bundle.module for CocoaPods support
1215
static func sm_frameworkBundle() -> Bundle {
13-
let bundle = Bundle(for: MessageView.self)
14-
// Check for Swift Package Manager bundle name
15-
if let path = bundle.path(forResource: "SwiftMessages_SwiftMessages", ofType: "bundle") {
16-
return Bundle(path: path)!
17-
}
18-
// Check for CocoaPods or Carthage bundle name
19-
else if let path = bundle.path(forResource: "SwiftMessages", ofType: "bundle") {
20-
return Bundle(path: path)!
21-
}
22-
// Just return the app bundle
23-
else {
24-
return bundle
16+
17+
let candidates = [
18+
// Bundle should be present here when the package is linked into an App.
19+
Bundle.main.resourceURL,
20+
21+
// Bundle should be present here when the package is linked into a framework.
22+
Bundle(for: BundleToken.self).resourceURL,
23+
24+
// For command-line tools.
25+
Bundle.main.bundleURL,
26+
]
27+
28+
let bundleNames = [
29+
// For Swift Package Manager
30+
"SwiftMessages_SwiftMessages",
31+
32+
// For Carthage
33+
"SwiftMessages",
34+
]
35+
36+
for bundleName in bundleNames {
37+
for candidate in candidates {
38+
let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle")
39+
if let bundle = bundlePath.flatMap(Bundle.init(url:)) {
40+
return bundle
41+
}
42+
}
2543
}
44+
45+
// Return whatever bundle this code is in as a last resort.
46+
return Bundle(for: BundleToken.self)
2647
}
2748
}

0 commit comments

Comments
 (0)