MyEmptyClass.swift 1.96 KB
//
//  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
    }
}