MyEmptyClass.swift
1.96 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
//
// MyEmptyClass.swift
// WarplySDKFrameworkIOS
//
// Created by Βασιλης Σκουρας on 14/4/22.
//
import Foundation
public class MyEmptyClass {
// static func resourceBundle() -> Bundle? {
// let frameworkBundle = Bundle(for: MyEmptyClass.self)
// let bundleURL = frameworkBundle.resourceURL?.appendingPathComponent("ResourcesBundle.bundle")
// let resourceBundle = Bundle(url: bundleURL!)
// return resourceBundle
// }
public static func resourceBundle() -> Bundle? {
#if SWIFT_PACKAGE
// For SPM, resources are in Bundle.module
return Bundle.module
#else
// For CocoaPods, use existing logic
let frameworkBundle = Bundle(for: MyEmptyClass.self)
// Try ResourcesBundle.bundle first (for local development)
if let bundleURL = frameworkBundle.resourceURL?.appendingPathComponent("ResourcesBundle.bundle"),
let resourceBundle = Bundle(url: bundleURL) {
return resourceBundle
}
// Fallback to Resources.bundle (for CocoaPods)
if let bundleURL = frameworkBundle.resourceURL?.appendingPathComponent("Resources.bundle"),
let resourceBundle = Bundle(url: bundleURL) {
return resourceBundle
}
// Final fallback to framework bundle itself
return frameworkBundle
#endif
}
}
// MARK: - Bundle Extensions for SPM Support
extension Bundle {
/// Returns the appropriate bundle for XIB files and storyboards
static var frameworkBundle: Bundle {
#if SWIFT_PACKAGE
return Bundle.module
#else
return Bundle(for: MyEmptyClass.self)
#endif
}
/// Returns the appropriate bundle for resources (images, fonts, etc.)
static var frameworkResourceBundle: Bundle? {
#if SWIFT_PACKAGE
return Bundle.module
#else
return MyEmptyClass.resourceBundle()
#endif
}
}