TomLisankie
TomLisankie

Reputation: 3955

Why am I getting an 'Expression Result Unused' warning?

I have a piece of code that is giving me a 'Expression Result Unused' warning. I have no idea what I'm doing wrong. Please help!

  if(task.typeForThis.typeID == @"DivisionAT"){

    probsPerDayLabel.hidden = NO;
    whatToDoLabel.hidden = YES;
    //int ppdi = task.probsPerDay;
    //NSString *ppd = [NSString stringWithFormat: @"%i", ppdi];
    probsPerDayLabel.text = @"Do %i problems today.",task.probsPerDay; //Right here

}

Upvotes: 0

Views: 2299

Answers (2)

grahamparks
grahamparks

Reputation: 16296

This line:

probsPerDayLabel.text = @"Do %i problems today.",task.probsPerDay

should be:

probsPerDayLabel.text = [NSString stringWithFormat:@"Do %i problems today.",task.probsPerDay];

In your version, the result of task.probsPerDay is completely unused, and the text on the label will be "Do %i problems today.", without the %i being replaced by a number.

Upvotes: 5

jonkroll
jonkroll

Reputation: 15722

You need to be using the stringWithFormat: method of NSString, like this:

probsPerDayLabel.text = [NSString stringWithFormat:@"Do %i problems today.", task.probsPerDay];

Upvotes: 3

Related Questions