ios - 无法从 Parse 对象检索 createdAt 值

标签 ios uitableview swift parse-platform data-retrieval

我无法从 Parse 中获取每个对象的 createAt 值。而且当数据就在那里时,我不想将额外的时间戳保存为字符串。

这是我正在做的事情的列表。我希望有人可以提供帮助 -------------------------------------------------- --------------------

 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
            }

最佳答案

不要使用objectForKey访问它,只需通过createdAt属性直接访问它。

正如文档中明确指出的,键:

This does not include createdAt, updatedAt, authData, or objectId. It does include things like username and ACL.

关于ios - 无法从 Parse 对象检索 createdAt 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30487622/

相关文章:

ios - 如何判断(在运行时)库是否使用 cocoapods 链接?

iphone - 如何将值传递给另一个 View Controller ?

iphone - UITableView 低于代码全屏?

swift - UITableViewAutomaticDimension 不适用于调整单元格高度

ios - 使用 Linphone iOS SDK 启用视频通话

swift 泛型没有强制展开沮丧

iOS - 提高 SQLite 的插入性能

iOS 发布 Reference iPhoneContactList with ARC

ios - 将按钮连接到引脚标注

ios - 为什么在使用 init(barButtonSystemItem, target, action) 初始化时 UIBarButtonItem 的目标设置为 nil?