Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increment numeric value stored in Objective-C string

Tags:

xcode

iphone

How can I increment numeric String value?

If it is initially "1", I want to increment it in every applicationDidEnterBackground click

like image 439
Toseef Avatar asked Jun 27 '26 10:06

Toseef


2 Answers

In your case it's weird that you use string for that purpose but you can technically do it like this:

int myInt = [myString intValue];// I assume you need it as an integer.
myString= [NSString stringWithFormat:@"%d",++myInt];
like image 72
Mikayil Abdullayev Avatar answered Jun 30 '26 01:06

Mikayil Abdullayev


Best option: make it a number instead of a string.

Other option: strValue = [NSString stringWithFormat:@"%d", [strValue integerValue] + 1];

like image 45
Phillip Mills Avatar answered Jun 29 '26 23:06

Phillip Mills



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!