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

查看:21
本文介绍了快速从 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)")
            }

        })

那么 for object in objects 在哪里,它给了我一个包含所有内容的数组.那么如何提取该数组以获取名字、昨晚、位置、员工 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天全站免登陆