Вопрос

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