Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: property 'myBoolVariableName' with 'retain' attribute must be of object type

I have a BOOL value inside my @interface definition in my .h file. Here it is below. It has the same problem whether it's a pointer or not.

@interface myCustomViewController : UIViewController <UIWebViewDelegate> {
{
 //...more iboutlets defined above
 BOOL *myBoolVariableName;
}

When I compile, I get "error: property 'myBoolVariableName' with 'retain' attribute must be of object type" on the line for the import of my .h file.

I found this page here about an integer / nsnumber:

http://discussions.apple.com/thread.jspa?threadID=1846927

So, it seems I can't use BOOL values inside an @interface definition. What can I use instead?

What should I do for BOOL / boolean values?

like image 632
Neo42 Avatar asked Aug 27 '09 00:08

Neo42


1 Answers

I'm guessing that later in your interface you have something like this:

@property (retain) BOOL *myBoolVariableName;

That means make a property who's value is a pointer to a BOOL, and use retain semantics.

Your problem is that BOOL * is a pointer to a byte of memory, not a pointer to an object. And retain is something that applies only to objects.

Here's how you can make a BOOL property.

@interface myCustomViewController : UIViewController <UIWebViewDelegate> {
    BOOL myBoolVariableName;
}

@property myBoolVariableName;

@end

The important differences are that the variable is declared as "BOOL", not "BOOL *" and the property doesn't have (retain).

like image 173
Jon Hess Avatar answered Sep 22 '22 05:09

Jon Hess