This might seem like a basic question but I’m still getting a handle on properties so please bear with me.
I have a custom NSView subclass that does its own drawing. I’ve set up support for different styles with a @property for setters and a typedef enum for human-readable integers. It works great, but the view won’t redraw after setting its style unless I manually call setNeedsDisplay:YES on the control or resize its parent window.
Logically one would think the solution would be to simply do a [self setNeedsDisplay:YES] in the classes’ setStyle: method, but I cannot for the life of me figure out how to properly do it. Whenever I try to override setStyle: it just complains, “Writable atomic property ‘style’ cannot pair a synthesized getter with a user defined setter”.
What should be done in this situation?
Ideally, you would just declare your actual ivar/storage as a private property, then manually implement the setter
setStyle:. In the implementation ofsetStyle:, set your private property/state, and perform your updates. So you just abstract the data from the client’s interface. There are other ways to approach this, such as directly setting the ivar.So an implementation may take the form:
MONThing.h
MONThing.m
Over time, you will learn multiple ways to accomplish this, and when you would favor one over the other.