将NstaggedpointerString转换为int

时间:2016-11-02 11:51:02

标签: ios objective-c string nstaggedpointerstring

实际上我已经使用此代码将NstaggedpointerString转换为字符串

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);

我得到的字符串输出就像这样

String

     (
        1
    )

现在我怎么得到这个。

1 个答案:

答案 0 :(得分:2)

替换它:

int indexDayValue = (int)index;

用这个:

int indexDayValue = [index intValue];

修改

  

[__ NSArrayI intValue]无法识别的选择器发送到实例0x7f940053f7e0

那是因为index实际上是一个数组,而不是一个字符串。执行以下操作:

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