Xcode 6.3更新导致工作应用程序失败 - 现在工作的不会

时间:2015-04-09 17:00:05

标签: ios xcode swift

我不知道是否有其他人经历过这个,但我有一个应用程序,我正在建设,它工作得很好。然后我愚蠢地允许mac安装并xcode更新。接下来我知道,我打开项目并且构建失败并出现21个错误。我修了20个。顺便说一句,其他任何人都发现此问题时出现PF_Nullability错误,check this out

这适用于20个错误,但最后一个是在一个正常工作的函数中。在这个函数中,我在parse.com上查询一个数据类,并获得一个随机对象来填充我的视图controller/app/whatevers中的变量。我正在使用下面的函数,所以你可以看到整个事情,但这是错误的行:

 countQuery.countObjectsInBackgroundWithBlock { (count: Int32, error: NSError!) -> Void in
There error: cannot invoke 'countobjectsinbackgroundwithblock' with an argument list of type '((Int32, NSError!) - Void in)'

以下是整个功能,希望它只是像其他20个修复一样的语法:

     func CallData() {
    var countQuery = PFQuery(className: "QandA")
    countQuery.countObjectsInBackgroundWithBlock { (count: Int32, error: NSError!) -> Void in
        if (error == nil) {
            let randomNumber = Int(arc4random_uniform(UInt32(count)))
            var query = PFQuery(className: "QandA")
            query.skip = randomNumber
            query.limit = 1
            query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) -> Void in
                if (error == nil) {
                    var object: AnyObject = objects[0]
                    self.Question = object  ["Question"] as String!
                    self.Answers = object  ["Answers"] as Array!
                    self.Answer = object  ["Answer"] as String!

                    if (self.Answers.count > 0) {
                        self.QuestionLabel.text = self.Question
                        self.Button1.setTitle(self.Answers[0], forState: UIControlState.Normal)
                        self.Button2.setTitle(self.Answers[1], forState: UIControlState.Normal)
                        self.Button3.setTitle(self.Answers[2], forState: UIControlState.Normal)
                        self.Button4.setTitle(self.Answers[3], forState: UIControlState.Normal)
                    }
                } else {
                    NSLog("Something is wrong with the find request, dude.  Sorry. %@", error)
                }
            }
        } else {
            NSLog("Something is wrong with the count request, dude.  Sorry. %@", error)
        }   
    }
}

有关如何摆脱该错误的任何想法?为什么它以前没有工作呢?谢谢。

4 个答案:

答案 0 :(得分:2)

好吧,一个错误最终导致了另一个,但我终于得到了解决...它基本上是语法(我猜也是投射错误,但基本上是语法中的语法错误......我猜...这里有一个问号,那里有一个感叹号......我是一个新手,所以我真的不知道,只是通过试验和错误)但是这里有效:

  func CallData() {
        var countQuery = PFQuery(className: "QandA")
        countQuery.countObjectsInBackgroundWithBlock { (count: Int32, error: NSError?) -> Void in
            if (error == nil) { let randomNumber = Int(arc4random_uniform(UInt32(count)))
                var query = PFQuery(className: "QandA")
                query.skip = randomNumber; query.limit = 1
                query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
                    if (error == nil) {

                        var object: AnyObject = objects![0]
                        self.Question = object ["Question"] as! String!
                        self.Answers = object ["Answers"] as! Array!
                        self.Answer = object ["Answer"] as! String!
                        if (self.Answers.count > 0) {
                            self.QuestionLabel.text = self.Question
                            self.Button1.setTitle(self.Answers[0], forState: UIControlState.Normal)
                            self.Button2.setTitle(self.Answers[1], forState: UIControlState.Normal)
                            self.Button3.setTitle(self.Answers[2], forState: UIControlState.Normal)
                            self.Button4.setTitle(self.Answers[3], forState: UIControlState.Normal) }
                    } else { 

                        NSLog("Something is wrong with the find request, dude. Sorry. %@", error!) 
                    } 
                }
            } else { 
                NSLog("Something is wrong with the count request, dude. Sorry. %@", error!) 
            } 
        } 
    }

答案 1 :(得分:1)

你为什么不:

  1. 转到https://developer.apple.com/downloads/index.action?name=Xcode(需要开发者帐户)并下载Xcode 6.2 DMG
  2. 将当前Xcode 6.3应用程序(仅称为Xcode)重命名为Xcode-6.3
  3. 安装下载的DMG,然后将Xcode复制到应用程序。
  4. Xcode现在是Xcode 6.2
  5. 我使用这种方法,所以Xcode总是最后一个。这样我就可以构建旧项目,只需切换到正确的Xcode(我将所有图标放在Dock上)。

    注意:这是您的主要问题的解决方法。在不久的将来,您应该转换到Xcode 6.3& Swift 1.2,但与此同时你可以再次构建

答案 2 :(得分:1)

下载最新版本的Parse以解决此问题。

https://www.parse.com/docs/downloads/

答案 3 :(得分:0)

Xcode中有一个工具可以帮助您将Swift 1.1转换为1.2 - 转到编辑>转换