Fahadsk
Fahadsk

Reputation: 1109

Loading images from asset catalog from private pod

I have created a private pod which has some images, i have put that images in asset catalog, now when i try to access it, it does not load in my host app where i have installed this private pod

This is my private podspec

s.resource_bundles = {
     'myPod' => ['myPod/Assets/*.xcassets']
  }

and i have added this asset catalog in the Assets folder which gets created with pod

This in my VC inside viewDidLoad in my private pod

if let image = UIImage(named: "myIcon", in:Bundle(for:myVC.self), compatibleWith: nil) {
    sendButton.setImage(image.withRenderingMode(.alwaysTemplate), for: .normal)
    sendButton.setTitle("", for: .normal)
}

I can also see that assets file in my host app, pods section inside Resources folder, also my bundle is not nil.

Upvotes: 2

Views: 2058

Answers (1)

Fahadsk
Fahadsk

Reputation: 1109

Finally, i found a solution, turns out the problem is with resource bundles, I can see Assets.car present in bundle, but images were still not loading.

I thought using png files might work, and i can see that it was being copied to the bundle but i can't access it with image name, turns out i have to add this to image name myPod.bundle/imageName and it worked but still it was not a good solution.

Finally there was a cleaner and much simpler solution for this, is to use resources instead of resource_bundles in pod spec file, just thats it.

s.resources = 'myPod/Assets/**'

then do pod install and it will load images from your asset catalog.

Upvotes: 6

Related Questions