• 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: [SOLVED] CoreData/NSPersistentDocument initialization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [SOLVED] CoreData/NSPersistentDocument initialization


  • Subject: Re: [SOLVED] CoreData/NSPersistentDocument initialization
  • From: Oftenwrong Soong <email@hidden>
  • Date: Sun, 22 Nov 2009 22:34:38 -0800 (PST)

Hi All,

Thanks to Jerry for the feedback.

What I thought was a framework question (why -init was being called instead of -initWithType:error: in my NSPersistentDocument subclass) turned out to instead be a tools question. I had placed a breakpoint in -initWithType:error: and execution did not halt there, so I asked why this method wasn't being called. Now, I believe the method was being called but the breakpoint was not halting execution. Why this happened remains a mystery because I tried many things in rapid succession until the breakpoints started working.

When they started working, I saw that everything worked exactly as Jerry said it should:
    -init was being called in both cases (new document and loading an existing document).
    -initWithType:error: was being called for new documents.

(And, yes, I am calling the super implementation in both.)

Thanks for the help,
Soong




----- Original Message ----
From: Jerry Krinock <email@hidden>
To: Cocoa Developers <email@hidden>
Sent: Fri, November 20, 2009 11:07:18 PM
Subject: Re: [SOLVED] CoreData/NSPersistentDocument initialization

On 2009 Nov 20, at 12:04, Oftenwrong Soong wrote:

> However, initWithType:error is never called for new document creation (or any document creation for that matter). I placed a breakpoint inside the method and execution does not pause there. Instead, -(id)init gets called.

It's not 'instead'.  It's both.  When a new document is created, Cocoa invokes -initWithType:error:.  When you override this method, you must invoke super.  -[NSPersistentDocument initWithType:error:] will then invoke -init.  Likewise if you override -init, invoke super.

> This is a problem because -(id)init is called when documents are opened as well as created from scratch.

Actually it's rather handy for doing *some* initializations which you want done in both new and old documents.  I say *some* because your persistence stack is not yet functioning at this point.

_______________________________________________

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




_______________________________________________

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: 
 >CoreData/NSPersistentDocument initialization (From: Oftenwrong Soong <email@hidden>)
 >Re: [SOLVED] CoreData/NSPersistentDocument initialization (From: Oftenwrong Soong <email@hidden>)
 >Re: [SOLVED] CoreData/NSPersistentDocument initialization (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: mySQL client lib linking problem...
  • Next by Date: NSString componentsJoinedByString--strange output
  • Previous by thread: Re: [SOLVED] CoreData/NSPersistentDocument initialization
  • Next by thread: UI Question: Hide application window after minimising
  • Index(es):
    • Date
    • Thread