首先,我使用
Xcode 6 beta 2.其次,我有编程经验(基本,VB,脚本语言),但它不包括任何严肃的OO编程,我对IOS编程完全不熟悉.直接进入斯威夫特.提前感谢那些可以提供帮助的人.我几天来一直在努力奋斗.
无法构建简单的UIImage数组. (为了简单起见,我已经删除了所有其他代码.)我试图理解为什么声明一个UIImage数组并加载图像在viewDidLoad()中工作,但不是在ViewController的“基础”,这是我似乎需要的地方它可以用于其他工作.
(我注意到它似乎与这个数组声明有关,这会引起我的困惑.我可以在任一位置声明并分配简单的UIImage变量.)
这是我的代码:
// ViewController.swift import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } var icon = UIImage[]() icon.append(UIImage(named: "yes.png")) <<==== expected declaration error icon.append(UIImage(named: "no.png")) }
但是这段代码没有:
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. var icon = UIImage[]() icon.append(UIImage(named: "yes.png")) <==== no error,and builds icon.append(UIImage(named: "no.png")) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }