0

I'm trying to use the parse.com data browser to inset a new string array into my code.

So if I've got a code with an array of @"blue", @"yellow", @"black", nil then how can I change it to @"white", @"gold", @"brown", nil ?

In the app, I have the user press a button and one of said string value appears at random. I would like to put a new array on a backend to have new values so that I don't have to update the app every time.

Is there an example of how to do this? I haven't been able to get the Data Browser to replace the array in my code with the array in the data browser.

I've got:

PFQuery *query = [PFQuery queryWithClassName:@"colorArray"]; 
self.colors = [query findObjects];

But it crashes when I try to retrieve the values of the array when it gets to this part of the code in a later method -

NSUInteger index = arc4random_uniform(self.colors.count]; 
self.colorLabel.text = [self.colors objectAtIndex:index];

self.colors, by the way, is synthesized from the header file as an array. It looks like the code doesn't understand the "index" part of the equation when it tries to set the self.colorLabel.text using the obectAtIndex

The crash is "-[PFObject length]: unrecognized selector sent to instance 0xcb56740".

Am I doing this right?

7
  • What's the crash, what's the value of self.colors, and does that code actually compile? Or is that a typo? Commented Sep 29, 2013 at 20:38
  • The crash says -[PFObject length]: unrecognized selector sent to instance 0xcb56740 Commented Sep 29, 2013 at 20:42
  • self.colors is just the name of the NSArray, which I declare in the header and then synthesize in the implementation. The code does work in the simulator, but after I push the button to make a random string value appear (one of the color names) it crashes w/ the above crash. Commented Sep 29, 2013 at 20:44
  • Can you log the contents of the new array for us please? Commented Sep 29, 2013 at 20:45
  • 1
    Did you read the documentation of PFQuery? findObjects returns an array of PFObject instances. You can't assign those to an NSString property. What property of the PFObject are you trying to access? EDIT: also, this looks like two questions in one, am I wrong? "How to replace a an array stored on parse", and "how to put the color name into a label". Commented Sep 29, 2013 at 20:46

2 Answers 2

1

self.colors is an array of PFObjects - not NSStrings

That is why this line fails:

self.colorLabel.text = [self.colors objectAtIndex:index];

What you need is something like:

NSUInteger index = arc4random_uniform(self.colors.count]; 
PFObject *colourPFObject = [self.colors objectAtIndex:index];
self.colorLabel.text = [colourPFObject objectForKey:@"columnNameForColour"];

Don't forget to change columnNameForColour to whatever name you call your colour column in your the Parse.com colorArray class

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much! Changing it up like this way exactly what it needed :)
0

See the @Carl Veazey comment.

 {colors = (Red,Blue,Black);}

is from the description method of PFObject, you need to use the accessor methods of PFObject to get at the colors (or array of colors).

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.