Xcode's IB Editor doesn't handle images in subdirectories properly

Originator:nick
Number:rdar://31360348 Date Originated:31 March 2017
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 8.3
Classification:Serious Bug Reproducible:Always
 
Summary:
The Interface Builder Editor in Xcode can show images that are in the root of your app bundle when using the native image view classes like UIImageView. If you have images in a subdirectory within your app bundle (e.g. "Images/my-image.png"), which might happen when including images via a Folder Reference, then it's not possible to specify the image without it either not showing up in the IB editor, or not showing up at runtime.

Steps to Reproduce:
1. Create a folder for all images that are to be imported into an iOS app, named "Images"
2. Create an image in that folder, named "my-image.png"
3. Create a Folder Reference in your iOS project for the "Images" folder
4. Create a UIImageView in a XIB or Storyboard
5. Set the UIImageView's image to "my-image.png"

Expected Results:
Given that the image shows up correctly in the IB editor, it should also be set correctly at runtime.

Actual Results:
The image doesn't get set at runtime, since the "image" field in the IB editor seems to have the same behaviour as the +[UIImage imageNamed:] API, i.e. it used to search from the root of the app bundle.

If an image is within a folder in your app bundle (e.g. "Images"), you can specify the image as "Images/my-image.png", and the +imageNamed: API will work. Specifying "Images/my-image.png" also allows XIBs/Storyboards to successfully load the correct image at runtime, but if you do this, the IB editor will show a "missing" image in the editor pane.

Version:
Xcode 8.3

Notes:
We use Folder References to avoid the tedious work of keeping our Xcode projects in sync with folders of assets which we pull into our apps from our design team via scripts and automation.

This works really well, and allows Xcode's Open Quickly feature to find everything in our "Images" folder, but the only downside of this approach is that it's not possible to get IB to both

1. Show the image in the editor pane
and
2. Actually load said image at runtime

No matter what behaviour IB has, the editor should ideally be consistent with the runtime; i.e. there shouldn't be a scenario like this where the editor preview looks correct but it breaks at runtime (or vice versa).

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!