Mantaining legacy APIs in a framework

2015-08-31 Thread Graham Cox
Hi all, a fairly general question.

Suppose I have a framework class - e.g. GCBase - that has a public method -foo: 
 Application code that links to the framework can freely subclass GCBase and 
commonly overrides -foo:

Later, I decide that the method would be much better in a different form, let’s 
call it -foo:withBar:  Code that links to the framework now should override 
this method instead. However, the framework can’t force this change on its 
clients, for a while it will need to support the older method -foo: if it has 
been overridden by a subclass. So the framework needs to arrange that if 
-foo:withBar: wasn’t overridden, but -foo: was, it should invoke the older 
override for backward compatibility until the client code is revised.

Apple’s frameworks do this quite often, but I’m not sure how to achieve this in 
my own. Something simple like -respondsToSelector: isn’t any good, because of 
course it always does respond to the selector in the base class, and the 
framework has no knowledge of subclasses beyond its own borders. Seems like I’d 
need to drop down into the runtime functions but it’s still not really obvious 
what would work. How do Apple do this?

—Graham





___

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

Re: Autolayout requiring NSDisableScreenUpdates

2015-08-31 Thread Seth Willits
> On Aug 30, 2015, at 4:09 PM, Ken Thomases  wrote:
> 
> Turn off Visible at Launch on the window in the NIB.

D'oh! You're right. I mistakenly left on that and that's what was causing it. 
Thanks!


--
Seth Willits



___

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

Re: Mantaining legacy APIs in a framework

2015-08-31 Thread Jens Alfke

> On Aug 31, 2015, at 4:09 PM, Graham Cox  wrote:
> 
> So the framework needs to arrange that if -foo:withBar: wasn’t overridden, 
> but -foo: was, it should invoke the older override for backward compatibility 
> until the client code is revised.

One way to do it is something like
@implementation BaseClass
...
if ([self methodForSelector: @selector(foo:)] != [BaseClass 
instanceMethodForSelector: @selector(foo:)]) {
// self must be an instance of a subclass that’s overridden 
-foo:.
}

—Jens
___

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

How to terminate an NSTask whenever my app terminates?

2015-08-31 Thread Jens Alfke
(I know this has come up here before, but I can’t get the right combination of 
search terms to find an answer…)

I’m writing a little GUI wrapper app around a command-line-based server. It 
uses NSTask to launch the server. I want to ensure that when the app exits, the 
server process exits too. I can tell the NSTask to terminate in my app 
delegate's -applicationWillTerminate: method, but that doesn’t handle cases 
where the app crashes or is force-quit.

IIRC there is a way to tell the kernel to terminate the child process when its 
parent process exits. But what is it, exactly?

—Jens

PS: As far as I know this is unrelated to the SIGHUP mechanism by which shells 
kill their child processes when they exit; that relies on having a TTY attached 
to the subprocess.
___

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

Re: How to terminate an NSTask whenever my app terminates?

2015-08-31 Thread Doug Hill
Hey Jens,

I ran across this:

Monitoring a Process with a dispatch source 


"A process dispatch source lets you monitor the behavior of a specific process 
and respond appropriately. A parent process might use this type of dispatch 
source to monitor any child processes it creates. For example, the parent 
process could use it to watch for the death of a child process. Similarly, a 
child process could use it to monitor its parent process and exit if the parent 
process exits."

Good luck!

Doug Hill
http://chartcube.com/ 


> On Aug 31, 2015, at 4:32 PM, Jens Alfke  wrote:
> 
> (I know this has come up here before, but I can’t get the right combination 
> of search terms to find an answer…)
> 
> I’m writing a little GUI wrapper app around a command-line-based server. It 
> uses NSTask to launch the server. I want to ensure that when the app exits, 
> the server process exits too. I can tell the NSTask to terminate in my app 
> delegate's -applicationWillTerminate: method, but that doesn’t handle cases 
> where the app crashes or is force-quit.
> 
> IIRC there is a way to tell the kernel to terminate the child process when 
> its parent process exits. But what is it, exactly?
> 
> —Jens
> 
> PS: As far as I know this is unrelated to the SIGHUP mechanism by which 
> shells kill their child processes when they exit; that relies on having a TTY 
> attached to the subprocess.

___

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

NSTableView: Rows from bottom up

2015-08-31 Thread Eric Gorr
Normally when one adds the first row to a NSTableView, it will appear at the 
top of the view and additional rows will appear below it. Is it possible to 
have the first row appear at the bottom of the NSTableView and for new rows to 
appear above it?

No doubt this would require some extensive customization. I am open to 
alternative solutions, but the one invariant will remain…first row at the 
bottom and additional rows appearing above.

