Re: Problem with Auto Layout and drawRect
Re: Problem with Auto Layout and drawRect
- Subject: Re: Problem with Auto Layout and drawRect
- From: Dave <email@hidden>
- Date: Tue, 08 Sep 2015 09:52:05 +0100
> On 8 Sep 2015, at 01:02, Graham Cox <email@hidden> wrote:
>
> Just a brief comment on the design of your class.
Actually it was based on something I found in a book I think and written many moons ago back in the dark ages of CodeWarrior.
> Why do you declare properties for frame and pane colour, and then have additional setter methods that set these properties (and mark the view as needing display)?. You can write the property setter methods directly to cause a refresh and none of those extra methods are needed. It ensures that there’s no way code can change the property without the view redrawing.
Because I want to be able to change the properties without the view updating sometimes. Also at some point I was going to make the properties private and just use methods which seems to be the new way of doing things.
> The flags for drawing the frame and fill are redundant - you could have the colour property set to nil to mean ‘don’t draw this’.
I could but then when when I wanted to switch off drawing the pane or the frame I’d have to remember the colour somewhere, having them separate means I can turn it off without having to worry about the current colour and when its turned back on, it has the same colour as before.
> Also, NSColor is immutable so there’s little purpose to having that property ‘copy’, it can be ‘retain’ (or ‘strong’) and it will save you a small amount of space per instance.
AFAIK, the copy attribute causes a retain in this case anyway so it makes no odds. Also “copy” is logically want is wanted in this case, I know NSColor is immutable, but that’s an implementation detail that in theory could change, by explicitly making it copy I make it clear that the values are private to the property/class.
> These are minor nits to be sure, but often it’s this that makes the difference between a good class and a great one.
It draws a friggin coloured Rectangle for god’s sake, no need to worry whether its good, bad or totally crap - it works! lol
All the Best
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden