tags:

views:

437

answers:

1

Hello,

I have:

 BOOL someBoolValue = ... //some code returning BOOL

when I try to invoke:

[self performSelectorOnMainThread:@selector(refreshView:) withObject:someBoolValue waitUntilDone:NO];

I'm getting a warning:

cast to pointer from integer of different size

Any hints on this?

+4  A: 

You are passing a "raw" boolean value, where an id (pointer to an object) should be.

[self performSelectorOnMainThread: @selector(refreshView:) 
      withObject:someBoolValue 
      waitUntilDone:NO]

should better be

[self performSelectorOnMainThread:@selector(refreshView:) 
      withObject: [NSNumber numberWithBool: someBoolValue] 
      waitUntilDone: NO]

You can extract the boolean value in your refreshView: method by sending the boolValue method to the number object:

if( [myWrappedBoolean boolValue] ) {
    ...
}

Unlike Java or C#, Objective-C has no "autoboxing" from primitive values to objects. The BOOL type is just a small integer type, which causes the error message you are seeing, because the compiler needs a pointer for the second argument to performSelectorOnMainThread:withObject:waitUntilDone:.

Dirk
Thanks for explanation! Now I get it.I've got one more related question: what parameter type should I put to the refreshView: method? should it be BOOL? or id?
Jakub
Definetly `id` or even a more specific type (`NSNumber` if you follow the direction given in the answer). No autoboxing also means no auto*un*boxing.
Dirk
Thanks! It looks reasonable.
Jakub