This code will simply return the last character of the string and not delete it:
NSString *newString = [oldString substringToIndex:[oldString length]-1];
you can use this instead of removing the last character and saving the remaining string values:
str = [str substringWithRange:NSMakeRange(0,[str length] - 1)];
and also using substringToIndex for NSString with 0 length will fail.
you must add confirmation before doing this:
if ([str length] > 0) { str = [str substringToIndex:[s length] - 1]; }
with this, it is safe to use the substring method.
NOTE. Apple will reject your application if it is vulnerable to crashes.
krischu Aug 28 '14 at 7:34 2014-08-28 07:34
source share