質問

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