IF Else方法,在NSString中

时间:2014-04-27 22:25:04

标签: ios objective-c nsstring

我有这个NSString格式:

comandoInsert = [NSString stringWithFormat:@"INSERT INTO fazerbem_clients (image) Values('%@')", list[0]];

但是大多数情况下数组列表可能是空的,导致编译器出现问题,所以我想尽可能在​​其中添加一个方法,如果数组为空,那么他会放一个空字符串如 @""

我尝试过这种方式不起作用:

comandoInsert = [NSString stringWithFormat:@"INSERT INTO fazerbem_clients (image) Values('%@')", [list[0] : @""] ];

我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

试试这个

comandoInsert = [NSString stringWithFormat:@"INSERT INTO fazerbem_clients (image) Values('%@')", list.count ? list[0] : @"" ];