What triggs dataRepresentationOfType?

  • In Aaron's book on page 157 it says:

    The menu items Save, Save As..., Save All, and Close are all different, but all deal with the same
    problem: getting the model into a file or file wrapper... To handle these menu items, your NSDocument subclass must implement ...

    - (NSData *)dataRepresentationOfType:(NSString *)aType

    My question is what triggers the method dataRepresentationOfType and how it's done. Is it the Runtime system that automatically sends dataRepresentationOfType to the current NSDocument when the user chooses Save or is something else happenning?

    Bob


    ____________________________________________________________________________________
    Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more.
    http://mobile.yahoo.com/go?refer=1GNXIC
  • --- Bob Ueland <bobueland...> wrote:

    > My question is what triggers the method
    > dataRepresentationOfType and how it's done. Is it
    > the Runtime system that automatically sends
    > dataRepresentationOfType to the current NSDocument
    > when the user chooses Save or is something else
    > happenning?

    When the Save menu item is chosen, it sends its action
    (saveDocument:) down the responder chain, eventually
    finding your document as the first responder.
    NSDocument knows how to save itself, and its method
    for doing this calls on dataRepresentationOfType: to
    get the data it needs to write.

    Cheers,
    Chuck

    __________________________________________________
    Do You Yahoo!?
    Tired of spam?  Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
  • > - (NSData *)dataRepresentationOfType:(NSString *)aType
    >
    > My question is what triggers the method dataRepresentationOfType and
    > how it's done. Is it the Runtime system that automatically sends
    > dataRepresentationOfType to the current NSDocument when the user
    > chooses Save or is something else happenning?

      Any time you want to know the answer to questions like this your
    first stop should be the documentation. The documentation, for
    example, specifically says of this method:

    "This method is invoked by the default implementation of
    fileWrapperRepresentationOfType:."

      You can also look at the "companion guide" section of the doc that
    contains the method you're interested in (the very top of the
    NSDocument doc, in this case). It typically refers you to one or more
    documents covering the topic in general. In this case, "Document-Based
    Applications Overview" which in turn contains a section titled
    "Message Flow in the Document Architecture" that explains in great
    detail exactly what you're asking.

      It's vitally important to master searching the documentation. It
    all started with searching for the method you mentioned. I had to do
    that just now because I don't remember where everything is and what
    it's called, but in five seconds, I had detailed answers to your
    question.

      It sure beats waiting for an answer from the list. :-)

    --
    I.S.
  • Thanks Charles and I.S. for your answers, it's clear now what happens.

    With regards to I.S. I have some small comments.

    I.S. wrote:Any time you want to know the answer to questions like this your
    first stop should be the documentation.

    I did actually begin by going to the 'NSDocument Class Reference' and found the following 'explaination':

    dataRepresentationOfType:
    A
    primitive method overridden by subclasses to return a data object that
    represents the data of the receiver in a given type. (Deprecated. Use
    dataOfType:error: instead.)

    - (NSData *)dataRepresentationOfType:(NSString *)aType

    Discussion
    A
    primitive method overridden by subclasses to return a data object that
    represents the data of the receiver in a given type (aType). The
    default implementation raises an NSInternalInconsistencyException. This
    method is invoked by the default implementation of
    fileWrapperRepresentationOfType:.

    aType is the type name corresponding to the value of the CFBundleTypeName entry in the document type's Info.plist dictionary.

    I
    did not understand this. Also it did not answer my question. Then I did
    look at the 'companion guide' called 'Document-Based Applications
    Overview'. I downloaded the pdf file and opened it and saw that it was
    67 pages long. So I did not look inside it because I'm not yet savvy
    enough to find my way around (this was probably mistake. I should at
    least have glanced through the TOC and then maybe I would have spotted
    the heading Message 'Flow in the Document Architecture'.)
    Then I went and
    searched on Internet and then in the forum. Since I did not find any
    answer, I posted a question and got a nice explanation from Charles.

    I.S. wrote: I don't remember where everything is and what
    it's called, but in five seconds, I had detailed answers to your
    question. It sure beats waiting for an answer from the list. :-)

    That's
    because you are Cocoa Savvy. Newbies like me can't find such an answer
    in 10 minutes, less alone in five seconds. I know that I must
    eventually get acquainted with refdocs, but right now I'm in no
    position to do that, so I nibble small sections and I'm very happy when
    I understand whole pages.

    However thanks for the encouragement.
    Every time I do ask something from the forum I learn a lot :). So I
    don't mind waiting for the answer.

    Bob


    __________________________________________________
    Do You Yahoo!?
    Tired of spam?  Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
  • You said this:

    > I downloaded the pdf file and opened it and saw that it was
    > 67 pages long. So I did not look inside it because I'm not yet savvy
    > enough to find my way around (this was probably mistake. I should at
    > least have glanced through the TOC and then maybe I would have spotted
    > the heading Message 'Flow in the Document Architecture'.)

      Then you said this:

    > That's
    > because you are Cocoa Savvy. Newbies like me can't find such an answer
    > in 10 minutes, less alone in five seconds. I know that I must
    > eventually get acquainted with refdocs, but right now I'm in no
    > position to do that, so I nibble small sections and I'm very happy when
    > I understand whole pages.

      ... which boils down to "I know I need to tackle the documentation
    but I don't want to right now." :-)

      That you're not yet Cocoa savvy doesn't matter. I became savvy by
    spending hours browsing the documentation and getting a good feel for
    how it's organized (and incidentally learning about the API and its
    architecture at the same time). It's time well spent because I can at
    least remember, "Oh yeah, there's a reference guide on that topic."
    then I can go in search of it. I don't "know" most of Cocoa. I just
    know where to find the answers because I familiarized myself with the
    docs.

      You'll never know everything about Cocoa without 'peeking'. It's
    just not going to happen. Knowing how to research your questions with
    the available reference material (ie, developing your research skills)
    is a much more realistic and effective goal. Believe me, it'll make
    you a much better developer.

    --
    I.S.
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today