Hey I’m learning Objective C and I have one question. I Have one Text Field the Input should be a Number with this number i want to calculate something but how do I do that ?
NSNumber *test;
if ([prospekt_1 intValue] == 0) {
test = [prospekt_1 intValue] * 2.50;
[ergebnis_prospekt_1 setIntValue:test];
}
Thanks for your help. 🙂
NSNumber
testis an object pointer. You’re assigning an int to an object, essentially making it a pointer to an invalid memory address.You want
test = [NSNumber numberWithInt:[prospekt_1 intValue] * 2.50];This creates a new object (NSNumber) and assigns it to the pointer
test.or
You could skip the NSNumber object entirely and just assign the int value directly. Why waste memory on an object? An int is smaller memory footprint.
Replace
NSNumber *withintand it will also work and be more memory efficient.