I’m trying to display in a label on my main screen the size of NSMutableArray when the screen loads 1st time and then every time I hit the Add button, but I get errors such as “Expression result unused”. I tried several options but still no success…
Please advise me with your inputs, thanks! 🙂
int arraySize;
NSMutableArray *arrRaceCars;
- (void)viewDidLoad
{
[super viewDidLoad];
arrRaceCars = [[NSMutableArray alloc]init];
arraySize = [self numberOfObjectsInArray:arrRaceCars]; // call for a method that should return the number of objects in array
self.lblCarsCount.text = @"%d cars in the race", &arraySize;
}
// ...part of the Add button validation; in case that everything is OK, the code below should add an object to the array and change the display of number of cars in the array in the label
else
{
self.carType = [segmentedSelectCar titleForSegmentAtIndex:segmentedSelectCar.selectedSegmentIndex];
self.carName = self.txtCarName.text;
self.carSpeed = [self.txtCarSpeed.text intValue];
car* newCar = [[car alloc]initCarWithName:carName carType:carType carMaxSpeed:carSpeed];
NSLog(@"Car type is: %@, Car name is: %@, Car speed is: %d", self.carType, self.carName, self.carSpeed);
[arrRaceCars addObject:newCar];
arraySize = [self numberOfObjectsInArray:arrRaceCars];
self.lblCarsCount.text = @"%d cars in the race", &arraySize; // this is the problematic line
[self alertMessage:@"addNewCar" :@"Your car has been added!" :nil :@"OK" :nil];
}
// this is the method that should return the number of objects within the array
-(int) numberOfObjectsInArray : (NSMutableArray*) arrayToCheck
{
return [arrayToCheck count];
}
Instead of
you should be using:
The first line of code compiles, but the compiler doesn’t know you want to do a string with a format (the “expression result unused warning”) which is why you should put the explicit “
stringWithFormat” method call in there.