不能使用类型'(String,equalTo:String?!)'的参数调用'whereKey'

时间:2015-08-31 18:07:36

标签: ios swift parse-platform where-clause pfquery

我在此代码的这一行收到此错误消息:

findSweeter.whereKey("objectId", equalTo: sweet.objectForKey("sweeter")!.objectId)

错误:

  

不能使用类型'的参数调用'whereKey'(String,   equalTo:String?!)'

以下是我在cellForRowAtiIndex路径中使用的代码,用于检索要在单元格中显示的个人资料图片,个人资料名称和内容:

var findSweeter:PFQuery = PFUser.query()!
  findSweeter.whereKey("objectId", equalTo: sweet.objectForKey("sweeter")!.objectId)

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

      if error == nil{
          let user:PFUser = (objects as! NSArray).lastObject as! PFUser
          cell.usernameLabel.text = user.username


          UIView.animateWithDuration(0.5, animations: {
              cell.sweetTextView.alpha = 1
              cell.timestampLabel.alpha = 1
              cell.usernameLabel.alpha = 1
              cell.profilePic.alpha  = 1
          })
      }
  }

非常感谢任何解决此问题的方法。使用Xcode 6.3.2。提前谢谢!

1 个答案:

答案 0 :(得分:0)

尝试在查询之前展开可选变量。

if let sweeter: PFObject = sweet.objectForKey("sweeter") as? PFObject {
    var findSweeter:PFQuery = PFUser.query()!
    findSweeter.whereKey("objectId", equalTo: sweeter.objectId)
    findSweeter.findObjectsInBackgroundWithBlock {
        // ...
    }
}