I am trying to declare some integer values (used for controlling checkboxes that I made). I declare them all in the .h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITextFieldDelegate> {
int check1Yes; //There are more but this one causes the same error so I show one for example
}
Then in the .m I set them all to “1” in viewDidLoad
- (void)viewDidLoad {
check1Yes = 1;
[super viewDidLoad];
}
Lastly I call it in a C method that checks to see if it equals 1. This is where I get the error:
void fillBox(int *checkbox)
{
if(check1Yes == 1) //ERROR on this line
checkbox[0] = 1;
else
checkbox[0] = 0;
}
How can I fix this issue?
C functions do not have access to instance variables of your class; only Objective C methods do.
C functions can access global variables and static variables declared in the same compilation unit, but if you would like to give them access to instance variables, you need to pass them explicitly from your Objective C methods: