[Solved] Boolean as on/off switch for a method [closed]


One Approach can be – You can use Notifications for this

Add Observer in your view controller where Updation needs to be done

[[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(booleanValueChanged:) 
        name:@"BOOLEAN_NOTIFICATION"
        object:nil];

- (void) booleanValueChanged:(NSNotification *) notification
    NSDictionary *userInfo = notification.userInfo;
    BOOL flag = [[userInfo objectForKey:@"booleanValue"] boolValue];
}

Now wherever you are changing the value of that bool, Use the following code:

NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:flag] forKey:@"booleanValue"];
[[NSNotificationCenter defaultCenter] postNotificationName: @"BOOLEAN_NOTIFICATION" object:nil userInfo:userInfo];

0

solved Boolean as on/off switch for a method [closed]