-2

I'm new to coding and can't find an accurate answer anywhere. I'm trying to make the NSNumber return false if the BOOL is true. Any help? Thanks

static BOOL someBOOL;

%hook  (class I want to hook)

-(void)sampleMethod:(NSNumber *)boolNumber
{
    if (!someBOOL) 
    {
        [NSNumber numberWithBool:NO];
    } 
    else 
    {
        return %orig;
    }
}

%end
creker
  • 9,400
  • 1
  • 30
  • 47
Andrew68
  • 1
  • 1

1 Answers1

0

Init someBOOL:

static BOOL someBOOL = YES;

Then

if (!someBOOL) 
{
    return [NSNumber numberWithBool:NO];
} 
else 
{
    return %orig;
}

And to return replace void with NSNumber and remove excess parameter

-(NSNumber*)sampleMethod

To get returned value:

NSNumber *n = [self sampleMethod];
creker
  • 9,400
  • 1
  • 30
  • 47
nicael
  • 18,550
  • 13
  • 57
  • 90
  • I did this and I got the error: "cannot initialize return object of type 'BOOL' (aka 'signed char') with an rvalue of type NSNumber *" – Andrew68 May 11 '14 at 21:47
  • Where does NSNumber *n = [self sampleMethod]; go? – Andrew68 May 11 '14 at 22:09
  • NSNumber has a method called boolValue. Use it on the line that is causing this: "cannot initialize return object of type 'BOOL' (aka 'signed char') with an rvalue of type NSNumber *'. [https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/nsnumber_class/Reference/Reference.html#//apple_ref/occ/instm/NSNumber/boolValue](https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/nsnumber_class/Reference/Reference.html#//apple_ref/occ/instm/NSNumber/boolValue) – Cătălin Stan May 11 '14 at 22:16
  • @nicael Please use either `YES` or `NO` to initialize a `BOOL` variable. Also keep in mind that `someBool` will be initialized to `NO` by default. – rmaddy May 12 '14 at 00:18