views:

280

answers:

3

Does anyone know why I am getting the following error:

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
{
 id result = (Possession *)[possessions objectAtIndex:[indexPath row]];

 [result setRowSwapped:TRUE]; //Passing argument makes pointer from integer without a cast
}

//This is the property on the possession object.  I just want to set it as true thats it
@property (nonatomic) bool *rowSwapped;
A: 

You need to show us the definition of your setRowSwapped: routine to be sure, but it looks to me like you have a mismatch in the definition and the use. Did you make that method take a BOOL * parameter? Regardless, it's a little weird to type your variable id - what is your goal on that front?

Carl Norum
A: 

TRUE is a number (equaling 1 in value) and setRowSwapped seems to expect a pointer of some kind as argument. Thus the compiler is transforming the int value 1 into a pointer, which is a warning, because this is hardly ever correct and if it was correct and you'd know what you are doing, you had used an explicit cast, which also avoids the warning. Sine you used no cast, you probably expected that the method expects a boolean as argument, and that seems to be incorrect.

BTW, since this is Objective-C, you should not use TRUE/FALSE in Objective-C, but YES/NO. The difference is that TRUE/FALSE is of type bool (all lower case, same as _Bool or boolean_t on Mac) and that again is usually of type int and 4 byte (at least on PPC and Intel, maybe not true for other Apple devices, like iPad). YES and NO are of type BOOL (all upper case) and this type is 4 Byte on PPC and 1 Byte on Intel. Thus bool and BOOL are not always the same and in some very rare conditions this can indeed cause problems. So you should not mix them. In Obj-C code use BOOL and YES/NO, in C code, use bool, boolean_t or _Bool and TRUE/FALSE.

Mecki
A: 

I used bool instead of BOOL.

TheLearner