winston
winston

Reputation: 3100

How to compare pointer parse objects in Swift?

I have a simple game that uses Parse.com for the backend. I originally stored the user values for a Game object as Strings and structured the queries and if statements accordingly (I'm new to programming). I then learned that the right way to do it is to store the users as pointer objects that "point" back to the User table.

I'm struggling to get my if statements to work. I want to check if the current user (PFUser.currentUser()) is equal to one of the users I have stored in the Game table:

//continue an active game that already exists with the user
                    if results != nil{
                        println(results)

                            //continue existing game
                            for result in results {

                                var user1 = result["user1"] as PFUser
                                var user2 = result["user2"] as PFUser
                                var round = result["round"] as Int
                                var turn = result["turn"] as PFUser

                                //continue game if current user is user1
                                if PFUser.currentUser() == user1 {

When I step through my code with breakpoints, the if PFUser.currentUser() == user1 statement is being skipped, even though the statement is true (user 1 is indeed the same user as the currentUser). How do I properly compare the user1 pointer object to the currentUser?

Thanks!

Upvotes: 1

Views: 580

Answers (1)

mattdaw
mattdaw

Reputation: 121

PFUser isn't set up to support equality in that way, but it looks like comparing objectIds would do the right thing in your case:

if PFUser.currentUser().objectId == user1.objectId

Upvotes: 1

Related Questions