I have controller object that's trying to initialize 2 NSManagedObjects using a custom initialization method and then stick them in an array. When I debug the code, I'm actually getting 2 pointers to the same object so it seems my NSManagedObject subclass is behaving unintentionally like a singleton.
In my custom initialization method, I'm calling the designated initializer (which I haven't overridden) for the NSManagedObject, as the documentation instructs, so I'm not sure why I'm getting 2 references to the same object.
Both tClosetRootNode and tPersonRootNode are pointing to the same memory.
Here is the code that calls the custom Init method:
and here is the init method's code:
Eventually I intend to have more than just these two objects (but I'm trying to get it working first with just these).
I appreciate any help you can send my way, and I'd be happy to post the full project if you think it would help, although it's still pretty rough.
In my custom initialization method, I'm calling the designated initializer (which I haven't overridden) for the NSManagedObject, as the documentation instructs, so I'm not sure why I'm getting 2 references to the same object.
Both tClosetRootNode and tPersonRootNode are pointing to the same memory.
Here is the code that calls the custom Init method:
Code:
// from DISourceListController.m
-(void) awakeFromNib
{
//appDelegate is an iVar linked as an IBOutlet in IB. My core data stack is currently living in the appDelegate
NSManagedObjectContext *tManagedObjectContext = [appDelegate managedObjectContext]; // tManagedObjectContext appears valid when debugged
DISourceListNode *tClosetRootNode = [[DISourceListNode alloc] initWithName: @"WARDROBE"
managedObjectContext: tManagedObjectContext
childArrayController: closetArrayController];
DISourceListNode *tPersonRootNode = [[DISourceListNode alloc] initWithName: @"PEOPLE"
managedObjectContext: tManagedObjectContext
childArrayController: personArrayController];
rootNodeArray = [[NSArray alloc] initWithObjects: tClosetRootNode,
tPersonRootNode, nil];
[tClosetRootNode release];
[tPersonRootNode release];
for( DISourceListNode* tArrayItem in rootNodeArray )
{
NSLog( @"rootNodeArray item is: %s", [tArrayItem valueForKey: @"name"] );
}
[sourceList reloadData];
}
and here is the init method's code:
Code:
// from DISourceListNode.m
-(id) initWithName: (NSString *)theName managedObjectContext: theMOC childArrayController: (NSArrayController *)theArrayController
{
NSEntityDescription* tEntityDescription = [NSEntityDescription entityForName: @"DISourceListNode"
inManagedObjectContext: theMOC];
// Call the Designated initializer with the appropriate Parameters
[self initWithEntity: tEntityDescription insertIntoManagedObjectContext: theMOC];
// prep the ivars
[self setValue: YES forKey: @"isRoot"];
[self setValue: theName forKey: @"name"];
[self setChildArrayController: theArrayController];
[self createChildMArrayWithChildArrayController: theArrayController];
NSLog( @"creating DISourceListNode with name: %@", [self valueForKey: @"name"] );
return self;
}
Eventually I intend to have more than just these two objects (but I'm trying to get it working first with just these).
I appreciate any help you can send my way, and I'd be happy to post the full project if you think it would help, although it's still pretty rough.