BFBundle+Ext.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Bundle+Ext.swift
  3. // BFFramework
  4. //
  5. // Created by ak on 2021/6/2.
  6. // 取 BFFramework 资源目录
  7. import Foundation
  8. public extension Bundle {
  9. // bf main bundle url
  10. // func BF_mainbundle_URL() -> URL {
  11. // let bundle: Bundle = Bundle(for: BFBaseViewController.self)
  12. // return bundle.url(forResource: "BFFramework", withExtension: "bundle")!
  13. // }
  14. func BF_mainbundle_URL() -> URL {
  15. var bundleURL = Bundle.main.url(forResource: "Frameworks", withExtension: nil)
  16. bundleURL = bundleURL?.appendingPathComponent("BFCommonKit").appendingPathExtension("framework")
  17. let bundle: Bundle = Bundle(url: bundleURL!)!
  18. return bundle.url(forResource: "BFCommonKit_Resources", withExtension: "bundle")!
  19. }
  20. // bf main bundle
  21. func BF_mainbundle() -> Bundle {
  22. return Bundle(url: BF_mainbundle_URL())!
  23. }
  24. private class func bundleURL(moduleName: String,isAssets: Bool = true) -> URL? {
  25. if isAssets {
  26. var bundleURL = Bundle.main.url(forResource: "Frameworks", withExtension: nil)
  27. bundleURL = bundleURL?.appendingPathComponent(moduleName).appendingPathExtension("framework").appendingPathComponent("\(moduleName)_Resources").appendingPathExtension("bundle")
  28. return bundleURL
  29. } else {
  30. return Bundle.main.url(forResource: "\(moduleName)_Resources", withExtension: "bundle")
  31. }
  32. }
  33. class func current(moduleName: String,isAssets: Bool = true) -> Bundle? {
  34. guard let url = bundleURL(moduleName: moduleName,isAssets: isAssets) else {
  35. return nil
  36. }
  37. return Bundle(url: url)
  38. }
  39. }