Cast to pointer from integer of different size in performSelectorOnMainThread:withObject:waitUntilDone
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?
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:
.
精彩评论