Unable to retrieve createdAt values from Parse objects

蓝咒 提交于 2019-12-24 00:56:00

问题


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
            }

回答1:


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.




回答2:


You can access it directly in your for object loop like this.

object.updatedAt

instead of

objectforkey("updatedAt")


来源:https://stackoverflow.com/questions/30487622/unable-to-retrieve-createdat-values-from-parse-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!