Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Self-Destructing Message iPhone App Retrieving and Viewing Data from Parse.com Deleting Data from Parse.com

Boaz Keren Gil
Boaz Keren Gil
18,947 Points


Hello, I'm trying to delete the files from the Parse database using REST API (complete delete).

This is the CURL code given at Parse website:

    curl -X DELETE \
        -H "X-Parse-Application-Id: <YOUR_APPLICATION_ID>" \
        -H "X-Parse-Master-Key: <YOUR_MASTER_KEY>" \

And this is my objective c code:

        PFFile *file = [self.selectedMessage objectForKey:@"file"];
        [self.selectedMessage deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error){
            if (error) {
                NSLog(@"%@ %@", error, [error userInfo]);
            } else {
                //Getting the unique file name attached to the selected message.

                NSURL *fileURL = [NSURL URLWithString:file.url];
                NSString *fileName = [NSString stringWithFormat:@"%@",fileURL.pathComponents[2]];

                //Creating the CURL request.
                NSString *urlString = [NSString stringWithFormat:@"https://api.parse.com/1/files/%@", fileName];
                NSURL *url = [[NSURL alloc] initWithString:urlString];
                NSMutableURLRequest *restAPI = [[NSMutableURLRequest alloc] initWithURL:url];
                [restAPI setHTTPMethod:@"DELETE"];
                [restAPI setValue:@"MY APP KEY" forHTTPHeaderField:@"X-Parse-Application-Id"];
                [restAPI setValue:@"MY MASTER KEY" forHTTPHeaderField:@"X-Parse-Master-Key"];
                NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:restAPI delegate:self startImmediately:YES];


I've never done this before, and unfortunately there is no way to check if it worked on Parse.com

What do you think?

P.S. I have this annoying unused variable notification about *connection... even though I don't need to use it again right? once I initialize it, it runs.. Maybe I should add

[connection cancel] 

after this?

2 Answers

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

I don't know if you need to delete connection at the end, but I would think you could get onto the Parse-site and check to if they are there.

Boaz Keren Gil
Boaz Keren Gil
18,947 Points

I don't know if this code is working or not, and there is no way to check it on the Parse web interface.. By theory everything is implemented right? it should work? And should I add the connection cancel at the end?