2015-06-21 65 views
0

這是我的代碼:Swift錯誤:行上的連續聲明必須用';'分隔

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-預期宣言

在此先感謝

+1

如果您*縮進*您的代碼正確,那麼你會注意到一個右大括號丟失... –

+1

我永遠不會理解人們如何沒有正確的縮進程序 - 只是隨機線和大括號後彼此沒有任何結構...他們應該嘗試python ^^ – luk2302

回答

0

由於@MartinR所指出的,你缺少一個右括號。

「重新縮進」菜單項(編輯/結構/重新縮進或^ I)可被用於容易地自動格式化當前選擇,這使得這樣的問題痛苦難以忽視。

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 

我希望現在對你更清楚一點。請正確練習縮進代碼,這樣可以節省很多時間調試這樣的簡單錯誤! :)

相關問題