Ios 如何在解析中识别与特定对象关联的用户?

Ios 如何在解析中识别与特定对象关联的用户?,ios,swift,parse-platform,Ios,Swift,Parse Platform,我在Parse中有一个Product类,我试图在选中时识别用户及其与产品关联的电子邮件。在我的产品类中,我有一个用户指针 以下是我到目前为止的情况: func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let product: PFObject = PFObject(className: "Product") let createdB

我在
Parse
中有一个
Product
类,我试图在选中时识别用户及其与产品关联的电子邮件。在我的
产品
类中,我有一个用户指针

以下是我到目前为止的情况:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {


        let product: PFObject = PFObject(className: "Product")

        let createdBy: AnyObject! = product.objectForKey("user")?.email



        println("You selected cell #\(indexPath.row), created by \(createdBy)!")
代码只为
createdBy
值提供了“nil”


我试着按照
解析
文档,但我真的不知道我在做什么。这是我的第一个应用。

我认为在查询中,从解析中提取信息时,需要使用
includeKey
参数

它看起来是这样的:


query.includeKey(“用户”)
这应该允许您获取该用户信息

您需要做的是为每个产品对象保存一个
userID
。事实上,当您创建一个新的parse user对象时,每个用户都已经有了一个名为
objectId
的属性。您可以使用此唯一标识符来设置每个产品对象中名为
userID
的属性。或者,如果您希望它成为用户的电子邮件,请确保将电子邮件存储给用户:

let user = PFUser()
// Fill in the rest here...
user.setObject("someone@somewhere.com", forKey: "email")
user.save()
然后在创建购买对象时(确保下面有一个实例化的
用户

let product = PFProduct()
// Fill in the rest here...
product.setObject(user["email"], forKey: "purchaserEmail")
product.save()
因此,当您试图检查与该产品的购买者相关联的电子邮件时

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    let product: PFProduct = self.products.objectAtIndex(indexPath.row) as! PFProduct

    var purchaserEmail: String = product["purchaserEmail"]

    println("Go spam \(purchaserEmail) more.")
}
如果您想将用户名保存到产品对象中,也可以对用户的用户名执行同样的操作。希望这有所帮助