Stuck again - Drawing App

I’m not sure what the book is really asking for here: “Create a new document-based application that allows the user to draw ovals in arbitrary locations and sizes. NSBezierPath has the following initializer:
​ ​ ​ ​i​n​i​t​(​o​v​a​l​I​n​R​e​c​t​:​ ​N​S​R​e​c​t​)​ ​-​>​ ​N​S​B​e​z​i​e​r​P​a​t​h​”

I’ve written a version that uses init(ovalIn: NSRect) -> NSBezierPath that will draw random sized ovals automatically with a click of the mouse, locating the origin of the oval where the mouse clicked in the view. – The book’s version of init(ovalInRect: NSRect) is now init(ovalIn: NSRect) – I had to add a custom view to the document view to get this to work. But this will only show one oval at a time (so far), and technically, I don’t think it is a real drawing app. I haven’t spent time trying to figure out how to save or undo this yet since I don’t know if it is the correct way to go.

I did another version that allowed me to draw ovals (as many as I wanted to draw) in the document view by dragging the mouse. But this version doesn’t use the suggested initializer, init(ovalIn: NSRect) -> NSBezierPath. And I haven’t figured out a way to save it yet, but can still work on that aspect if this is the correct path to take. I tried to add a computed oval over the drawn one using the mouse locations to come up with an origin and a rect of that size, then using the recommended init(ovalIn: NSRect) to draw the oval, but I get a whole list of runtime errors with that when it tries to fill().

Any ideas of what the intent was here? I know no one from BNR monitors this any more (unless some of you that have been kind enough to help me are from there) so I can’t get input from them.

Are either of these ideas on the path of what the intent for this challenge is, or am I way off? I don’t want to keep trying figure out a way to get either to work correctly if I’m way off.

Thanks!

You can get unstuck by doing some extra work :slight_smile:

I don’t have the book yet, but since the book is asking you to do a document-based exercise you should at least implement the functionality that is required for saving and opening documents.

In older versions of the book there used to be a chapter on archiving objects (saving them to a store) and unarchiving them (resurrecting them from an archive.) This involves the use of the NSCoding protocol, which is easy to understand and which is explained in Apple’s documentation, here.

Godspeed

I agree about not stopping on this challenge yet and I will finish both the archiving along with the undo. I was just not sure which version of what I’ve come up is closer to what the Challenge was asking for. I’ll just pick the one that is close to a real drawing app and use that one.

There still is the chapter on archiving, it’s chapter 12 now.

Thanks ibex!

Moving on. Can’t get it to work.