Re: How do you copy a NSManagedObjectContext
Re: How do you copy a NSManagedObjectContext
- Subject: Re: How do you copy a NSManagedObjectContext
- From: Martin van-Eerde <email@hidden>
- Date: Thu, 8 Feb 2007 20:37:57 +0000
I Guess I made a another classic newbie mistake. I had already
dragged the second classes header file into IB and created a instance
of the class as well as creating a second instance in the AppDelegate...
Which I guess leads me to another question, I am creating a single
window app, the window has a toolbar and 5 tabs which the toolbar
selects. Each tab displays data from a different CoreData entity.
I don't want one large AppDelegate file, so for the first tab as a
learning exercise I created a category which worked great, for the
second I have created a "helper class" which is the one I was having
trouble with. I have now created a IBOutlet in AppDelegate for the
helper class which is instantiated in the nib and linked the two.
Which is the preferred way of splitting up code to control multiple
tabs/windows discrete units of works, categories, or delegates/helper
classes, if it is helper classes should they be instantiated in the
nib or in the AppDelegate and data manually bound to controls?
Note to self, stop calling pointers references (sorry it's my Java
background) ;-(
Thanks Martin
On 8 Feb 2007, at 20:01, email@hidden wrote:
I have my single window core data application which has all the
managed object template code. I want a second class to do some of
the persisting for certain objects but am having trouble passing the
reference of the managed object context to the second class.
I have for a init method of the second class:
-(id)initWithManagedObjectContext:(NSManagedObjectContext *)moContext
{
self = [super init];
moCopy = moContext;
[moCopy retain];
}
And from the application delegate in the awakeFromNib:
[[OtherClass alloc] initWithManagedObjectContext:[self
managedObjectContext]];
moCopy in the subclass gets a reference in the init method but it
appears to go out of scope as soon as the init method returns as when
I come to use moCopy in another method later it is set to 0x0
In fact I seem to be unable to retain any references passed from
AppDelegate to another class, for instance in the other classes
interface if have
id refToAppDelegate;
and call [otherClass setRefToAppDelegate:self] - A reference is
passed in and copied to refToAppDelegate, but again the pointer? gets
set to 0x0 as soon as the method is exited.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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