0

I have a Parse class with the name "Question", and a column called "quizid" of type Number.

In xcode swift class, I have a variable of type Int quiz_id.

I have a class inherited from PFQueryTableViewController

I want to pull data from the class "Question" based on where condition that column "quizid" value is equal to, quiz_id integer variable.

Here is the code I am using, but It gives runtime exception.

Could you tell me the right code for query?

whereKey while using Int variable in swift

override func queryForTable() -> PFQuery{
    let query = PFQuery(className: "Question")
    query.whereKey("quizid", equalTo:PFObject(withoutDataWithObjectId:self.quiz_id! as! String))
    query.cachePolicy = .CacheThenNetwork
    query.orderByAscending("createdAt")

    return query
}
boraseoksoon
  • 2,164
  • 1
  • 20
  • 25
Parth Tiwari
  • 855
  • 2
  • 9
  • 23

3 Answers3

1

check for Optional() by printing your value. Cheers!

0

I figured it, I should just use,

query.whereKey("quizid", equalTo: self.quiz_id!)
Parth Tiwari
  • 855
  • 2
  • 9
  • 23
0

I guess the equalTo: expect a String and don't a PFobject.. https://parse.com/docs/ios/guide#queries-basic-queries

try

override func queryForTable() -> PFQuery{
let query = PFQuery(className: "Question")
query.whereKey("quizid", equalTo:PFObject(withoutDataWithObjectId:self.quiz_id! as! String) as! String
query.cachePolicy = .CacheThenNetwork
query.orderByAscending("createdAt")
return query
}