这是我的代码:
import UIKit
class PlaylistMasterViewController: UIViewController {
@IBOutlet weak var abutton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
abutton.setTitle("Press me!", forState: .Normal)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showPlaylistDetailSegue" {
let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
playlistDetailController.segueLabelText = "Yay!You Pressed"
}
}
我在最后一行收到错误!我的xCode版本是6.3.2 ..我无法克服这一点,因为应用程序总是失败。我在这里遇到两个错误: 1-一行上的连续声明必须用';'分隔。 2-预期宣言
提前致谢
答案 0 :(得分:1)
您错过了结束括号以关闭课程,我已经通过每次打开和关闭括号时添加注释来证明这一点,例如:
if myVar == 1 { //OPEN: 1
//do something
} //CLOSE: 1
1只是一种跟踪哪个支架的方法,所以如果你有多个括号(你这样做),你会看到像
这样的东西//OPEN: 2 and //CLOSE: 2
我已添加下面的代码,显示您的括号何时打开和关闭。
import UIKit
class PlaylistMasterViewController: UIViewController { //OPEN: 1
@IBOutlet weak var abutton: UIButton!
override func viewDidLoad() { //OPEN: 2
super.viewDidLoad()
abutton.setTitle("Press me!", forState: .Normal)
} //CLOSE: 2 -- 1 still needs to be closed
override func didReceiveMemoryWarning() { //OPEN: 3
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} //CLOSE: 3 -- 1 still needs to be closed
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { //OPEN: 4
if segue.identifier == "showPlaylistDetailSegue" { //OPEN: 5
let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
playlistDetailController.segueLabelText = "Yay!You Pressed"
} //CLOSE: 5 -- 1 & 4 still need to be closed
} //CLOSE: 4 -- 1 still needs to be closed
// This is where you need to close 1, you're missing the bracket under this comment
} //ADD ME -- CLOSE: 1 -- no brackets to close left
我希望你现在对此更清楚一点。请练习正确缩进代码,这样可以节省大量时间调试这样的简单错误! :)
答案 1 :(得分:0)
正如@MartinR指出的那样,你错过了一个大括号。
“Re-indent”菜单项(Editor / Structure / Re-Indent或^ I)可用于轻松自动格式化当前选择,这使得这些问题难以忽略。