im trying this:
NSNumber *num1;
NSNumber *num2;
self.addNumberOfRoundsText.text = [num1 stringValue];
self.numberOfRoundsText.text = [num2 stringValue];
NSNumber *sum = [NSNumber numberWithInt:([num1 intValue] + [num2 intValue])];
NSLog(@"%@", [sum stringValue]);
For some reason, the console keeps outputting 0 im not sure if there is something i am missing. I just want to get the text from two UITextField’s and add them. Then output them to the console. Thank you for the help!
In your example code, you haven’t initialized
num1andnum2. So (if you are using ARC, which is the default for new projects), those variables are initialized to nil.In Objective-C, you can send any message (like
stringValueorintValue) to nil, and it will return 0 or nil back. So:I’m not sure what you’re actually trying to do. Maybe you have two text fields, and each text field contains a number, and you want to add up those two numbers. If that’s what you want to do, try this: