[Drawkit] NSDocument based application, nil drawing
Graham Cox
graham.cox at bigpond.com
Fri May 22 17:30:17 PDT 2009
On 23/05/2009, at 3:24 AM, V1ru8 wrote:
> I'm totally new to DrawKit and I have some problems to understand
> its architecture. I set up a new Document Based application. Added a
> scroll view, a DKDrawingView and sub classed DKDrawingDocument.
> That works perfectly and I can add objects to my document (via drag
> and drop or by copy and paste).
> But now I want to access the DKDrawing of my document. But when I
> call "drawing" on the document only nil is returned. On the
> DKDrawingView I found the following line:
>
> "the drawing we created automatically (if we did so - typically nil
> for doc-based apps)"
>
> That has something to do with it?! I think I just don't get
> something about the main concept of DrawKit. Shouldn't DrawKit
> automatically generate a new DKDrawing when the DKDrawingDocument is
> initialized? I tried to set the drawing to a new DKDrawing. But then
> the document is just blank and I can't even add something.
>
> BTW DrawKit looks like a really great framework!
Hi Thomas, welcome to the list!
In IB, you need to hook the mMainDrawingView outlet to your
DKDrawingView. This ensures that the document ends up supplying the
DKDrawing instance and not the view.
Normally if you don't make this connection, the view will
automatically create a DKDrawing, which is the one you see in the
view. The document may make another one, but only if the document type
is set up so that the default DKDrawingDocument recognises it. (See -
initWithType:error:) Since your document's -drawing instance is nil,
it seems likely that you don't have a filetype set up to one of DK's
standard types (either .drawing or net.apptree.drawing UTI). The
intention is that your app will either declare its own file types, in
which case it has to fully implement -initWithType:error, including
making a DKDrawing instance, or it uses or extends DK's types, in
which case the -initWithType:error: method will make the drawing for
you.
I hope that helps - if you need further clarification do ask!
--Graham
More information about the Drawkit
mailing list