Here the situation that I encounter a lot is enough for the template code to be wasteful and sufficient, and I am sure that I cannot be the only one. Is this uniomatic, is there a better way, or should I just do it every time?
@interface SomeUIElement : UIView @property CGFloat insetMargin; // <-- just an example of a UI parameter @end @implementation SomeElement - (void)setInsetMargin:(CGFloat)insetMargin { _insetMargin = insetMargin; [self setNeedsDisplay]; // <-- the only thing that stops it being synthesized } @end
now this causes a compilation warning that I donโt have a recipient to get rid of what I can add
- (CGFloat)insetMargin { return _insetMargin; }
but now he complains that I donโt have ivar (because the specific getter and setter means that it wasnโt created for me), so I need to add
@interface SomeUIElement () { CGFloat _insetMargin; }
which means that we have significant overhead, just requiring a forced screen refresh when the property changes.
Is there any way to tell ObjC that I intended to create getter and ivar for it, so I only need to write setter, or (b) the best way to request a display update when a property is associated with a change in appearance?
How does the Apple SDK do this (I assume I have not missed any way to view, say, the source of UILabel)?
source share