Gang,

In my fighting with services, I'm trying a different approach and hence
have a different question - is there a way that I could craft a service
that reads in selected text, uses that to open and perform a web
connection, and then returns that data back to the calling app?

The trivially silly example I have would be a service that looks up the
definition of a word and pastes the definition in place. So I might select
the word "apple" and invoke my service, and it goes off and searches the
web or my central server or something and pastes back into place "An
awesome computer company and/or fruit". No, I don't know why anyone would
want such a service, this is just to illustrate the concept.

The issue is that my -doWebStuff:userData:error: method seems to only let
me write to the pasteboard during the invocation of that method, and once
it completes I'm done. NSURLConnection is all delegate based, so I wouldn't
have the results of my lookup until the secondary thread completes and my
delegate realizes its done loading the data. By that point, the doWebStuff
method is long since completed and I'm stuck w/o results.

I can see a few different hypothetical ways to make this work:
(a) somehow block the main thread until the secondary threads come back.
I'm not sure this'd work since the delegate method would be invoked on the
main thread, which I'm currently blocking.

(b) Somehow update the pasteboard after the service method finished?

(c) Somehow defer my way out of the method to do something else, then hop
back in when I'm done? Something like the concept of a promise in
javascript. I'm grasping at straws here.

(d) Might NSOperationQueue be magical enough to allow something like this?


I'm stumped. For now, I think this just gets filed under "Can't be done"
since by everything I can tell I have to do all work in a service in that
single invocation of the single method in the single thread, and anything
that'd cause me to hop out of there kills the concept.

Does anybody have a method to do this? Or is it just not possible?

Many thanks,

-Jim.....
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to