Is a monolithic NSView the way to go?

5 views
Skip to first unread message

Benjamin Ragheb

unread,
May 4, 2013, 10:27:04 PM5/4/13
to cocoah...@googlegroups.com
I'm working on a Mac app and I'm hoping your collective experience may save me from having to learn from my own mistakes. I want to write a document editor, where a document consists of:

- one or more images, layered on top of each other;
- a collection of points, drawn over the images, which can be created, selected, and moved around;
- line segments, which join some of the points.

My first idea is to simply fill the window with a custom NSView subclass in which I draw all of these things, handle the mouse events, track which point is selected, etc. I know how to do this, but I wonder if there isn't a better way. It feels like there would be too much going on in this one view object.

Is this the right way to do it? Is it advisable to use CALayer instead of overriding drawRect:? Are there lesser-known things in AppKit that might be useful?

-- Ben

Andy Lee

unread,
May 5, 2013, 7:14:34 AM5/5/13
to cocoah...@googlegroups.com
Hi Ben,

It's perfectly reasonable to have the monolithic view object.

Check out Apple's Sketch example, in which SKTGraphicView is the monolithic view:

<http://developer.apple.com/library/mac/#samplecode/Sketch/Introduction/Intro.html>

I would also at least look at Graham Cox's DrawKit:

<http://apptree.net/drawkitmain.htm>

I only know DrawKit by name and not first-hand experience, so I don't know if Graham uses layers, but I remember this thread where he asked about printing:

<http://www.cocoabuilder.com/archive/cocoa/324990-printing-layer-based-view.html>

Also I don't know what work he's done since 2010 (which is the date he gives for beta 7), but it's his baby, so I would guess he's continued to work on it.

--Andy

Andy Lee

unread,
May 5, 2013, 1:40:29 PM5/5/13
to cocoah...@googlegroups.com
Truth be told, in your shoes I'd probably end up rolling my own view class but keep these projects around for reference.

--Andy
Reply all
Reply to author
Forward
0 new messages