Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Allen Chen
Allen Chen
7,209 Points

I can't retrieve messages , but there are messages in my dashboard Messages

I have examined many times and searched for the same question. I still can't retrieve messages from Messages Dashboard.

There is my code:

- (void)viewWillAppear:(BOOL)animated   {
    [super viewWillAppear:animated];

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

    [query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];
    //[query whereKeyExists:@"recipientIds"];
    [query orderByDescending:@"createdAt"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects , NSError *error)    {
        if (error) {
            NSLog(@"Error : %@ %@" , error , [error userInfo]);
        }
        else    {
            // We found messages!
            self.messages = objects;
            [self.tableView reloadData];
            NSLog(@"Retrieved %lu messages" , (unsigned long)[self.messages count]);
        }
    }];
}

but if I add [query whereKeyExists:@"recipientIds"]; (As //[query whereKeyExists:@"recipientIds"]; mentioned) The app may retrieve messages.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1; 
   // I have checked the value in numberOfSectionsInTableView
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self.messages count];
}

My Data structure of Messages in Parse objectId , file , fileType , recipientIds , senderId , senderName , createdAt , updatedAt , ACL

Thanks~

You are absolutely right, the same happened to me. It didn't display any message until I used whereKeyExists:@recipientIds. I think the Instructor should look at this issue

1 Answer

Allen, here is a full template for the social network application: Click Here.