views:

130

answers:

3

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;  
}
+8  A: 

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.

Jasarien
+5  A: 

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];
jlehr
To be specific, from the docementation: `Returns YES on encountering one of "Y", "y", "T", "t", or a digit 1-9—the method ignores any trailing characters.`
Abizern
+7  A: 

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"])
Dave DeLong