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

Value of type 'NSUInteger' should not be used as format arguments.

I have 2 problems. First, when I write

NSLog(@"Retrieved %d messages", [self.messages count]);

A warning appears: "Value of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead".

The second problem is that my app crashes, this is my code:

- (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(@"No mames hay un Error: %@ %@", error, [error userInfo]);
        } else {
            self.messages = objects;
            [self.tableView reloadData];
            NSLog(@"Retrieved %d messages",[self.messages count]);
        }
    }];
}

These are the errors: https://www.dropbox.com/s/uxh5oyf0d0uc8jp/Ribbit.tiff?dl=0 https://www.dropbox.com/s/npmin6291facxek/Ribbit2.tiff?dl=0

And this is my class Messages: https://www.dropbox.com/s/oc0jbdap3ey4mq1/Parse.tiff?dl=0

Please I need help. I don't know what I'm doing wrong.

I found the solution, for the first problem Xcode suggested this:

NSLog(@"Retrieved %lu messages",(unsigned long)[self.messages count]);

For the second problem I was reading the documentation and changed my code to this:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ IN recipientIds", [[PFUser currentUser] objectId]];
    PFQuery *query = [PFQuery queryWithClassName:@"Messages" predicate:predicate];

    [query orderByDescending:@"createdAt"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        } else {
            self.messages = objects;
            [self.tableView reloadData];
            NSLog(@"Retrieved %lu messages",(unsigned long)[self.messages count]);
        }
    }];
}

But... Why does the Ben's code work? I need an explanation. My English isn't that good, so I'm going to write in Spanish. En la documentación aparecen dos ejemplos de como buscar un elemento en un array:

// Find objects where the array in arrayKey contains 2.
// Using PFQuery
[query whereKey:@"arrayKey" equalTo:@2];

// Or using NSPredicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"2 IN arrayKey"];
PFQuery *query = [PFQuery queryWithClassName:@"MyClass" predicate:predicate];

¿Por qué el primero le funciona a Ben pero a mi no, hace que la app tenga todos los errores que he mostrado anteriormente? ¿Por qué el segundo si me funciona si son dos formas distintas de hacer lo mismo?

1 Answer

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