Re: Won't Applescript command use defined ivars?
Re: Won't Applescript command use defined ivars?
- Subject: Re: Won't Applescript command use defined ivars?
- From: Chris Paveglio <email@hidden>
- Date: Thu, 01 Sep 2011 06:36:40 -0700 (PDT)
Scott and Martin, thanks. I did not understand that NSScriptCommand made a new instance of itself each time it was called. Now it makes sense what was going on. I will try to use Scott's suggestion of a singleton or static for the connection object, and of course break things into different classes now.
Chris
----- Original Message -----
From: Martin Wierschin <email@hidden>
To: Chris Paveglio <email@hidden>
Cc: Cocoa Dev List <email@hidden>
Sent: Wednesday, August 31, 2011 7:47 PM
Subject: Re: Won't Applescript command use defined ivars?
> But I am going to need the application to use the instance of the class from when it's started, not make a new instance every time the script command is given.
As Scott mentioned, that's not how the Cocoa framework works with regard to AppleScript. It's going to create a new instance of your command subclass every time; don't try and fight that.
It's a structural problem, but one that's easily overcome by splitting apart your AppleScript and database logic, which you should probably be doing anyways. Similarly, your application delegate should not be your NSScriptCommand subclass.
> -(void)applicationDidFinishLaunching:(NSNotification *)aNotification
> {
> userName = NSUserName(); //I also may have tried to retain it but no difference in outcome when Applescript calls the method
> theConnection = [[ODBCConnection alloc] init];
Retaining the ivar might not make a difference now, but you really need to understand and implement the Cocoa memory management guidelines. Carelessly ignoring the rules because they don't make a difference during testing is dangerous and will cause you heartache and lost time later. Also, because your subclass doesn't implement a dealloc method, you're leaking that connection object.
I can't stress enough that it's imperative you understand the memory management rules.
~Martin
_______________________________________________
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