• 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: Core Data Based Application Bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data Based Application Bug?


  • Subject: Re: Core Data Based Application Bug?
  • From: Charilaos Skiadas <email@hidden>
  • Date: Fri, 5 Aug 2005 00:49:24 -0500


On Aug 5, 2005, at 12:37 AM, Colin Cornaby wrote:

Hey,

I'm trying to rig up some code to only run when a new document is opened in my Core Data based Application. It is my understanding that I can simply override the init method within the NSPersistantDocument instnace to add code for when a new untitled document is created. However, this code is being run every time a new document is opened in addition to a new document being created. Here is the code:

//  MyDocument.m
//  Catalyst
//
//  Created by Colin Cornaby on 7/28/05.
//  Copyright __MyCompanyName__ 2005 . All rights reserved.

#import "MyDocument.h"
#import <ThemeKit/TKTheme.h>

@implementation MyDocument

- (id)init
{
self = [super init];
if (self != nil) {
//Initialize the theme for the document. A TKTheme is a NSManagedObjectContext subclass
//so we can directly interface to CoreData. We can also set the TKTheme as this persistent
//document's object context.
TKTheme *documentTheme = [[TKTheme alloc] init];
[documentTheme addVariation:@"Untitled Variation"];
[self setManagedObjectContext:documentTheme];
}
return self;
}


- (NSString *)windowNibName
{
    return @"MyDocument";
}

- (void)windowControllerDidLoadNib:(NSWindowController *) windowController
{
[super windowControllerDidLoadNib:windowController];
// user interface preparation code
}


@end

However, the addVariation method is being called every time a document is opened, as a new variation adds itself to the list of variations any time?

When I did a document based app before I think the init method worked as the documentation states, running only when an "Untitled" document is opened. Do I go about this a different way in a Core Data Based Application, or is this actually a bug?

Maybe this is relevant, from the NSPersistentDocument tutorial:
http://developer.apple.com/documentation/Cocoa/Conceptual/ NSPersistentDocumentTutorial/index.html#//apple_ref/doc/uid/TP40001799


" NSDocument provides a method—initWithType:error:—that is called only when a new document is created, not when it is subsequently reopened. You can therefore create the Department object in this method, and be assured that when a document is reopened a new Department object will not be created."


--------------------------- Colin Cornaby - http://gomac.blogspot.com/ Carpe Stellarem - Lead Programmer, ProToys - http://carpestellarem.com Macintosh Specialist - University of Portland - htttp://up.edu


Haris


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Core Data Based Application Bug? (From: Colin Cornaby <email@hidden>)

  • Prev by Date: Core Data Based Application Bug?
  • Next by Date: Subclassing cells?
  • Previous by thread: Core Data Based Application Bug?
  • Next by thread: Re: Core Data Based Application Bug?
  • Index(es):
    • Date
    • Thread