[英]Parse retrieving a pointer object
我有以下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!)")
}
}
}
@彼得
正如您已经写过的那样,您在parse数据库中创建了两个解析类。 您可以将这些类称为自定义类或模型类,因此,每当要打印任何模型类的属性值时,都必须使用NSLog()属性值,例如您的情况:(在Objective-C中)
Categories * catObj = [[Categories alloc] init];
NSLog(@“名称:%@,创建位置:%@,更新位置:%@”,catObj.name,catObj.createdAt,catObj.updatedAt);
初始化Items查询后,尝试添加include方法:
var query = PFQuery(className:"Items")
query.includeKey("category")
触发查询访存时,此方法检索指定的键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.