无法从 Parse 对象中检索 createdAt 值 [英] Unable to retrieve createdAt values from Parse objects
问题描述
我无法从 Parse 获取每个对象的 createdAt 值.而且我不想在数据就在那里时将额外的时间戳保存为字符串.
这是我正在做的事情的清单.我希望有人可以提供帮助----------------------------------------------------------------------
var followArray = [String]()var resultsNameArray = [String]()var resultsIcon = [PFFile]()var resultsImgArray = [PFFile?]()var resultsTimeTampArray = [NSDate?]()-------------------------------------------------------------------函数刷新结果(){var followQuery = PFQuery(className: "Follow")followQuery.whereKey("user", equalTo: PFUser.currentUser()!.username!)followQuery.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) ->作废如果错误 == 零{对于对象中的对象!{ self.followArray.append(object.objectForKey("Following") as!String)}var query = PFQuery(className: "Moments")query.whereKey("userName", containsIn: self.followArray)query.addDescendingOrder("createdAt")query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) ->作废如果错误 == 零{对于对象中的对象!{self.resultsNameArray.append(object.objectForKey("profileName") as!String)self.resultsIcon.append(object.objectForKey("icon") as!PFFile)self.resultsImgArray.append(object.objectForKey("image") as?PFFile)//尝试使用createdAt"属性,但我仍然从 Parse 获取 nil 值self.resultsTimeTampArray.append(object.objectForKey("createdAt") as! NSDate)}//重新加载表self.resultsTable.reloadData()}}}}-----------------------------------------------------------------------func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->UITableViewCell{var cell:TimelineCell = tableView.dequeueReusableCellWithIdentifier("Cell") as!时间线单元格在此处输入代码//我在这里遇到错误!//致命错误:在展开可选值时意外发现 nil//数据格式化程序var dateFormatter:NSDateFormatter = NSDateFormatter()dateFormatter.dateFormat = "yyyy-MM-dd"var strDate = dateFormatter.stringFromDate(self.resultsTimeTampArray[indexPath.row]!)返回单元格}
不要使用 objectForKey
访问它,直接通过 createdAt
属性访问它.>
正如文档中明确指出的,密钥:
<块引用>这不包括 createdAt、updatedAt、authData 或 objectId.它确实包括用户名和 ACL 等内容.
I cannot get the createdAt value from Parse for each object.And I dont want to have to save an additional timestamp as a String when the data is sitting right there.
This is the list of what i was doing.I hope someone who can help ----------------------------------------------------------------------
var followArray = [String]()
var resultsNameArray = [String]()
var resultsIcon = [PFFile]()
var resultsImgArray = [PFFile?]()
var resultsTimeTampArray = [NSDate?]()
-------------------------------------------------------------------
func refreshResult()
{
var followQuery = PFQuery(className: "Follow")
followQuery.whereKey("user", equalTo: PFUser.currentUser()!.username!)
followQuery.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil
{
for object in objects!
{ self.followArray.append(object.objectForKey("Following") as! String)
}
var query = PFQuery(className: "Moments")
query.whereKey("userName", containedIn: self.followArray)
query.addDescendingOrder("createdAt")
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil
{
for object in objects!
{
self.resultsNameArray.append(object.objectForKey("profileName") as! String)
self.resultsIcon.append(object.objectForKey("icon") as! PFFile)
self.resultsImgArray.append(object.objectForKey("image") as? PFFile)
//tried to use "createdAt" property but it i still getting nil value from Parse
self.resultsTimeTampArray.append(object.objectForKey("createdAt") as! NSDate)
}
//reload table
self.resultsTable.reloadData()
}
}
}
}
-----------------------------------------------------------------------
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell:TimelineCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! TimelineCell
enter code here //I'v got an error here!
//fatal error: unexpectedly found nil while unwrapping an Optional value
// dataFormatter
var dateFormatter:NSDateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
var strDate = dateFormatter.stringFromDate(self.resultsTimeTampArray[indexPath.row]!)
return cell
}
Don't access it using objectForKey
, just access it directly via the createdAt
property.
As explicitly stated in the docs, the keys:
This does not include createdAt, updatedAt, authData, or objectId. It does include things like username and ACL.
这篇关于无法从 Parse 对象中检索 createdAt 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!