I could fake it by creating a large enough number of rows so the view is filled 
and setting the scroll position to the bottom, but I find that to be a bit 
inelegant…although, I would go that route before doing something completely 
custom.

If you are wondering why someone might need such a thing, consider the case of 
a calculator where the most common way to view the numbers (at least for RPN 
entry) is for the most recent entry or calculation is to appear at the bottom 
and previous entries to appear above it.



___

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

Re: NSTableView: Rows from bottom up

2015-08-31 Thread Keary Suska
On Aug 31, 2015, at 7:51 PM, Eric Gorr  wrote:
> 
> Normally when one adds the first row to a NSTableView, it will appear at the 
> top of the view and additional rows will appear below it. Is it possible to 
> have the first row appear at the bottom of the NSTableView and for new rows 
> to appear above it?
> 
> No doubt this would require some extensive customization. I am open to 
> alternative solutions, but the one invariant will remain…first row at the 
> bottom and additional rows appearing above.
> 
> I could fake it by creating a large enough number of rows so the view is 
> filled and setting the scroll position to the bottom, but I find that to be a 
> bit inelegant…although, I would go that route before doing something 
> completely custom.
> 
> If you are wondering why someone might need such a thing, consider the case 
> of a calculator where the most common way to view the numbers (at least for 
> RPN entry) is for the most recent entry or calculation is to appear at the 
> bottom and previous entries to appear above it.

Unless something changed before I used it last, the insert location will depend 
on how you add an object, i.e. -add: vs -insert:, as well as any sorting 
settings. Using -add: should always append to the end of the collection as long 
as it is unsorted or does not re-sort automatically. If you use your own method 
to add new objects, you can do whatever you want. No need to customize much.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


___

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

Re: How to terminate an NSTask whenever my app terminates?

2015-08-31 Thread Scott Ribe
Normally, when a parent exits, all child processes are killed. This is not 
specific to terminal/tty sessions. However, a process can be detached from its 
parent so that it will survive the parent's exit. I doubt that NSTask does 
this, but you should verify.

Create a dummy helper: int main() {while(1) sleep(1);}

Use NSTask to launch it. Kill your parent in various ways and verify that the 
child gets killed: kill -9, call abort, crash it with the time-honored 
*(char*)0 = 0.

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice






___

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

Re: How to terminate an NSTask whenever my app terminates?

2015-08-31 Thread Michael David Crawford
On the UNIX command line "nohup" prevents children from being killed when
the parent exits.  If you want to manually start a daemon:

   $ nohup mydaemon &

Then you can log out and it keeps running.


-- 
Michael David Crawford P.E., Consulting Process Architect
mdcrawf...@gmail.com
http://mike.soggywizard.com/

  One Must Not Trifle With Wizards For It Makes Us Soggy And Hard To
Light.
___

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

Re: How to terminate an NSTask whenever my app terminates?

2015-08-31 Thread Ken Thomases
On Aug 31, 2015, at 9:50 PM, Scott Ribe  wrote:
> 
> Normally, when a parent exits, all child processes are killed.

This is not true.

> This is not specific to terminal/tty sessions.

Yes, it is.

Try the following program.  The parent will print the child's PID and exit (by 
falling out of main()).  Then do a "ps xww -p ".  You'll see the 
child is still running.  You can kill it when satisfied.

Nothing special was done to detach the child from the parent and nothing need 
be done.

Regards,
Ken

#include 
#include 
#include 
#include 


int main(void)
{
int child = fork();
if (child == -1)
{
perror("fork");
exit(EXIT_FAILURE);
}
else if (child == 0)
{
// in child
printf("sleeping...\n");
while (1) sleep(1);
}
else
{
// in parent
printf("child %d\n", child);
}

return 0;
}


___

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

Re: How to terminate an NSTask whenever my app terminates?

2015-08-31 Thread Bavarious

> On Aug 31, 2015, at 20:32, Jens Alfke  wrote:
> 
> (I know this has come up here before, but I can’t get the right combination 
> of search terms to find an answer…)
> 
> I’m writing a little GUI wrapper app around a command-line-based server. It 
> uses NSTask to launch the server. I want to ensure that when the app exits, 
> the server process exits too. I can tell the NSTask to terminate in my app 
> delegate's -applicationWillTerminate: method, but that doesn’t handle cases 
> where the app crashes or is force-quit.
> 
> IIRC there is a way to tell the kernel to terminate the child process when 
> its parent process exits. But what is it, exactly?

There was a 2010 cocoa-dev thread about this:
http://www.lists.apple.com/archives/cocoa-dev/2010/Aug/msg00512.html

Same thread, single page with all posts:
http://www.cocoabuilder.com/archive/cocoa/291918-how-to-assure-nstask-termination-when-parent-dies.html


___

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