Vulkan Vulkan - 25 days ago 7
Objective-C Question

Since the last Xcode update I can't work with images

This is the basic code I use to add an image named "Background.png" to an UIImageView:

UIImageView *imageView = [[UIImageView alloc] init];

imageView.image = [UIImage imageNamed:@"Background.png"];

imageView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);

[self.view addSubview:imageView];


Since the last Xcode update the resource can't be loaded.

I tried running on an iPhone 6 - iOS 10.3 and the Simulator - iOS 11.0

For some reason even though the iOS deployment target is version 10.3 the simulator runs on iOS 11.0

The image is there, in the same folder as the project named: "Background.png"

I've been doing the same thing for years and now it has stoped working.

Anyone had a similar issue?

Answer Source

You may want to utilize the purpose of Assets.xcassets. Put your assets there and you can easily use your images. Note that you do not have to put the image's file extension. It's easy, like so:

UIImage *markerImage = [UIImage imageNamed:@"marker"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:markerImage];
[imageView setFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:imageView];

I have an image in my Assets.xcassets named marker.

Edit: this is tested, I made an Objective-c project just for this question :)