Obj-C failed in substring messageWithRange

The following code crashes my application on line 3 without an error that I would recognize or know how to deal with. Any ideas on what I'm doing wrong?

NSInteger *match = [str1 intValue] + [str2 intValue];
NSString *strrep = [NSString stringWithFormat:@"%i", match];
label.text = [strrep substringWithRange:NSMakeRange(1,3)];
+3
source share
3 answers

I suggest you split line 3 into two lines to isolate the problem.

NSString *result = [strrep substringWithRange:NSMakeRange(1,3)];
label.text = result;

If I were to guess, I would say that the shortcut was probably released somewhere and you are trying to assign a bad location.

+6
source

You want to NSInteger match. There is no pointer. (NSInteger is not a class, it is just a typedef for intor longdepending on your compilation goal.)

, , , , , int.

+6

If your string is less than (1 + 3) 4 characters long, it will crash.

+3
source

Source: https://habr.com/ru/post/1739217/


All Articles