Xcode 使用ComponentSeparatedByString创建的元素的类型转换是什么?
我需要从infoArray中的许多字符串中提取一些信息。infoArray中每个元素的布局看起来像@NO,YES,YES,YES,NO,NO,YES,等等 当我使用以下命令时:Xcode 使用ComponentSeparatedByString创建的元素的类型转换是什么?,xcode,Xcode,我需要从infoArray中的许多字符串中提取一些信息。infoArray中每个元素的布局看起来像@NO,YES,YES,YES,NO,NO,YES,等等 当我使用以下命令时: [splitArray setArray:[[infoArray objectAtIndex: i] componentsSeparatedByString:@","]]; 我可以通过以下方式访问新splitArray中所需的任何内容: NSLog(@"Result = %@", [infoArray objectAt
[splitArray setArray:[[infoArray objectAtIndex: i] componentsSeparatedByString:@","]];
我可以通过以下方式访问新splitArray中所需的任何内容:
NSLog(@"Result = %@", [infoArray objectAtIndex: 0]);
在这种情况下,它将正确打印出来。问题是在以下情况下我需要使用它:
if([infoArray objectAtIndex: 0] == @"YES"){
//do something
}
即使值为YES,上述代码也显然不起作用。我认为排版是错误的。我是个新手。有什么建议吗 很抱歉,我的笔记出错了:
NSLog(@"Result = %@", [infoArray objectAtIndex: 0]);
应该是
NSLog(@"Result = %@", [splitArray objectAtIndex: 0]);
if([splitArray objectAtIndex: 0] == @"YES"){
及
应该是
NSLog(@"Result = %@", [splitArray objectAtIndex: 0]);
if([splitArray objectAtIndex: 0] == @"YES"){
你们应该用额外的数据修改你们的问题,而不是回答你们自己的问题 要回答您的问题,请使用:
[[splitArray objectAtIndex: 0] isEqualToString:@"YES"]