Reputation: 923
I declared a function with boolean input var. I get no errors. However, when calling it from another controller, notification appears: "incompatible integer to pointer conversion sending'BOOL' to parameter of type BOOL". What am I doing wrong? Thanks.
- (void)composeBar: (BOOL *)savePars
from other view:
AppDelegate *localFunction = [[UIApplication sharedApplication] delegate];
[localFunction composeBar:YES];
Upvotes: 5
Views: 2807
Reputation: 726479
This is because you declared the function as taking a pointer to boolean, not a boolean. This is how the declaration should look:
- (void)composeBar: (BOOL)savePars
*
accompanies id types (i.e. the ones you define through @interface/@implementation
). Regular C types, enums, structs, etc. do not need a *
in the declaration, unless you actually want to pass a pointer.
Upvotes: 4
Reputation: 185661
BOOL*
isn't a boolean. It's a pointer to a boolean. Just use
- (void)composeBar:(BOOL)savePars
You're likely confused because all Obj-C objects are declared with the *
, but that's because they're actually pointers. However, BOOL
is not an object, it's actually just a char
which holds 0
or 1
. Just as you would use int
for an integer instead of int*
(or in more idiomatic code, NSInteger
), you use BOOL
instead of BOOL*
.
Upvotes: 9