• 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: Fri, 20 Nov 2009 13:54:06 -0800 (PST)

Hi all,

Well it's solved, for now, but I have no idea how or why. I'll explain the steps taken as well as I can remember them, in the hopes that someone has seen something similar and can tell me what in the world just happened.

I needed to initialize a Core Data model on new document creation and followed the steps in Apple's "Departments" example, which explains how to override NSDocument's initWithType:error: method in my MyDocument class. The fine explanation is here:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/NSPersistentDocumentTutorial/04_Department/department.html#//apple_ref/doc/uid/TP40002832-SW1


In my last post, I stated that initWithType:error: was not being executed for new document creation. I came to this conclusion because of two things:

1. The model apparently wasn't being initialized and interface elements were not displaying the correct values or even operating correctly. For example, you could not type into a text field in the running application. That text field was supposed to be connected, through a NSObjectController, to a model object.

2. I placed breakpoints in initWithType:error: and execution did not stop there. The breakpoint arrows turned yellow (as opposed to blue) in the Xcode gutter. Somewhere I heard that this happens when the code has not been loaded into memory, hence the breakpoint cannot be resolved. I don't know why this should be the case since the document window did appear and hence its controller class must have been loaded.

I checked my build configuration and was running Debug, not Release.

I checked the compiler flags related to debug information. Although I don't believe there was a problem with my earlier settings, I changed the following:

- Debug Information was stabs; I changed it to DWARF with dSym file.
- Level of Debug Info was default; I changed it to All Symbols (which sets -fno-eliminate-unused-debug-symbols.
- I set optimization to None (-O0) as opposed to -Os. Yes, I know it should be -Os but that does bizarre things like statement reordering and elimination.

I even cleaned all targets and re-ran. But none of this seemed to make any difference.

To test my sanity, I created a new NSPersistentDocument-based Core Data project, copied the model file over, copied a few methods, such as initWithType:error:, into the generated MyDocument class implementation, copied over my custom NSView subclass, threw that and an object controller into a xib file, drew some connections, and ran it. It *did* execute initWithType:error:. But my original project didn't.

This was strange indeed.

I did a bunch of things at that point (not necessarily in this order): closed and re-opened Xcode, cleaned and rebuilt all targets a few times, put some NSLog calls in the methods that didn't appear to execute, and probably a few other things I can't remember, and somehow, mysteriously, it began to work. It stops at the breakpoints now, though sometimes they're blue and sometimes they're yellow. I can't explain any of this. If someone can, please enlighten me!

Thanks,
Soong



----- Original Message ----
From: Oftenwrong Soong <email@hidden>
To: email@hidden
Sent: Fri, November 20, 2009 12:04:06 PM
Subject: CoreData/NSPersistentDocument initialization

Hi all,

My document model is Core Data based. When a new document is created, I must initialize the model to contain several objects with default values.

I followed Apple's "Departments" example:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/NSPersistentDocumentTutorial/04_Department/department.html#//apple_ref/doc/uid/TP40002832-SW1

At that page, it explains how to create a new Department object when a new document is created. It does so by implementing -(id)initWithType:error: in the MyDocument class, which is a NSPersistentDocument subclass, just like my own app's document class.

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. This is a problem because -(id)init is called when documents are opened as well as created from scratch.

My questions are:
1. Have I overlooked something?
2. Is there a better way to initialize new Core Data models to a known state? (Yes, I know I can create a whole model in code, a la the Core Data Utility example, but I mean when using NSPersistentDocument.)

Thanks,
Soong



_______________________________________________

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

  • Follow-Ups:
    • Re: [SOLVED] CoreData/NSPersistentDocument initialization
      • From: Jerry Krinock <email@hidden>
References: 
 >CoreData/NSPersistentDocument initialization (From: Oftenwrong Soong <email@hidden>)

  • Prev by Date: How to incrementally compress jpeg?
  • Next by Date: Re: How to incrementally compress jpeg?
  • Previous by thread: CoreData/NSPersistentDocument initialization
  • Next by thread: Re: [SOLVED] CoreData/NSPersistentDocument initialization
  • Index(es):
    • Date
    • Thread