Mad Burea Mad Burea - 1 month ago 33
iOS Question

Convert NstaggedpointerString to int

actually i have used this code for converting NstaggedpointerString to string

NSString *index = [responseSelectedAvailibility[i] valueForKey:@"day"];

NSLog(@"String %@",index);

int indexDayValue = (int)index;
NSLog(@" index %d",indexDayValue);

indexDayValue = indexDayValue-1;

NSLog(@" index after decrementing %d",indexDayValue);


i get output of string is like this

String

(
1
)


now how i get this 1.

Answer

Replace this:

int indexDayValue = (int)index;

with this:

int indexDayValue = [index intValue];

Edit:

[__NSArrayI intValue] unrecognized selector sent to instance 0x7f940053f7e0

That's because index is in fact an array, not a string. Do the following:

NSArray *dayArray = [responseSelectedAvailibility[i] valueForKey:@"day"];
NSString *dayIndexString = [dayArray firstObject];
int dayIndex = [dayIndexString intValue];