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

Retrieved 0 messages

I'm having the same problem a couple of others have had and I tried resolving it by changing 'recipientIds' to 'recipientsIds' as suggested but this doesn't seem to be the problem.

Does anyone know what else could be causing this?

It means that when I run the program I can't see the message, or the icon. :(

13 Answers

Frank Novello
Frank Novello
19,299 Points

Make sure you Have the right class name. The M in messages is capitalized. I made the mistake of not capitalizing at first.

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

Cristian Malita
Cristian Malita
4,103 Points

The code should work fine, just make sure that all the keys in your query match the keys on Parse.com. If your key on Parse.com is something like "recipientIds" and in your code you use something like "recipientsIds" it will not work. It's really easy to make mistakes like this, so make sure your keys match.

Andres Oliva
Andres Oliva
7,810 Points

This may sound strange, but could you add this line of code to yours?

PFUser *currentUser = [PFUser currentUser];
if (currentUser) {
    //Here goes your query
    //The last line of code here should be "]};" from your block of code of [query findObjectsInBackgroundWithBlock: 
}

This needs to go right after [super viewWillAppear:animated]; in the viewWillAppear method of your InboxViewController.

I have this in viewDidLoad at the moment Andres. I'll go change it.

This is actually what my code looks like in my inbox view controller.

- (void)viewDidLoad {
    [super viewDidLoad];

    PFUser *currentUser = [PFUser currentUser];
    if (currentUser) {
        NSLog(@"Current user:%@", currentUser.username);
        }
    else {
        [self performSegueWithIdentifier:@"showLogin" sender:self];    }

    }

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

    PFQuery *query = [PFQuery queryWithClassName:@"Messages"];
    [query whereKey:@"recipientsIds" equalTo:[[PFUser currentUser]objectId]];
    [query orderByDescending:@"createdAt"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error){
            NSLog(@"Error:%@ %@", error, [error userInfo]);
        }
        else {
            //We found messages
            self.messages = objects;
            NSLog(@"Messages: %@", self.messages);
            [self.tableView reloadData];
            NSLog(@"Retrieved %d messages", [self.messages count]);
        }

    }];
}

Also, just as a side note. I actually just remembered that when I created this view controller class the name was saved as 'InboxViewControllerTableViewController' rather than 'InboxViewController'. Could this be conflicting with something elsewhere? Sorry I completed forgot about that since I originally noticed it when new class was created.

Andres Oliva
Andres Oliva
7,810 Points

Did you already checked that your messages are being stored in parse.com?

Hi Andres, and thank you for responding. Yes, I checked on parse.com and all of my users (9) are stored there, and there is 1 message logged there also.

Are you 'logged in' as one of the recipients of the message? If you didn't send it to 'yourself' then you won't see it.

Andres Oliva
Andres Oliva
7,810 Points

In your willViewAppear method of InboxViewController, check self.messages with an NSLog, right after this line of code:

self.messages = objects;

Andres, I just plugged in that NSLog and this came back on console:

2014-10-28 21:47:50.104 Ribbit[4191:116476] Found messages 2014-10-28 21:47:50.104 Ribbit[4191:116476] Retrieved 0 messages

Andres Oliva
Andres Oliva
7,810 Points

How did you write the NSLog statement?

I did it like this:

NSLog(@"Messages: %@", self.messages);

and logged this into the console:

2014-10-28 21:17:32.694 Ribbit[4937:393738] Messages: ( "<Message: 0x7fb918ce6130, objectId: lXZm0WKSMg, localId: (null)> {\n file = \"<PFFile: 0x7fb91ac20c80>\";\n fileType = image;\n recipientIds = (\n ksKVqgoY6Y\n );\n senderId = ksKVqgoY6Y;\n senderName = Andy;\n}" )

You should get a similar output, or something like this: 2014-10-28 21:17:32.694 Ribbit[4937:393738] Messages: ()

I changed my NSLog statement and the build failed this time.

This is the error message I got:

2014-10-29 12:34:03.375 Ribbit[2046:49075] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot do a comparison query for type: (null)' *** First throw call stack: ( 0 CoreFoundation 0x0000000110a823f5 exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000011071bbb7 objc_exception_throw + 45 2 CoreFoundation 0x0000000110a8232d +[NSException raise:format:] + 205 3 Ribbit 0x000000010efc1fa1 +[PFInternalUtils assertValidClassForQuery:] + 333 4 Ribbit 0x000000010ef9f5f9 -[PFQuery whereKey:equalTo:] + 86 5 Ribbit 0x000000010ef7b1c3 -[InboxViewControllerTableViewController viewWillAppear:] + 227 6 UIKit 0x0000000110f96eef -[UIViewController _setViewAppearState:isAnimating:] + 487 7 UIKit 0x0000000110fc1ed0 -[UINavigationController _startTransition:fromViewController:toViewController:] + 776 8 UIKit 0x0000000110fc29f7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 523 9 UIKit 0x0000000110fc34b7 -[UINavigationController __viewWillLayoutSubviews] + 43 10 UIKit 0x0000000111107399 -[UILayoutContainerView layoutSubviews] + 202 11 UIKit 0x0000000110ee7199 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521 12 QuartzCore 0x000000010f51ef98 -[CALayer layoutSublayers] + 150 13 QuartzCore 0x000000010f513bbe _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 14 QuartzCore 0x000000010f513a2e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 15 QuartzCore 0x000000010f481ade _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 16 QuartzCore 0x000000010f482bea _ZN2CA11Transaction6commitEv + 390 17 UIKit 0x0000000110e6c67d -[UIApplication _reportMainSceneUpdateFinished:] + 44 18 UIKit 0x0000000110e6d368 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2642 19 UIKit 0x0000000110e6bd22 -[UIApplication workspaceDidEndTransaction:] + 179 20 FrontBoardServices 0x00000001145b72a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16 21 CoreFoundation 0x00000001109b7abc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12 22 CoreFoundation 0x00000001109ad805 __CFRunLoopDoBlocks + 341 23 CoreFoundation 0x00000001109ad5c5 __CFRunLoopRun + 2389 24 CoreFoundation 0x00000001109aca06 CFRunLoopRunSpecific + 470 25 UIKit 0x0000000110e6b799 -[UIApplication _run] + 413 26 UIKit 0x0000000110e6e550 UIApplicationMain + 1282 27 Ribbit 0x000000010ef80973 main + 115 28 libdyld.dylib 0x0000000112263145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

