1

Context

I use Parse.com as my backend. Parse lets you have the ability to store an array of pointers to another one of your classes. In my case, for each user, if they are a business owner, I have an array of pointers to the businesses they own. The array looks like this: [{"__type":"Pointer","className":"Businesses","objectId":"auUS4I8ILh”}]

Now, in my application, I have a class that allows users to post to a timeline. If the user is also a business owner, it will allow the user to decide between posting as themselves or as the business they own. In order to do this, when I query for the user that's posting, I include the key that holds the array of pointers in my "_User" class.

Issue

Okay so my issue is when I'm trying to get the information out of the array of pointers. If I print the current user out to the console, it clearly shows the information in that column, as shown below. However, I can't figure out a good way to access this information.

Originally, I tried this:

if let businessOwner: [AnyObject] = self.currentUser.objectForKey("BusinessOwner") as! [AnyObject] {...}

After this, the next part of the code is supposed to get the object id's by iteration so that I can query for the business' information:

for business in businessOwner {
   objectIDArray.append(business.objectId as! String)
}

This originally worked when there was only one business in the array of pointers, but eventually even that stopped working. I've tried changing some things here and there, but the two problems I continually run into are: 1) the if...let statement just falls through, indicating that there was nothing to put into the businessOwner array (which I know isn't true because I can see the print out in the console), or 2) that the businessOwner array is instantiated and filled, but then the program crashes when trying to access the object id of the business, presumably related to the way I'm trying to access the string that is the object's id.

For clarification's sake, here is what the dictionary looks like after the business is assigned during iteration:enter image description here

Printed description of the "BusinessOwner" array of pointers.

So in essence, what do I have to do to assign the objects in my "BusinessOwner" column to an array, and then, how can I get the object id's in order to use them for my query? I've been fighting this issue for a couple of days. If anyone could help me out here it would be awesome.

1 Answer 1

3

Okay I figured it out. Part of the reason this wasn't working was that I was trying to access the object ID, but as you can see in the console picture, the objectId was being wrongly associated with the class name, so it was finding nil each time. That, I believe, is a Parse issue then. If you come to this thread looking for how to access data from a pointer array, the way to do it is as follows:

if let pointerObjects = parseClassObject["arrayOfPointers"]! as? [AnyObject] {
        for object in pointerObjects {
            if let id = object["objectId"] as? String {
            //do your own thing here
            }
        }
...}
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.