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

后端 未结 2 1836
有刺的猬
有刺的猬 2021-02-13 23:29

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 myCusto         


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-14 00:14

    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  {
        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).

提交回复
热议问题