• 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: Calling maincontroller
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling maincontroller


  • Subject: Re: Calling maincontroller
  • From: Hans van der Meer <email@hidden>
  • Date: Fri, 8 Oct 2010 11:44:02 +0200

On 7 okt 2010, at 22:13, Quincey Morris wrote:

> On Oct 7, 2010, at 11:58, Hans van der Meer wrote:
>
>> In my application I instantiate a MainController (the delegate having "awakeFromNib) from where all actions are dispatched. In order to send messages to the displaywindow residing in MainController, there is the problem how to find this MainController from other callers (possibly on other threads). Now it is coded as follows:
>>
>> In MainController.c:
>> static MainController *controller = nil;
>> controller = self; /* in its init method */
>> + (void) message:(NSString *)msg;
>>   { dispatch_async(dispatch_get_main_queue(), ^{[controller message:msg];});}
>> - (void) message:(NSString *)msg;
>>
>> I am not very happy with the static variable but do not see another way to accomplish this. I fear my solution is not as much in the spirit of Cocoa programming as it should be.
>> Is there a better way?
>
> If it's your application delegate, other objects can find it as [NSApp delegate] or [[NSApplication sharedAppplication] delegate].

That is exactly what I needed. My code now is:
- (void) message:(NSString *)message;
{
  dispatch_async(dispatch_get_main_queue(),
    ^{[[NSApp delegate] message:message];});
}
And this will get rid of the static variable and the class function in the MainController. It is of course a matter of which style one prefers. For me this coding most clearly expresses what goes on and shows it at exactly the point where the action is invoked.

Thanks!

Hans van der Meer

_______________________________________________

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

References: 
 >Calling maincontroller (From: Hans van der Meer <email@hidden>)
 >Re: Calling maincontroller (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: init returns nil or raises exception?
  • Next by Date: Problem using dictionary
  • Previous by thread: Re: Calling maincontroller
  • Next by thread: NSComboBox bound to NSMutableArray of NSMutableDictionary with NSArrayController?
  • Index(es):
    • Date
    • Thread