Re: Proper way to retain member of AppDelegate?
Re: Proper way to retain member of AppDelegate?
- Subject: Re: Proper way to retain member of AppDelegate?
- From: Alex Zavatone <email@hidden>
- Date: Wed, 15 Oct 2014 17:20:01 -0400
You mit want to check out singleton creation if you want to access at data object from multiple objects.
Just google for Matt Galloway singleton and the first link should show you what you need.
This is geared for iOS but I suspect it should work fine if you are targeting the Mac as well.
Cheers.
Sent from my iPad. Please pardon typos.
On Oct 15, 2014, at 4:42 PM, Howard Moon <email@hidden> wrote:
> Hi,
>
> I'm working on my first ARC-enabled app, but am having a problem with how to keep my delegate's member data alive.
>
> At startup (in the delegate's applicationDidFinishLaunching: function), my delegate initializes a data object (a member of the delegate) containing some NSString members. Those strings are populated via a call to a helper class that is also a member of the delegate. That helper class call initiates an asynchronous set of actions (HTTP), then returns immediately back to the delegate. After returning from that call, the delegate's applicationDidFinishLaunching: function simply drops out the bottom.
>
> When the helper class finishes populating the data from the asynchronous HTTP call, it responds with a callback into the delegate. The delegate's callback function responds by showing the main window and populating some text fields and buttons according to the strings in the data object. The callback function then drops out the bottom. The dialog shows the correct information, meaning that at THAT point in time, the data object was still valid.
>
> My problem comes later, when the user clicks on one of the buttons, which calls an action in the delegate. At this point, I try to extract one of the strings from the data object (to launch a browser with the given URL string), and it gives me an access violation. Apparently, my data object has been deleted. That is strange, since it is a member of the delegate.
>
> I was under the impression that my design was correct, in that member objects of the delegate should be initialized in the applicationDidFinishLoading: function, right? So why does the object get deleted while my delegate still exists? More importantly, how do I keep that member data object alive so that my delegate's actions can access it?
>
> Thanks,
> Howard
>
>
>
>
>
>
> _______________________________________________
>
> 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
_______________________________________________
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