2014-10-31 42 views
0

我不明白我的View Controller中這段代碼有什麼問題,底線(帶有單個括號)會一直出現兩個錯誤,一個聲明「連續聲明行必須用';'「和」預期聲明「分隔。當我將分號添加到它指向的地方時,它仍然會說預期的聲明錯誤....但是對於什麼?任何人都可以找到它的任何錯誤?有關在一條線上連續聲明的Swift錯誤

import UIKit 

class ViewController: UIViewController { 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    var testObject = PFObject(className:"TestObject") 
    testObject["foo"] = "bar" 
    testObject.saveInBackgroundWithTarget(nil, selector: nil) 

    var voteCount = PFObject(className:"VoteCount") 
    voteCount["votes"] = 0 
    voteCount["optionName"] = "Crepes" 
    voteCount.incrementKey("votes") 
    voteCount.saveEventually() 

    var query = PFQuery(className:"VoteCount") 
    query.getObjectInBackgroundWithId("e8KhneiSfw") { 
     (voteCount: PFObject!, error: NSError!) -> Void in 
     if error != nil { 
      NSLog("%@", error) 
     } else { 
      voteCount["votes"] = 1 
      voteCount.incrementKey("votes") 
      voteCount.saveEventually() 
     } 
    } 
class Counter { 
    var voteCount: Int = 0 
    func incrementBy(amount: Int, numberOfTimes times: Int) { voteCount += amount * times 
     } 
} 

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

} 

Screenshot for error

回答

1

有這條線之前缺少一個右括號:

class Counter { 

viewDidLoad()方法不正確關閉,所以會發生什麼是類和didReceiveMemoryWarning被定義爲本地viewDidLoad

正確的縮進通常會顯示類似的錯誤...您是否正確縮進了您的代碼?

0

正如所寫,class Counterfunc didReceiveMemoryWarning()都在viewDidLoad之內。修復你的大括號。

+0

這樣做的伎倆,謝謝! – appyhour 2014-10-31 20:57:54

相關問題