2014-10-31 46 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

相关问题