本文介绍了解析查询 findObjectsInBackgroundWithBlock 出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ios 开发的新手,我最近找到了一个教程,可以使用解析后端构建类似 ios 应用程序的高音扬声器.我当前的设置是 Xcode 7.1 和 swift 2.0,本教程是在旧版本的 swift 上完成的,所以我不得不调整一些 swift 语法以使其工作.我做得很好,直到我遇到以下错误,

I am new to ios development and I recently found a tutorial to build a tweeter like ios app using a parse backend. My current set up is Xcode 7.1 with swift 2.0, the tutorial was done on an older version of swift so I had to adjust some of the swift syntax in order to make it work. I was doing fine until I hit the following error,

func loadData(){
    timelineData.removeAllObjects()
    var findTimelineData:PFQuery = PFQuery(className: "Tweet")

    findTimelineData.findObjectsInBackgroundWithBlock{
        (objects:[AnyObject]?, error:NSError?) -> Void in
        if (error == nil && objects != nil){
            for object:PFObject! in objects!{
               self.timelineData.addObject(object)
            }
            let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects
            self.timelineData = array as! NSMutableArray
            self.tableView.reloadData()
        }

  }

在这里,我试图将解析表/类中的所有数据访问/存储到数组中.编辑器抱怨闭包参数 (objects:[AnyObject]?, error:NSError?) -> Void in.经过几次尝试,

Here I am trying to access/store all the data in a parse table/class into an array. And the editor is complaining about the closure argument (objects:[AnyObject]?, error:NSError?) -> Void in. After a couple of tries,

  1. (objects:[AnyObject]!, error:NSError!) -> Void in
  2. (objects:[AnyObject], error:NSError?) -> Void in
  3. (objects:[AnyObject]?, error:NSError) -> Void in
  4. (objects:[AnyObject], error:NSError) -> Void in

我尝试的所有选项都给了我同样的错误:'([AnyObject]!, NSError!) -> Void' 不能转换为 'PFQueryArrayResultBlock?'

All the options I tried gave me the same error:'([AnyObject]!, NSError!) -> Void' is not convertible to 'PFQueryArrayResultBlock?'

事实上对于 (objects:[AnyObject]?, error:NSError?) -> Void in(我认为这是最有意义的),编辑器会崩溃,如果我运行代码,我会得到一个段错误.

In fact for (objects:[AnyObject]?, error:NSError?) -> Void in (which I thought makes the most sense), the editor would crash and if I ran the code I would get a seg fault.

有人遇到过类似的问题吗?或知道修复?

Has anyone run into similar issue? or know of a fix?

提前感谢您的帮助.

推荐答案

尝试将 [AnyObject]? 更改为 [PFObject]?.这似乎是 Swift 2.0 所要求的.

Try changing [AnyObject]? to [PFObject]?. This seems to be required by Swift 2.0.

所以代替:

findTimelineData.findObjectsInBackgroundWithBlock {
    (objects:[AnyObject]?, error:NSError?) -> Void in

使用:

findTimelineData.findObjectsInBackgroundWithBlock {
    (objects:[PFObject]?, error:NSError?) -> Void in

您还需要更改对数组对象的迭代,因为它们现在已经是 PFObject.

You'll also need to change your iteration over the array objects, since they will now already be PFObject.

这篇关于解析查询 findObjectsInBackgroundWithBlock 出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:54