Convert NstaggedpointerString to int

2.2k views Asked by At

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.

1

There are 1 answers

5
alexburtnik On BEST 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:

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