문제

I have this NSString with format:

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

but most times the array list can be empty, causing a problem in the compiler, so I would like if possible to add a method if else within it, in a way that if the array is empty there he puts an empty string as @""

I tried this way just does not work:

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

How I can do this?

도움이 되었습니까?

해결책

try this

comandoInsert = [NSString stringWithFormat:@"INSERT INTO fazerbem_clients (image) Values('%@')", list.count ? list[0] : @"" ];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top