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
}

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

I figured it, I should just use,

query.whereKey("quizid", equalTo: self.quiz_id!)

Comments

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
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.