E-Madd
E-Madd

Reputation: 4582

What's wrong with this method?

I'm getting a warning: "Return makes pointer from integer without a cast" for this method...

+(BOOL *)getBoolFromString:(NSString *)boolStr  
{  
    if(boolStr == @"true" || boolStr == @"1"){  
        return YES;  
    }  
    return NO;  
}

Upvotes: 1

Views: 188

Answers (3)

Dave DeLong
Dave DeLong

Reputation: 243156

Besides what @Jasarien and @jlehr have said, you have a problem with this:

(boolStr == @"true" || boolStr == @"1")

That's doing pointer comparison, not object equality. You want:

([boolStr isEqualToString:@"true"] || [boolStr isEqualToString:@"1"])

Upvotes: 8

jlehr
jlehr

Reputation: 15597

To get a BOOL from an NSString, all you need to do is send a -boolValue message, like so:

NSString *myString = @"true"; // or @"YES", etc.
BOOL bool = [myString boolValue];

Upvotes: 6

Jasarien
Jasarien

Reputation: 58448

BOOL is not a class or object, so returning a pointer to a BOOL is not the same as returning a BOOL.

You should remove the * in +(BOOL *) and everything will be ok.

Upvotes: 8

Related Questions