0

I am using the following code to update a Parse object as button action:

-(IBAction)sendPressed:(id)sender
{


    NSLog(@"boton subir cadena pulsado");
    loadingSpinner.hidden = NO;
    [loadingSpinner startAnimating];

    //Upload a new picture
    NSData *pictureData = UIImagePNGRepresentation(self.chainPhoto.image);

    PFFile *file = [PFFile fileWithName:@"img" data:pictureData];
    [file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

        if (succeeded){
            NSLog(@"IMAGEN CARGADA");

            PFQuery *query = [PFQuery queryWithClassName:@"cadenas"];

            // Retrieve the object by id
            [query getObjectInBackgroundWithId: chain.objectId block:^(PFObject *imageObject, NSError *error)
             {

            [imageObject setObject:file forKey:@"image"];




            [imageObject setObject:self.commentTextField.text forKey:@"chain_name"];


            [imageObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

                if (succeeded){
                    //Go back to the wall
                    [self.navigationController popViewControllerAnimated:YES];
                }
                else{
                    NSString *errorString = [[error userInfo] objectForKey:@"error"];
                    [self showErrorView:errorString];
                }
            }];
        }

       ERROR HERE--> else
            {
            NSString *errorString = [[error userInfo] objectForKey:@"error"];
            [self showErrorView:errorString];
        }

             }
        [loadingSpinner stopAnimating];
        //loadingSpinner.hidden = YES;
        //self.commentTextField.text =@" ";
        self.progress_block.hidden = YES;

       // self.imageView.image = [UIImage imageNamed:@"no-image.jpg"];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Restaurant Chain changed with success"
                                                        message:@"You can now go back to the list."
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];



    } progressBlock:^(int percentDone) {


        self.progress_block.hidden =NO;
        self.progress_block.progress = (float) percentDone/100+progressValue;


    }];

}

In the line that I have marked as ERROR HERE in the code, there is an error warning (Expected ":"), but I can't find out why.

Any help is welcome.

1 Answer 1

1

From the looks of it, you never closed the query bracket:

PFQuery getObjectInBackground.... {

but never closed it using the proper syntax or it looks like you have an extra bracket }. For better practice, you should use proper indentation with if statements or else complications can happen like this. You get lost in the code because you don't know where a statement begins or ends

You should close it after the else statement so:

    } ERROR HERE--> else {
        NSString *errorString = [[error userInfo] objectForKey:@"error"];
        [self showErrorView:errorString];
        //stop animating and other stuff
    }
}];

I can't troubleshoot because i'm on my iPhone but I would suggest going back and using proper indentation so you can catch your culprit

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

2 Comments

Thank you, I have reinvented the code and corrected it following your proposal.
@mvasco okay cool, yeah it's always best to keep indentation proper, not for that, because what happens when go back to that code a year from now, you want it to be clear and concise because at that point it will be alien to you.

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.