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

How to access other attributes/columns from a parse.com object after pulling the object from parse

I am pulling code from parse using the query below. I retrieve the objects but I can only access "object.objectId" if I try "object.name" and "name" is a column on the Funlists table my app crashes and I get this error: "Thread 1:EXC_BAD_INSTRUCTION(code=EXC_1286_INVOP, subcode=0x0)"

var query = PFQuery(className: "FunLists")
query.whereKey("createdBy", equalTo:"Sean Plott")
query.findObjectsInBackgroundWithBlock {
   (objects: [AnyObject]!, error: NSError!) -> Void in

     if error == nil {
        // The find succeeded.
        NSLog("Successfully retrieved \(objects.count) scores.")

         // Do something with the found objects
          for object in objects {
             NSLog("%@", object.objectId)
             self.funlists.append(object.name)          
          }

            } else {
                // Log details of the failure
                NSLog("Error: %@ %@", error, error.userInfo!)
            }

            dispatch_async(dispatch_get_main_queue()) {
                self.tableView.reloadData()
            }
        }

1 Answer

The answer is to access it using object notation:

object["name"] as String

Just incase anyone else fell into this problems

Glad you figured it out!