Question: How can I get my UISwitch to call this function: <https://ghostbin.com/paste/y2xrc> when turned on, and return FALSE; when it is turned off. 

(I got the switch to show inside "CKTranscriptCollectionViewController" in the Messages.app (MobileSMS.app), and now I want it to do something when turned on or off which is what I posted in the link above).

```
#import <UIKit/UIKit.h>
#import <ChatKit/CKConversation.h>

@interface CKTranscriptCollectionViewController : UIViewController
@property (nonatomic, strong) UISwitch *mySwitch;
- (void)loadView;
@end

%hook CKTranscriptCollectionViewController

- (void)viewDidLoad {   
    %orig;
    UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(10, 10, 51, 31)];
    [mySwitch setOn:NO animated:YES];
    [self.view addSubview:mySwitch];
}

%end

```

Answer: 
define a bool in your header file,

```
BOOL allowForceMMS;

-(BOOL)forceMMS {
    return allowForceMMS;
)

- (void)viewDidLoad {   
    %orig;
    UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(10, 10, 51, 31)];

    //add action on switch to handle switch on/off
    [mySwitch addTarget:self action:@selector(setState:) forControlEvents:UIControlEventValueChanged];

    [mySwitch setOn:NO animated:YES];
    [self.view addSubview:mySwitch];
}

-(void)setState:(UISwitch*)switch {
    allowForceMMS = switch.isOn;
}

```
```
[mySwitch addTarget:self action:@selector(switchValueChangeHandler:) forControlEvents:UIControlEventValueChanged];

```