gpt4 book ai didi

ios - 解析错误 : PFObject does not have a member named 'createdAt'

转载 作者:可可西里 更新时间:2023-11-01 01:39:31 26 4
gpt4 key购买 nike

我被困在那个问题上。我已经阅读了 Parse 文档 ( https://parse.com/docs/ios/guide#queries-query-constraints ),但它对我帮助不大。

错误

当我尝试从 PFObject 获取“createdAt”或“updatedAt”时,出现以下错误:

['PFObject'] does not have a member named 'createdAt'

代码

这是(缩写)函数:

func loadCheckInData() {

var query = PFQuery(className: "CheckIn")
query.orderByDescending("createdAt")
query.selectKeys(["firstName","lastName","updatedAt","createdAt"])

query.findObjectsInBackgroundWithBlock({
(objects: [AnyObject]?, error: NSError?) -> Void in

if error == nil {

println(objects)
// Do something
if let object = objects as? [PFObject] {
println("\(object.createdAt)") <---- Error here
self.CheckedPatients = Array(object.generate())
}
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
})
}

然后我使用以下代码检索“CheckIn”Parse 类中的“firstName”、“lastName”(并尝试检索“createdAt”)

func collectionView(cellView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

// Add parse data
if let value = CheckedPatients[indexPath.row]["lastName"] as? String {
cell.cellLabelTwo.text = value
}
if let value = CheckedPatients[indexPath.row]["firstName"] as? String {
cell.cellLabel.text = value
}
if let value = CheckedPatients[indexPath.row]["createdAt"] as? String {
cell.cellDay.text = value
}
return cell
}

我调用函数

override func viewDidAppear(animated: Bool) {
loadCheckInData()
}

事实上,我尝试了不同的方法来获取“createdAt”值,但我无法让它工作。有没有人有想法(如果可能的话,还有一个快速的解释)它可能很好。谢谢!

最佳答案

只是因为 updatedAt/createdAt 是所有 PFObjects 的属性,不需要使用键检索它,只需将其视为属性即可。

关于ios - 解析错误 : PFObject does not have a member named 'createdAt' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31480607/

26 4 0