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

How to create a sequence number as column in Parse.com

Hi guys,

I want to add a column as sequence number in my back end of Parse.com which starts 1. Each object gets an incremented sequence number.

PFObject *onderdeelAanvraag = [PFObject objectWithClassName:@"Aanvragen"];
        [onderdeelAanvraag setObject:[PFUser currentUser] forKey:@"Aanvrager"];
        onderdeelAanvraag[@"OnderdeelOmschrijving"] = onderdeelOmschrijving;
        onderdeelAanvraag[@"AutoOmschrijving"] = autoOmschrijving;
        NSDate *date = [NSDate date];
        onderdeelAanvraag[@"Datum"] =date;


        onderdeelAanvraag[@"sequenceNumber"]= *continuous number which starts at 1*

        [onderdeelAanvraag saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (error) {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:[error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alertView show];
            }
            else {
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
        }];

1 Answer

Sinan,

Are you sure you really want/need to do that? Each object has a unique id already and Parse provides createdAt and updatedAt fields with each object. If you want to create an index you can do that by adding a new field in Parse of type Number and then update it with each object creation. However, keep in mind you will have to manage the storage and retreival of this item between application launches.