【问题标题】:Unable to retrieve createdAt values from Parse objects无法从 Parse 对象中检索 createdAt 值
【发布时间】:2015-08-09 20:14:40
【问题描述】:

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

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

 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
            }

【问题讨论】:

    标签: ios uitableview swift parse-platform data-retrieval


    【解决方案1】:

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

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

    这不包括 createdAt、updatedAt、authData 或 objectId。它确实包括用户名和 ACL 之类的内容。

    【讨论】:

      【解决方案2】:

      您可以像这样在 for 对象循环中直接访问它。

      object.updatedAt
      

      而不是

      objectforkey("updatedAt")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-14
        • 1970-01-01
        • 1970-01-01
        • 2014-05-25
        相关资源
        最近更新 更多