Image from Swift Package Displays in Storyboard But Not in Simulator or Device

When trying to using an image from a Swift Package within Interface Builder / Storyboard Scene:
  • In the "Attributes Inspector" the images are displayed in the dropdown for placing within the UIImageView

  • When the the image is selected from the dropdown it is populated within the UIImage object

  • When the iOS app is side-loaded to an iPad or the Simulator, the image does not appear within the UIImage object

  • I have created a UIImage extension within the Swift Package containing corresponding color name properties populate in "Images.xcassets" -> when using these properties to populate the UIImage object within the Swift class via code the image displays successfully

Baseline:
  • Xcode version -> 12.4

  • iPadOS 14.4

  • [Package] -> Image sources within the package: "Sources" -> "Package Name" -> "Resources" -> "Images.xcassets"

  • [Package] -> Has "resources: [.process("Resources")]" added to "Package -> targets -> .target"


Question:
  • Is this a bug in within Xcode 12.*, by Apple/Xcode design or am I missing a step?

Replies

That works well, in Xcode 12.4 and iPad 14.4 simulator. No bug (except maybe somewhere in your own code).

Is it a png image ?

Are you sure you do not reset the image of the UIImageView in code ?
Thanks for your reply "Claude31".

The image is a vector PDF with:
  • "Preserve Vector Data" = checked

  • "Appearances" = none

  • "Scales" = Single Scale

I created a "test package" and a "test iOS project" just to test this functionality to try and find the issue. The only code in the VC class is an empty viewDidLoad() and there is only one scene in the storyboard.

I did notice this log just now: "Could not load the "circle_vector" image referenced from a nib in the bundle with identifier "com.*.*" - I plan to start searching for what that could be referencing.
  • did you got fix for loading vector/pdf image from package to xib directly?

  • Unfortunately "No". Even with Xcode 13.* I am seeing the same behavior.

    Colors -> I can add colorsets to an xcasset object within the package, apply them successfully to an object in the project storyboard -> color renders successfully when side-loaded on an iPad.

    Images -> I can add imagesets to an xcasset object within the package, apply them successfully to an image object in the project storyboard -> image does not render (I receive the following error in the log: Could not load the "image_name" image referenced from a nib in the bundle with identifier "dot.dot.name")

    Images -> This is for both raster and vector (PDF) images.

Add a Comment

I have to implement below function in package and set image programtically

public func AMImage(named name: String) -> UIImage? {

  return UIImage(named: name, in: Bundle.module, compatibleWith: nil)

}

  • Thank you for the programmatic example "dattatrayDeokar" -> I already have an image extension for the containing computed properties for all of the colorsets within the package.

Add a Comment

Is there an open feedback item for this. I'm currently seeing the same behavior in Xcode 13.1. It seems to be a bug with resource bundles loading via xibs/storyboards.

  • Not that I am aware of.

    Unfortunately "No". Even with Xcode 13.* I am seeing the same behavior.

    Colors -> I can add colorsets to an xcasset object within the package, apply them successfully to an object in the project storyboard -> color renders successfully when side-loaded on an iPad.

    Images -> I can add imagesets to an xcasset object within the package, apply them successfully to an image object in the project storyboard -> image does not render (I receive the following error in the log: Could not load the "image_name" image referenced from a nib in the bundle with identifier "dot.dot.name")

    Images -> This is for both raster and vector (PDF) images.

Add a Comment

I am experiencing the same thing with a PNG file in an asset catalog (Xcode 13.2.1). Colors work fine. The only thing that fixed it for me was to add the asset file to the main app's Copy Bundle Resources build phase.

I'm also having @IBDesignables fail to build in Interface Builder with error Designables failed: The build product does not exist in the file system.