Can't make the default property unavailable?

A UITableViewCell defaults to the textLabel property. Now I have subclassed UITableViewCell and created my own text layout system that does not use textLabel . To reduce the likelihood of an error, I would like to make the default textLabel inaccessible to the compiler (autocomplete), and that if I try to access it outside the class, the code will not compile.

Running the readonly property will still allow me to access and change the properties of the label, so this will not work.

Is there any way to do this?

Edit:

So, the closest I still update the property in my subclass and condemn it:

 @property (nonatomic) UILabel *textLabel NS_DEPRECATED_IOS(2_0, 3_0); 

which currently gives me a warning if I try to access the property. But that doesnโ€™t completely hide it from the compiler, and it also gives me the warning โ€œAvailability does not match previous declarationโ€.

+4
source share
2 answers

Ok, got it. You can use the UNAVAILABLE_ATTRIBUTE macro to do the following:

 @property (nonatomic) UILabel *textLabel UNAVAILABLE_ATTRIBUTE; 

and then executing cell.textLabel gives a compilation error: textLabel is unavailable .

+5
source

He just read. You can access, but not assign. See the header file.

 @property(nonatomic,readonly,retain) UILabel *textLabel 

//Example

 @interface myCell : UITableViewCell { } @end @implementation myCell -(void)check { //You can access UILabel *label = self.textLabel; //You canot assign self.textLabel = label; } @end 
+1
source

All Articles