Alex
Alex

Reputation: 1625

NSError double pointers in Parse iOS API

The Parse API has some asynchronous methods that take target and selector arguments. Some of them specify an (NSError **) argument in the signature for the selector. For example, the PF User class has a method - (void)signUpInBackgroundWithTarget:(id)target selector:(SEL)selector and the documentation says the selector should have this signature (void)callbackWithResult:(NSNumber *)result error:(NSError **)error. I am having trouble using the NSError object in my implementation.

In my code I do this:

- (void)signup
{
    PFUser *newUser = [PFUser user];
    [newUser setUsername:@"something"];
    [newUser setEmail:@"[email protected]"];
    [newUser setPassword:@"12345"];
    [newUser signUpInBackgroundWithTarget:self selector:@selector(signupDiDFinishWithResult:(NSNumber *)result error:(NSError **)error)];
}

- (void)signupDiDFinishWithResult:(NSNumber *)result error:(NSError **)error)
{
    if (error) {
        NSError *myError = *error;
        NSLog(@"Error code: %d", [myError code]);
        // I have also tried [*error code];
    }
}

When I run this and get to [myError code] line I get +[NSError code]: Unrecognized selector sent to class. I'm not sure what I am doing wrong with this double pointer. Thank you for any advice.

Upvotes: 0

Views: 205

Answers (1)

Wain
Wain

Reputation: 119031

It could be a typo in the documentation. Did you try it with just NSError *?

Alternatively, use:

[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (error) {
        NSLog(@"Error code: %d", [error code]);
    }
}];

Upvotes: 3

Related Questions