Mad Burea Mad Burea - 1 year ago 258
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



now how i get this 1.

Answer Source

Replace this:

int indexDayValue = (int)index;

with this:

int indexDayValue = [index intValue];


[__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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download