Search code examples
iosbackground-imagexcode7.3

Error when trying to set the iOS-application's background


Before I upgraded XCode to version 7.3.1 (7D1014), the following code snippet changed background of my application.

class InitialViewController: UIViewController {
    @IBOutlet weak var startImage: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "FogCity")!)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

Now I get following error: enter image description here

This image exists: enter image description here

The "print" function displays following: enter image description here

Please help me!


Solution

  • Your code is correct, I tested it. I refer to this line of code: self.view.backgroundColor = UIColor(patternImage: UIImage(named: "FogCity")!)

    What you have to do is to check the name of the image "FogCity" to exactly match.