Andres Oliva
Andres Oliva
7,810 Points

Wait, did the app crash? Or did it not build at all? Seeing that error, it looks like the app crashed at runtime. And it means that you are sending with nil as an argument.

Nope, it briefly said build succeeded but nothing appeared on screen- just blank, black screen.

The error type is different now. I'm not getting the infamous SIGABRT error instead.

Andres Oliva
Andres Oliva
7,810 Points

Did you add the if statement?

Hi, Brock Ormond, I logged in under the name of the person i sent the message to, and there is still no message retrieved and nothing showing in inbox.

I flipped the exact same IF statement to viewWillAppear and I'm still getting the same error message. Does that if block need to be changed somewhat? Thanks for keeping with this by the way!

If I can't resolve it at all I'm just going to keep going with last few videos and make sure my storyboard changes are perfect and then compare and contrast TH source code.

This is what I have now.

- (void)viewDidLoad {
    [super viewDidLoad];
    }

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

    PFUser *currentUser = [PFUser currentUser];
    if (currentUser) {
        NSLog(@"Current user:%@", currentUser.username);
    }
    else {
        [self performSegueWithIdentifier:@"showLogin" sender:self];    }

    PFQuery *query = [PFQuery queryWithClassName:@"Messages"];
    [query whereKey:@"recipientsIds" equalTo:[[PFUser currentUser]objectId]];
    [query orderByDescending:@"createdAt"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error){
            NSLog(@"Error:%@ %@", error, [error userInfo]);
        }
        else {
            //We found messages
            self.messages = objects;
            NSLog(@"Messages: %@", self.messages);
            [self.tableView reloadData];
            NSLog(@"Retrieved %d messages", [self.messages count]);
        }

    }];
}
Andres Oliva
Andres Oliva
7,810 Points

Can you add an exception breakpoint and tell where the code is crashing?

After I add a breakpoint, how do I assess it for where the code crashes? For example, I just added breakpoint after viewDidLoad and that is returning a green line with thread 1.1 highlighted next to it. Does this have any significance or is that just the normal way to signify where it had a break?

Andres Oliva
Andres Oliva
7,810 Points

That's normal, but then you added a normal breakpoint. Do you know how to add exception breakpoints?

yep, that was the one video I skipped so far.

i added the exception breakpoint and this is what came back:

http://m.imgur.com/snTSdxa

Okay, is this what happens as soon as you try to run or just when you are trying to pull up your message view?

Actually, it wasn't breaking in the first place, just no messages right? Can you return to that state? Seems like you added something it doesn't like and now we've just chasing a new bug.

Andres Oliva
Andres Oliva
7,810 Points

For what I can see, I believe your app is crashing because no user is logged in. At the moment you run the query, user is equal to nil, and that's raising an exception. You can check that putting a breakpoint in viewWillAppear in the line of code where you assign user to [PFUser currentUser]. It should be nil

ok im going to compare to source code now and see what's going on.

Andres Oliva
Andres Oliva
7,810 Points

I had a similar problem when I updated to Xcode 6.1 and I fixed it with the if statement that I told you before.

Take a look at my code if you want.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.moviePlayer = [[MPMoviePlayerController alloc] init];
    PFUser *currentUser = [PFUser currentUser];
    if (currentUser) {
        NSLog(@"Current user: %@", currentUser.username);
    } else {
        [self performSegueWithIdentifier:@"showLogin" sender:self];
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    PFUser *currentUser = [PFUser currentUser];
    if (currentUser) {
        PFQuery *query =  [PFQuery queryWithClassName:@"Message"];
        NSLog(@"%@", [[PFUser currentUser] objectId]);
        [query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];
        [query orderByDescending:@"createdAt"];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (error) {
                NSLog(@"Error: %@ %@", error, [error userInfo]);
            } else {
                self.messages = objects;
                NSLog(@"Messages: %@", self.messages);
                [self.tableView reloadData];
            }
        }];
    }
}

thanks again andres. ill come back to this again in the morn. my macbook is playing up lately and keeps dropping its internet connection and so i had to take a break from it and migrate to ipad hence the lack of screenshots.

i had an old saved copy of the treehouse ribbit project that i downloaded earlier on but i dont think it was their finished product. i need to download the ribbit project files from the very last video i think. im not sure what treehouse practice is here actually, whether they update files after each video or not. they didnt with the blogreader project anyway.

looking forward to comparing our code too. using this version of xcode has thrown up loads of issues in itself, well done for doing so well to work out that fix.

Hi, I'm not sure if you figured this out or not, but I had the same problem but it works now. This is my code:

  • (void)viewDidLoad { [super viewDidLoad];

    PFUser *currentUser = [PFUser currentUser]; if ( currentUser) { NSLog(@"Current User: %@", currentUser.username);

    } else { [self performSegueWithIdentifier:@"showLogin" sender:self]; }

}

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

    PFQuery *query = [PFQuery queryWithClassName:@"Messages"]; [query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]]; [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 %d messages", [self.messages count]); }

    }]; }