以#开头的NSString使用componentsSeparatedByString不起作用

时间:2018-09-01 17:13:44

标签: objective-c nsstring

我的代码如下:

NSArray *modifyVersionOnDevice  [FileHandler parseFile:devicepath];
NSString *param = [modifyVersionOnDevice objectAtIndex:1];

//param at this point is one element with string of "#MAJREV: 3"

//As soon as I run the next line, I get an error Unrecognized selector sent 
to instance.

NSArray *d =[param componentsSeparatedByString:@":"];

如果我进行硬编码

NSString *param =@"#MAJREV: 3";  it works

1 个答案:

答案 0 :(得分:-4)

原来,您必须将param转换为文字字符串。

NSString *param = [NSString stringWithFormat:@"%@",[modifyVersionOnDevice objectAtIndex:1]];

然后     NSArray * d = [param componentsSeparatedByString:@“:”];