Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Get Object Id from Parse

I would like to get the object id from parse when the object is created. The code below works except from the "println()" line. It simply prints "nil"

var myObject = PFObject(className:"Objects")
        myObject["category"] = categoryTextField.text
        myObject["date"] = date
        myObject.saveInBackground()




            var createdId = myObject.objectId
            println(createdId)
        }

Thanks

2 Answers

I used to have the same error but the solution is to first PFQuery the object then call query.findObjectsInBackgroundWithBlock PFObject object then inside of the code block you call your PFObject code . then println() to check error

i hope it helps

How do I query the object without knowing the id?

The reason you're getting this error is because you're saving the object but not retrieving it. Look into the retrieving objects on the Parse documentation.