Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I'm trying to render an image in the background of a UIView in Interface Builder. For some reason, however, the UIImage object is nil. I've checked my Build Settings to make sure the picture it represents is copied into the target, and the image file appears to be in the same directory & group as my source code.

Here's my code:

Code:
var image = UIImage(named: "string")

    override func prepareForInterfaceBuilder() {

        image!.drawInRect(self.bounds) // breakpoint here, where I see that image is nil

    }
 
Are you using xcassets or just adding the image directly to an image folder? Are you sure that image name is spelled correctly?
 
Last edited:
If the image is in xcassets then you should be able to just use the filename.

But if you just copied the image itself to the project directory, then you should also include the file extension (ie. .jpg). You also need too make sure that the image (or the xcassets file) has the right target membership. You do this by clicking the file itself in the navigator, then on the right navigation bar click the 'file inspector' icon (the paper icon) at the top right. Usually, the first target is the iOS target but yours may be different.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.