Firstly, I use Xcode 6 beta 2. Secondly, I have programming experience (basic, VB, script), but it does not contain any serious OO programs, and I am completely unfamiliar with IOS programming. Go straight to Swift. Thanks in advance to those who can help. A few days later I fought for it.
Failed to create a simple UIImage array. (I just deleted all the other code). I'm trying to understand why declaring a UIImage array and loading images works in viewDidLoad (), but not in the "base" of the ViewController, where I seem to need this for other things to work.
(I noticed that this is because this is an array declaration, which confuses me with confusion. I can declare and assign simple UIImage variables at any location.)
Here is my code:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
var icon = UIImage[]()
icon.append(UIImage(named: "yes.png")) <<==== expected declaration error
icon.append(UIImage(named: "no.png"))
}
But this code does not:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var icon = UIImage[]()
icon.append(UIImage(named: "yes.png")) <==== no error, and builds
icon.append(UIImage(named: "no.png"))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
source
share