1

Alright so i'm starting to get a headache here... Once my user sign onto my app i create a new class on parse with the name PFUser.Current()?.objectId! Within this class i store all the users information, and the user can acces it from any device since his user ID never changes. One of the things i store in the user class is an array which leads me to my question: I want to be able to acces this array but the only way this can be done is by using:

var query = PFQuery(className: "\(PFUser.current()?.objectId!)") // Calling the user class
    query.getObjectInBackground(withId: "") { (object: PFObject?, error: Error?) in

        if error != nil {
            print(error)

        } else {

            print(object)
        }
    }

The Problem is that i do not know how to retrieve the objectID from within the class UserObjectID.

I found some code that lets me retrieve my user list and append usernames and iDs to an array:

var query = PFUser.query()

    query?.findObjectsInBackground { (objects, error) in

        if let users = objects {

            for object in users {

                if let user = object as? PFUser {

                self.usernames.append(user.username!)
                self.userids.append(user.objectId!)

                }
            }
        }   
    }

How can i do a similar search, and find all the objectIDs within my individual userClass instead of the superUser class?

1 Answer 1

1

Are you sure you want to create a new class for each user? you going to end up with an enormous amount of tables with 1 row in each. Best to add your array as a column in the current _User table or create a new table and save all user arrays in it with a pointer.

That being said if do and your new table is named from the objectId of the user then you should be able to query that class with:

var userId: String = ""

let userClassName = PFUser.current()!.objectId!

let query = PFQuery(className: userClassName)
// as there is only 1 row get the first
query.getFirstObjectInBackground { (object, error) in
    if error != nil || object == nil {
        print("nothing here try again")
    } else {
        userId = object?.objectId
    }
}

If you have a table with many users and a pointer then use the following lines as a guide

let userObjectId =  PFUser.current()!.objectId!
query.whereKey("yourPointerName", equalTo: PFObject(outDataWithClassName: "theClassYouWantToQuery", objectId: userObjectId))
Sign up to request clarification or add additional context in comments.

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.