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 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


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.