0

I have multi project iOS app which used cocoapods podspec to maintain each project as a dynamic framework. Each project has its own images in Assets.xcasset and multiple other resource (xib, ttf, json...).

I'm using below podspec (which use resource_bundles to separate resource for each pod (my pod xcassets contain of multiple vector pdf file imageset)

Pod::Spec.new do |spec|
    moduleName = 'UIComponent'
    spec.name = moduleName
    spec.version = '0.0.7'
    spec.summary = "#{spec.name} function"

    spec.description = <<-DESC
    #{spec.name} helpful function
                   DESC
    spec.homepage = 'https://bitbucket.org/ascendcorp/ami-ios-customer-app'

    spec.license = 'MIT'
    spec.author = { 'xxxx' => 'xxx' }

    spec.platform = :ios, '13.0'
    spec.ios.deployment_target = '13.0'
    spec.swift_version = '5.3'

    spec.source = {
        git: '#{my_git}',
        branch: 'develop',
        # tag: "#{spec.version}",
    }

    spec.source_files = "#{spec.name}", "#{spec.name}/**/*.{h,m,swift}"
    spec.resource_bundles = {
        "#{spec.name}" => [
            "#{spec.name}/**/*.{lproj,xcdatamodeld,xib,json,ttf,xcassets}",
        ],
    }
    spec.exclude_files = "#{spec.name}/Exclude"
    spec.public_header_files = "#{spec.name}/**/*.h"
    spec.static_framework = false

    spec.dependency 'Core'

    spec.dependency 'RxSwift'
    spec.dependency 'RxCocoa'
    spec.dependency 'CoreList'
    spec.dependency 'SVProgressHUD'
    spec.dependency 'Material'
    spec.dependency 'Nuke'
end

The problem is with

spec.resource_bundles = {
        "#{spec.name}" => [
            "#{spec.name}/**/*.{lproj,xcdatamodeld,xib,json,ttf,xcassets}",
        ],
    }

I can see all the resouce being copy to my Development Pods (including xib, Assets.xcassets folder) but seem our normal reference not working (get bellow error)

Could not load the "ic_xxx" image referenced from a nib in the bundle with identifier "org.cocoapods.xxxx"

even my normal xib allocation also not work

super.init(nibName: "SplashViewController", bundle: Bundle(for: SplashViewController.self))

for image also not work

img = UIImage(named: name, in: Bundle(for: aClass), compatibleWith: nil)

What is the correct way to reference resource (Assets.xcassets, xib...) using spec.resource_bundles? Note: I cannot use spec.resources as it will cause duplicate and fail the build.

halfer
  • 19,824
  • 17
  • 99
  • 186
Lê Khánh Vinh
  • 2,591
  • 5
  • 31
  • 77
  • No hints there https://stackoverflow.com/questions/35692265/how-to-load-resource-in-cocoapods-resource-bundle ? Also, if you do `Bundle(for: SplashViewController.self).resourceURL` can you navigate in the folder hierarchy to find your ressources? – Larme Jun 01 '21 at 13:19
  • hi @Larme i can use `let bundle = Bundle(for: Self.self) let resourceUrl = bundle.resourceURL?.appendingPathComponent("CommonService.bundle") print("resourceUrl \(resourceUrl)") let resourceBundle = Bundle(url: resourceUrl!) super.init(nibName: "DropdownViewController", bundle: resourceBundle)` for xib but for xcassets i tried the bellow but not working – Lê Khánh Vinh Jun 01 '21 at 14:30
  • `let image1 = UIImage(named: "ic_checkbox_on", in: resourceBundle, compatibleWith: nil)` – Lê Khánh Vinh Jun 01 '21 at 14:30
  • I meant to see by using `try? FileManager.default.contents(atPath: resourceUrl.path)` and so on in the debugger to find the image. Maybe there https://stackoverflow.com/questions/33063233/cant-load-images-from-xcasset-in-cocoapods ? – Larme Jun 01 '21 at 14:35
  • seem like i have `nil` with above query `let test1 = try? FileManager.default.contents(atPath: resourceUrl!.path)` using`let resourceUrl = bundle.resourceURL?.appendingPathComponent("CommonService.bundle")` – Lê Khánh Vinh Jun 01 '21 at 14:42
  • using finder, using `resourceUrl` i can navigate to `CommonService.bundle` inside i see my xib file and a `Assets.car` folder. seem like having problem retrieve image from `Assets.car` – Lê Khánh Vinh Jun 01 '21 at 14:46

0 Answers0