Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set view's NSinteger property to NSInteger?

I'm trying to set a variable on a view that im getting ready to load. Heres the code for setting it:

 NSInteger amountOfQuestions = [self.questions.text intValue];
    Timer_ViewController *tvc = [[Timer_ViewController alloc] initWithNibName:@"Timer_ViewController" bundle:nil];

    tvc.amountOfQuestions = &amountOfQuestions;

And here's the @interface for Timer_ViewController:

@interface Timer_ViewController : UIViewController
{
    NSInteger amountOfQuestions;
}

    @property (nonatomic) NSInteger *amountOfQuestions;



@end

Im relatively new to objective-c so pointing out of obvious design flaws would be appreciated.

like image 999
Jonah Katz Avatar asked Apr 15 '26 09:04

Jonah Katz


1 Answers

You shouldn't make NSInteger a pointer - it's not an object type, just a typedef of a plain primitive type. If you're using a relatively recent version of Xcode, you can go with something like this:

@interface Timer_ViewController : UIViewController
@property (nonatomic, assign) NSInteger amountOfQuestions;
@end

And set it using:

tvc.amountOfQuestions = [self.questions.text intValue];

You don't even have to declare the instance variable or @synthesize the property - Xcode will handle it for you.

like image 134
Tim Avatar answered Apr 17 '26 00:04

Tim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!