3

I am struggling to use Parse to save an array of data - or at least I am finding I can't verify that my data is being saved.

I have a PFObject (journey) and I want to update it with my location (a string in the format: @"{lat, long}").

Eventually though I want to update and save my location every 10-30 seconds meaning I don't want to create a new object each time rather I want to add an array to the object and then update the array each time I have a new location.

Currently my code looks like this:

- (IBAction)startJourneyButtonPressed:(id)sender {

    PFObject * journey = [PFObject objectWithClassName:@"Journey"];
    journey[@"company"] = _companyNameTextField.text;
    journey[@"destination"] = _destinationTextField.text;

    [journey saveInBackground];

    NSData * faceImageData = UIImagePNGRepresentation([_faceButton imageForState:UIControlStateNormal]);
    PFFile * faceImageFile = [PFFile fileWithName:@"faceImage.png" data:faceImageData];

    [faceImageFile saveInBackground];

    NSData * carImageData = UIImagePNGRepresentation([_carButton2 imageForState:UIControlStateNormal]);
    PFFile * carImageFile = [PFFile fileWithName:@"carImage.png" data:carImageData];

    [carImageFile saveInBackground];

    journey[@"faceImage"] = faceImageFile;
    journey[@"carImage"] = carImageFile;

    [journey saveInBackground];

    NSMutableArray * locationArray = [NSMutableArray new];
    [locationArray addObject:[self getCurrentLocationString]];

    journey[@"location"] = locationArray;

    [journey saveInBackground];
}

The strings are saving fine and so are the images but the dataBase doesn't seem to be getting uploaded with the array.

Here is a screenshot of my database:

Parse DataBase

I am expecting to see a "location" heading but obviously it isn't appearing.

Reading up on other forums it says that I have to have an object in JSON format for this to work but as I am only storing Strings and I am not receiving and JSON errors I don't think this is the issue.

Any help would be very appreciated

0

1 Answer 1

2

Probably it is saving your array, you should just manually in your database add column with name "location" (do not forget to set it as array type) to see the values.

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

3 Comments

Yes this worked perfectly, I added a column to the table and the data that I was saving was immediately in that array column.
Is there a way to input the predefined array data in Parse.com?
The way to input the predefined array data in the Parse "Core" UI - assuming that the column is of type "Array" - is the same as it would be represented in JSON, enclosed in square brackets [] and each value within double quotes. For example: ["value1","value2","value3"]

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.