- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
int num = 5;
[viewController functionA:[NSNumber numberWithInt:num-1]];
}
-(void) functionA: (NSNumber*) indexNumber{
int hi = [indexNumber intValue];
}
viewController is an instance of a custom UIViewController class. functionA is a function in that class. touchesEnded is in another class.
I get EXC_BAD_ACCESS. After searching online it seems it might be a release/alloc error, but I couldn’t figure it out.
OK, 2 things:
You never have explicit ownership of your NSNumber, which is irrelevant, because
viewController is most likely nil. Why would you reference a class like that if you could just use self and save yourself some extra characters? If the function truly is in another class, check that you have even allocated and initialized it before you go running about and calling methods. Your crash might have more to do with said extra class than with your NSNumber.