Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to hide a @property in a subclass?

My app subclasses UICollectionViewFlowLayout and uses all of its properties except for minimumLineSpacing. To avoid confusion, I'd like to be able to "hide" minimumLineSpacing from the outside, so it looks like my subclass doesn't even support it. Is this possible?

like image 226
Spencer Williams Avatar asked Dec 09 '22 16:12

Spencer Williams


2 Answers

Yes you can. Kind of. You can mark it with __attribute__((unavailable)), which will cause the compiler to throw an error if you use it. However, the property will still be accessible if your object is cast to its superclass type, as this is a compile-time-only thing.

@interface MyClass : UICollectionViewFlowLayout
@property (nonatomic) CGFloat minimumLineSpacing __attribute__((unavailable));
@end
like image 104
Lily Ballard Avatar answered Dec 11 '22 05:12

Lily Ballard


I don't think you can actually hide it. You could of course overwrite the getter and setter and prevent the acutal value from beeing changed, if that is of importance. But they will always exist and be visible.

like image 34
Hermann Klecker Avatar answered Dec 11 '22 05:12

Hermann Klecker