快速从findObjectsInBackgroundWithBlock获取数据 [英] Getting data from findObjectsInBackgroundWithBlock in swift

查看:73
本文介绍了快速从findObjectsInBackgroundWithBlock获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Parse从数据库中获取数据. 调用块-findObjectsInBackgroundWithBlock时,将传递一个数组.因为我只接收一行数据,所以它们全部出现在数组的[0]部分中.那么我如何从该数组中取出所有位呢?

I am using Parse to get data out of a database. When the block - findObjectsInBackgroundWithBlock is called an array gets passed. As I am only receiving one row of data, it all appears in one [0] section of the array. So how do i get all the bits out of that array ??

以下是我正在使用的一些代码:

Here is some code I working with :

var MainPicture = PFQuery(className: "Staff")
        MainPicture.whereKey("Position", equalTo: "Sales Manager")
        MainPicture.findObjectsInBackgroundWithBlock ({(objects:[AnyObject]!, error: NSError!) in
            if(error == nil){
                for object in objects {

                }
                self.getMainImageData(objects as [PFObject])


            }
            else{
                println("Error in retrieving \(error)")
            }

        })

因此,对于对象中的对象而言,它为我提供了一个包含所有内容的数组.那么,如何提取该数组以获取名字,姓氏,位置,工作人员ID?

so where for object in objects is , it gives me one array with all the stuff in. So how can extract that array to get the First Name, Last Night, location, Staff ID out ?

谢谢

推荐答案

您需要将[AnyObject]强制转换为[PFObject],然后可以使用标准的Parse方法来获取数据.

You'll need to cast your [AnyObject] to a [PFObject] and then you can use the standard Parse methods to get the data out.

if let staffObjects = objects as? [PFObject] {
  for staff in staffObjects {
    // Use staff as a standard PFObject now. e.g.
    let firstName = staff.objectForKey("first_name")
  }
}

这篇关于快速从findObjectsInBackgroundWithBlock获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