IOS: using @private to hide properties

I am pushing a class that has a bunch of properties that I want to use only internally. Meaning I do not want to have access to them when they created my class. Here is what I have in my .h, but it still doesn't hide those from the autocomplete menu (getting into the watch list) in Xcode:

@interface Lines : UIView { UIColor *lineColor; CGFloat lineWidth; @private NSMutableArray *data; NSMutableArray *computedData; CGRect originalFrame; UIBezierPath *linePath; float point; float xCount; } @property (nonatomic, retain) UIColor *lineColor; @property (nonatomic) CGFloat lineWidth; @property (nonatomic) CGRect originalFrame; @property (nonatomic, retain) UIBezierPath *linePath; @property (nonatomic) float point; @property (nonatomic) float xCount; @property (nonatomic, retain) NSMutableArray *data; @property (nonatomic, retain) NSMutableArray *computedData; 

I thought using @private was what I needed, but maybe I did it wrong. Do I need to do something in my .m?

+16
private ios objective-c xcode
Oct 26 '11 at 22:05
source share
1 answer

@private only affects Ivars. This does not affect the properties. If you want to not publish properties, add them to the class extension instead. In your .m file at the top, put something like

 @interface Lines () @property (nonatomic) CGRect originalFrame; // etc. @end 

It looks like a category, except that the category "name" is empty. It is called a class extension, and the compiler treats it as if it were part of the original @interface block. But since this is in the .m file, it is visible only to the code in this .m file, and the code outside it can only see the public properties declared in the header.

+38
Oct 26 2018-11-21T00:
source share



All Articles