Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS & Stackmob - [NSNull length]: unrecognized selector sent to instance

Tags:

ios

stackmob

In my iOS app I'm trying to update user information in the database (with Stackmob), but I keep getting "unrecognized selector sent to instance."

- (IBAction)save:(UIButton *)sender {

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"User"];
NSPredicate *predicte = [NSPredicate predicateWithFormat:@"username == %@", self.username];
[fetchRequest setPredicate:predicte];

[self.managedObjectContext executeFetchRequest:fetchRequest onSuccess:^(NSArray *results) {

    NSManagedObject *todoObject = [results objectAtIndex:0];
    [todoObject setValue:@"[email protected]" forKey:@"email"];

    [self.managedObjectContext saveOnSuccess:^{
        NSLog(@"You updated the todo object!");
    } onFailure:^(NSError *error) {
        NSLog(@"There was an error! %@", error);
    }];

} onFailure:^(NSError *error) {

    NSLog(@"Error fetching: %@", error);

}];
}

Here's the full error I'm getting:

-[NSNull length]: unrecognized selector sent to instance 0x1ec5678

2013-07-21 12:01:25.773 [29207:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[NSNull length]: unrecognized selector sent to instance 0x1ec5678'

Thanks in advance.

like image 697
sambol Avatar asked Jul 22 '13 05:07

sambol


1 Answers

I think it may because your self.username is empty. Note that if you are getting the username data from json , you can't use if(username){...} but

if(![username isKindOfClass:[NSNull class]])

to avoid empty data because the json interpreter will generate an NSNull object.

like image 121
Chen Xiaofeng Avatar answered Nov 15 '22 22:11

Chen Xiaofeng