Skip to content

Commit

Permalink
Tweak bundle loading to support cocoapods.
Browse files Browse the repository at this point in the history
  • Loading branch information
cocoahero committed Nov 20, 2023
1 parent d849f78 commit 0c2f6de
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ShopifyCheckoutKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ Pod::Spec.new do |s|
s.ios.deployment_target = "13.0"
s.swift_version = "5.0"
s.source_files = "Sources/ShopifyCheckoutKit/**/*.swift"
s.resources = "Sources/ShopifyCheckoutKit/**/*.xcassets"
s.resource_bundles = {
"ShopifyCheckoutKit" => ["Sources/ShopifyCheckoutKit/Assets.xcassets"]
}
end
42 changes: 42 additions & 0 deletions Sources/ShopifyCheckoutKit/Bundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import Foundation

internal class ShopifyBundleFinder {}

extension Bundle {
static var shopifyCheckoutKit: Bundle {
#if COCOAPODS
guard let cocoapodsBundle = Bundle(for: ShopifyBundleFinder.self)
.url(forResource: "ShopifyCheckoutKit", withExtension: "bundle")
.flatMap({ Bundle(url: $0) })
else {
fatalError("[cocoapods] unable to load resource bundle")
}
return cocoapodsBundle
#else
return .module // use Swift Package Manager's synthesized helper
#endif
}
}
2 changes: 1 addition & 1 deletion Sources/ShopifyCheckoutKit/SpinnerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import UIKit
class SpinnerView: UIView {
private lazy var imageView: UIImageView = {
let view = UIImageView(image: UIImage(
named: "spinner", in: .module, with: nil
named: "spinner", in: .shopifyCheckoutKit, with: nil
))
view.translatesAutoresizingMaskIntoConstraints = false
return view
Expand Down

0 comments on commit 0c2f6de

Please sign in to comment.