Aaron
Aaron

Reputation: 1342

format not a string literal and no format arguments objective c

When I build the below code, I get a warning like "Format not a string literal and no format arguments".

NSString *items = [NSString stringWithFormat:@"%d",itemNumber[0]];

for (int i = 1; i < (_housesOwned[0] + 1); i++)
{
    items = [items stringByAppendingFormat:[NSString stringWithFormat:@",%d", itemNumber[i]]];
}

I'm getting the warning in the line inside for loop.

itemNumber is an int array. Please help. Even though build is successful, I'm having a feeling like this could mess up in future.

Upvotes: 2

Views: 360

Answers (1)

Ilanchezhian
Ilanchezhian

Reputation: 17478

You make this line

items = [items stringByAppendingFormat:[NSString stringWithFormat:@",%d", itemNumber[i]]];

to

items = [items stringByAppendingFormat:@",%d", itemNumber[i]];

or

items = [items stringByAppendingString:[NSString stringWithFormat:@",%d", itemNumber[i]]];

This will not give warning. Nothing else.

Upvotes: 3

Related Questions