gpt4 book ai didi

ios - 解析检索指针对象

转载 作者:行者123 更新时间:2023-11-30 14:10:17 25 4
gpt4 key购买 nike

我有以下 2 个解析类项目和类别。 Items 类有一个名为category 的列,它是一个指针,指向类中类别中的特定id。但是,当我想通过此指针从类别中检索数据时,它仅返回以下内容:

<Categories: 0x7ffddac633b0, objectId: dHbrk97s97, localId: (null)> {
}

这很奇怪,因为类别类包含名称、createdAt 和 UpdatedAt?为什么这些没有显示在这个对象中?

完整代码

func retrieveData() {
//Query Item Information
var query = PFQuery(className:"Items")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in

if error == nil {
// The find succeeded.

// Do something with the found objects
if let objects = objects as? [PFObject] {

self.collectionView.reloadData()

for object in objects {

var itemId = object.objectId!
var description = object["description"]! as! NSString
var createdAt = object.createdAt!
var title = object["title"]! as! NSString
var price = object["price"]! as! Int
var category = object["category"] as! PFObject


println(category)

//Query image
var query = PFQuery(className:"Images")
query.whereKey("imageId", equalTo:itemId)
query.whereKey("primaryImage", equalTo:true)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in

if error == nil {
// The find succeeded.
// Do something with the found objects
if let images = objects as? [PFObject] {
for image in images {
//var primaryImage = image[]
}
}
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
}

}


}
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
}

}

最佳答案

尝试在初始化 Items 查询后添加 include 方法:

var query = PFQuery(className:"Items")
query.includeKey("category")

当触发查询的获取时,此方法将检索指定的键。

https://parse.com/docs/ios/guide#queries-relational-queries

关于ios - 解析检索指针对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31855923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com