Question

This is driving me crazy. I have a string that will either be 0 or 1 always. Whenever I try to find out what it is, my application crashes.

if([[loggedUser isStaff] isEqualToString:@"1"])
{                         
[self performSegueWithIdentifier:@"staffLogin" sender:self];
}
else{
[self performSegueWithIdentifier:@"userLogin" sender:self];
}

This is what the console says:

[740:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFBoolean isEqualToString:]: unrecognized selector sent to instance 0x2d16350'

What's going on? I've checked the debugger and the string that it's checking for is appropriately displaying 0 and 1 as it should.

Was it helpful?

Solution 2

[loggedUser isStaff] seems to be an NSNumber / Boolean object yet you are trying to compare it to an NSString. Booleans and NSNUmbers do not have an isEqualToString method.

If you want to compare whether the user isStaff, you should try:

if ([[loggedUser isStaff] boolValue])
{
[self performSegueWithIdentifier:@"staffLogin" sender:self];
}
else{
[self performSegueWithIdentifier:@"userLogin" sender:self];
}

OTHER TIPS

You're trying to call an NSString method on a boolean. You just need to check whether or not the boolean value is true.

if([[loggedUser isStaff] boolValue])
{                         
    [self performSegueWithIdentifier:@"staffLogin" sender:self];
}
else{
    [self performSegueWithIdentifier:@"userLogin" sender:self];
}

assuming isStaff is an NSNumber object holding a boolean value.

if([loggedUser isStaff])
{                         
    [self performSegueWithIdentifier:@"staffLogin" sender:self];
}
else{
    [self performSegueWithIdentifier:@"userLogin" sender:self];
}

assuming isStaff is a boolan value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top