• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why does initWithCoder has other self-object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does initWithCoder has other self-object?


  • Subject: Re: Why does initWithCoder has other self-object?
  • From: Jens Alfke <email@hidden>
  • Date: Thu, 18 Aug 2011 09:16:04 -0700

On Aug 18, 2011, at 7:50 AM, Arno Oesterheld wrote:

> I can not call [super initWithCoder] because NSDocument does not have such a method. Should I call [self init] instead oder [super init]?

The advice you’ve gotten so far does not, unfortunately, address your basic problem, which is: Don’t make an archivable NSDocument. That isn’t how NSDocuments work. Your custom contents of the document should be archived, _not_ the NSDocument object itself.

AppKit is going to instantiate your NSDocument subclass instance for you, and then ask it to load its contents from a given file/URL/NSData. That’s what you should be unarchiving. Then when the user says to save, AppKit will ask your document object to save its contents; you archive the contents (not the NSDocument itself) and write them out.

Basically what you should do is define one or more classes that form your object model; then implement NSCoding in these classes. Your NSDocument subclass should have an instance variable pointing to the root model object. Now when the document is asked to load or save the data, it can archive/unarchive the root model object.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >Why does initWithCoder has other self-object? (From: Arno Oesterheld <email@hidden>)
 >Re: Why does initWithCoder has other self-object? (From: Peter <email@hidden>)
 >Re: Why does initWithCoder has other self-object? (From: Arno Oesterheld <email@hidden>)

  • Prev by Date: Suspicious Bill
  • Next by Date: Re: quick look question
  • Previous by thread: Re: Why does initWithCoder has other self-object?
  • Next by thread: Re: Why does initWithCoder has other self-object?
  • Index(es):
    • Date
    • Thread