Bundle+GKExtension.swift
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// Bundle+GKExtension.swift
// GKNavigationBarSwift
//
// Created by QuintGao on 2023/7/21.
//
import Foundation
extension Bundle {
static var gk_bundle: Bundle? {
normalModule ?? spmModule
}
private static var normalModule: Bundle? = {
let bundleName = "GKNavigationBarSwift"
var 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: GKNavigationBarConfigure.self).resourceURL,
// For command-line tools.
Bundle.main.bundleURL,
]
#if SWIFT_PACKAGE
// For SWIFT_PACKAGE.
candidates.append(Bundle.module.bundleURL)
#endif
for candidate in candidates {
let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle")
if let bundle = bundlePath.flatMap(Bundle.init(url:)) {
return bundle
}
}
return nil
}()
private static var spmModule: Bundle? = {
let bundleName = "GKNavigationBarSwift_GKNavigationBarSwift"
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: GKNavigationBarConfigure.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
}
}
return nil
}()
}