Re: stopping an application

2009-04-13 Thread Andrew Farmer

On 12 Apr 09, at 23:55, Arjun SM wrote:

Use the 'do shell script' command
do shell script kill -9 PID
That should work.


No, actually, don't do that.

We are discussing Cocoa programming here. Running an Applescript that  
executes a shell script command that wraps a system call is an  
incredibly inefficient approach to the problem. (The correct way to do  
this would be using the kill() syscall... but keep reading.)


In any case, that's a terrible way to quit an application. If the  
application has any files open, it'll quit without getting a chance to  
save them properly - in particular, it won't prompt the user to save  
changes, which is a really fast path to making the user angry at your  
program.

___

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

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


Re: How to create an ISO disc image

2009-04-13 Thread Charles Srstka

On Apr 12, 2009, at 6:37 PM, David wrote:


How can I create an ISO disc image.
Can the disc recording framework do it?
What about the DiskImages framework?
I can't find an API for it.


I think the only way to do that is to use NSTask to launch /usr/bin/ 
hdiutil with the appropriate arguments.


Charles
___

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

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


static vs non-static. Recommendation needed.

2009-04-13 Thread Тимофей Даньшин

Hello.
A foreword:
In my application I need to allow the user to create a database. So i  
display a dialogue panel, collect all the necessary information about  
the db to be created and create a "DatabaseInfo" object. Then i pass  
that DatabaseInfo object to the DatabaseCreator to actually create the  
needed database. I want the DatabaseCreator to "return" an sqlite3  
pointer.


And here is my dilemma:
As i don't need that DatabaseCreator to exist for a long time i  
thought it better to make it completely static. Sorry if the  
terminology is wrong, but what i mean is: it cannot be initialized, it  
has no instance variables, it has no instance methods, all it has is  
one public class method: + (sqlite3 *) createDbaseWithDatabaseInfo:  
(DatabaseInfo *) dbInfo;


However, that proves not very convenient, as i need to break up the  
logic of that class into individual steps and I end up passing a lot  
of things from one method to another.


Is it all right to init an object just to dealloc it in the next line  
(or create an autorelease object using a convenience method for that  
matter)? I mean, if i made it non-static, i would have something like  
this in the class that uses it:


DatabaseCreator *dbc = [DatabaseCreator creatorWithDBInfo: dbInfo];
sqlite3* database = [dbc database];  // and dbc would no longer be used.

Or is it better to put up with the inconveniences of having that thing  
static?


Thank you in advance,
Timofey.



___

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

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


Re: How to open two nibs at app launch ? Beginners question

2009-04-13 Thread Mario Kušnjer


On 2009.04.13, at 05:40, Quincey Morris wrote:


It's not wrong at all. Separate nibs are the recommended way of  
doing this.


You may just need to tell your window controller to display its  
window. Trying adding:


[myWindowController showWindow: nil];

after you've initialized your window controller.

Incidentally, in a non-document-based application (as your appears  
to be), a good place to put code to create your window controller  
would be in your application delegate's  
applicationDidFinishLaunching: method. You say you created a window  
controller. Where *did* you put that code?


Well I did a subclass of NSWindowController in separate file  
MainWindowController.


But I actually don't understand those application delegate's concept.
How do I make something to delegate to something else (did I even get  
that right ?) ?


Application delegate would be (in my case) an object added in  
MainMenu.nib that would have MainWindowController class set to it ?
And MainWindow.nib File's Owner is also set to MainWindowController,  
right ?
That would be the connection between MainWindow.nib file and the code  
to instantiate my window controller.

I'm not sure I doing it right !

So I should put applicationDidFinishLaunching (that would be  
instance ?) method  in MainWindowController class and inside  
instantiate my window controller ?


Thanks for answering !

Mario 
___


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

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


Re: static vs non-static. Recommendation needed.

2009-04-13 Thread Dave Keck
> Is it all right to init an object just to dealloc it in the next line (or
> create an autorelease object using a convenience method for that matter)? I
> mean, if i made it non-static, i would have something like this in the class
> that uses it:
>
> DatabaseCreator *dbc = [DatabaseCreator creatorWithDBInfo: dbInfo];
> sqlite3* database = [dbc database];  // and dbc would no longer be used.
>
> Or is it better to put up with the inconveniences of having that thing
> static?

In general, there's no good or bad way to do such things, it really
depends on context. Your instantiation method that you mentioned is
fine - but personally, I would go the static route for this situation
because, conceptually, there's no reason to instantiate a database
creator, as you mentioned.

One solution to help alleviate the hassle of passing 10 different
variables between your DatabaseCreator's class methods is to create a
struct that wraps all your variables that you're sending from class
method to class method, and simply pass a pointer to the struct
between them. This solution is simple and clean. There's no need to
expose this struct in your public interface, of course, as you can
just deal with it internally by declaring it in your .m file.

Another solution is to create static variables within
DatabaseCreator.m. I can't say I like this way of doing things, but I
suppose it's a solution nonetheless. (If you're not familiar with
static variables, check 'em out on Google.) Each helper method inside
your DatabaseCreator class would simply use the static variables
declared in the .m file to get the job done.

David
___

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

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


Re: [SOLVED ] NSPredicateEditorTemplateRow , pop up with Core Data objects

2009-04-13 Thread Dan Waltin

mmalc and Daniel Vollmer: thank you very much for your replies!

I still haven't got the IBOutlet NSArrayController stuff to work, but  
I have solved my original problem:  i.e. to populate the Core Data  
objects popup.


I'm using a fetch predicate, quite straight forward.

Kind regards
Dan Waltin
___

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

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


Re: How to open two nibs at app launch ? Beginners question

2009-04-13 Thread Quincey Morris

On Apr 13, 2009, at 01:14, Mario Kušnjer wrote:


But I actually don't understand those application delegate's concept.
How do I make something to delegate to something else (did I even  
get that right ?) ?


Application delegate would be (in my case) an object added in  
MainMenu.nib that would have MainWindowController class set to it ?
And MainWindow.nib File's Owner is also set to MainWindowController,  
right ?
That would be the connection between MainWindow.nib file and the  
code to instantiate my window controller.

I'm not sure I doing it right !

So I should put applicationDidFinishLaunching (that would be  
instance ?) method  in MainWindowController class and inside  
instantiate my window controller ?


Not exactly. Make your application delegate (let's say its class is  
MyAppDelegate) separate from your window controller. So, the steps are:


-- write a MyAppDelegate class (subclass of NSObject)

-- in IB, drag an object into MainMenu.xib, and set its class to  
MyAppDelegate (that causes an instance to be created automatically  
when your app starts up)


-- in IB, connect the 'delegate' outlet of the (predefined)  
Application object in MainMenu.xib to the MyAppDelegate object (that  
causes your MyAppDelegate object to actually *be* the application's  
delegate)


-- in your MyAppDelegate class, add an instance variable  
mainWindowController, of class MainWindowController


-- in your MyAppDelegate class, write an  
applicationDidFinishLaunching: method something like this:


	- (void) applicationDidFinishLaunching: (NSNotification *)  
aNotification {

mainWindowController = [[MainWindowController alloc] init];
[mainWindowController showWindow: nil];
}

-- your MainWindowController's init method should look something like  
this:


- (id) init {
self = [super initWithWindowNibName: @"MainWindow"];
if (!self) ...
...
return self;
}

-- in IB, set the class of File's Owner in MainWindow.xib to  
MainWindowController


I may have left out something, but that's the basic idea.


___

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

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


Re: static vs non-static. Recommendation needed.

2009-04-13 Thread Quincey Morris

On Apr 13, 2009, at 01:13, Тимофей Даньшин wrote:

As i don't need that DatabaseCreator to exist for a long time i  
thought it better to make it completely static. Sorry if the  
terminology is wrong, but what i mean is: it cannot be initialized,  
it has no instance variables, it has no instance methods, all it has  
is one public class method: + (sqlite3 *)  
createDbaseWithDatabaseInfo: (DatabaseInfo *) dbInfo;


However, that proves not very convenient, as i need to break up the  
logic of that class into individual steps and I end up passing a lot  
of things from one method to another.


Is it all right to init an object just to dealloc it in the next  
line (or create an autorelease object using a convenience method for  
that matter)? I mean, if i made it non-static, i would have  
something like this in the class that uses it:


DatabaseCreator *dbc = [DatabaseCreator creatorWithDBInfo: dbInfo];
sqlite3* database = [dbc database];  // and dbc would no longer be  
used.


Or is it better to put up with the inconveniences of having that  
thing static?


You can have the best of both worlds. Your DatabaseCreator class can  
have a *public* interface with just a single class method:


+ (sqlite3 *) createDbaseWithDatabaseInfo: (DatabaseInfo *) dbInfo;

but that doesn't prevent the class method from *privately* creating an  
object and disposing of it before returning:


+ (sqlite3 *) createDbaseWithDatabaseInfo: (DatabaseInfo *) dbInfo {
DatabaseCreator *dbc = [DatabaseCreator creatorWithDBInfo: 
dbInfo];
return [dbc database];  // and dbc would no longer be used.
}

Important: If you're *not* using garbage collection, make sure you  
retain the database object appropriately and release dbc appropriately  
before returning.



___

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

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


Re: stopping an application

2009-04-13 Thread Luca C.
2009/4/13 Bill Janssen 
>
>
> I was afraid of that...  Is there an easy way to do that from the
> command line given its PID?


Using an AppleEvent given the appropriate bundle id of the application is
actually pretty easy.I have found this in one my quite old project:

+ (OSStatus)quitApplicationWithBundleID:(NSString *)aBundleID {

  OSStatus err;

  AppleEvent event, reply;

  const char *bundleIDString;



  bundleIDCString = [aBundleID UTF8String];



  err = AEBuildAppleEvent(kCoreEventClass, kAEQuitApplication,
typeApplicationBundleID,

  bundleIDCString, strlen(bundleIDCString),
kAutoGenerateReturnID,

  kAnyTransactionID, &event, NULL, "");



  if (err == noErr) {

err = AESendMessage(&event, &reply, kAENoReply, kAEDefaultTimeout);

AEDisposeDesc(&event);

  }

  return err;

}


Haven't tested with Leopard yet, but I'm sure it works there.


HTH

--Luca C.
___

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

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


Re: How to open two nibs at app launch ? Beginners question

2009-04-13 Thread Mario Kušnjer


On 2009.04.13, at 11:15, Quincey Morris wrote:


Not exactly. Make your application delegate (let's say its class is  
MyAppDelegate) separate from your window controller. So, the steps  
are:


-- write a MyAppDelegate class (subclass of NSObject)

-- in IB, drag an object into MainMenu.xib, and set its class to  
MyAppDelegate (that causes an instance to be created automatically  
when your app starts up)


-- in IB, connect the 'delegate' outlet of the (predefined)  
Application object in MainMenu.xib to the MyAppDelegate object (that  
causes your MyAppDelegate object to actually *be* the application's  
delegate)


-- in your MyAppDelegate class, add an instance variable  
mainWindowController, of class MainWindowController


-- in your MyAppDelegate class, write an  
applicationDidFinishLaunching: method something like this:


	- (void) applicationDidFinishLaunching: (NSNotification *)  
aNotification {

mainWindowController = [[MainWindowController alloc] init];
[mainWindowController showWindow: nil];
}

-- your MainWindowController's init method should look something  
like this:


- (id) init {
self = [super initWithWindowNibName: @"MainWindow"];
if (!self) ...
...
return self;
}

-- in IB, set the class of File's Owner in MainWindow.xib to  
MainWindowController


I may have left out something, but that's the basic idea.


It's working !
Thank you!

Tell me please should and in what cases would I keep MyAppDelegate  
separate from MainWindowController and in what not, because I kinda  
made it work all from one place:


#import 


@interface MainWindowController : NSObject
{
NSWindowController *mainWindowController;
}

@end


#import "MainWindowController.h"


@implementation MainWindowController

- (void) applicationDidFinishLaunching:(NSNotification *) aNotification
{
	mainWindowController = [[NSWindowController alloc]  
initWithWindowNibName:@"MainWindow"];

[mainWindowController showWindow:nil];
}

@end

And about delegates, so if I want to do something else now I have to  
create another object in MainMenu.nib and make it a delegate of proxy  
object Application again ?

There can be multiple delegations for one Application object ?
Or should I make one object that will be a delegate but will hold the  
code for all other stuff ?

Could you explain this to me a little bit more ?

Thanks !

Mario

___

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

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


Re: static vs non-static. Recommendation needed.

2009-04-13 Thread Gregory Weston

ok5.admin wrote:


Hello.
A foreword:
In my application I need to allow the user to create a database. So i
display a dialogue panel, collect all the necessary information about
the db to be created and create a "DatabaseInfo" object. Then i pass
that DatabaseInfo object to the DatabaseCreator to actually create the
needed database. I want the DatabaseCreator to "return" an sqlite3
pointer.

...

Is it all right to init an object just to dealloc it in the next line
(or create an autorelease object using a convenience method for that
matter)? I mean, if i made it non-static, i would have something like
this in the class that uses it:

DatabaseCreator *dbc = [DatabaseCreator creatorWithDBInfo: dbInfo];
sqlite3* database = [dbc database];  // and dbc would no longer be  
used.


Or is it better to put up with the inconveniences of having that thing
static?


It's better to follow the practice that you'll find most maintainable.

But I might suggest you've omitted a couple of options. Would it be,  
for example, particularly evil if your DatabaseInfo object include a  
createDatabase method?

___

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

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


Re: static vs non-static. Recommendation needed.

2009-04-13 Thread Тимофей Даньшин
But I might suggest you've omitted a couple of options. Would it be,  
for example, particularly evil if your DatabaseInfo object include a  
createDatabase method?


Well, not exactly, i suppose. The point is that i create DatabaseInfo  
either before creating a new database or after opening an existing  
one. In both cases the object is used to show the user some general  
information about the currently open db, and in the former case, it is  
also used to actually create the database.

I think i'll stick to Quincey Morris's suggestion.

And again thank you all for the help.
Timofey.


On Apr 13, 2009, at 3:59 PM, Gregory Weston wrote:


ok5.admin wrote:


Hello.
A foreword:
In my application I need to allow the user to create a database. So i
display a dialogue panel, collect all the necessary information about
the db to be created and create a "DatabaseInfo" object. Then i pass
that DatabaseInfo object to the DatabaseCreator to actually create  
the

needed database. I want the DatabaseCreator to "return" an sqlite3
pointer.

...

Is it all right to init an object just to dealloc it in the next line
(or create an autorelease object using a convenience method for that
matter)? I mean, if i made it non-static, i would have something like
this in the class that uses it:

DatabaseCreator *dbc = [DatabaseCreator creatorWithDBInfo: dbInfo];
sqlite3* database = [dbc database];  // and dbc would no longer be  
used.


Or is it better to put up with the inconveniences of having that  
thing

static?


It's better to follow the practice that you'll find most maintainable.

But I might suggest you've omitted a couple of options. Would it be,  
for example, particularly evil if your DatabaseInfo object include a  
createDatabase method?

___

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:
http://lists.apple.com/mailman/options/cocoa-dev/ok5.admin%40gmail.com

This email sent to ok5.ad...@gmail.com


___

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

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


Exit an Application

2009-04-13 Thread Luca Ciciriello

Hi All.
I Know this, may be, is the most stupid question on this list by I'm  
pretty new using cocoa (I'm a C++ developer).
I've created an application with a button "Exit" and I've connected it  
with the method:


- (IBAction)exitApp:(id)sender
{
// TODO
}

Now my question is: "Which call I have to do to quit my application  
instead of // TODO?"

Is there a NSsomething to call?

Thanks in advance for any help.

Luca.

P.S.
I know you can answer me to read some manual before post these  
questions, but I've to release this app to my boss in less than an  
hour. Sorry.


___

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

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


Re: Exit an Application

2009-04-13 Thread Luca C.
[[NSApplication sharedApplication] terminate:self];
2009/4/13 Luca Ciciriello 

> Hi All.
> I Know this, may be, is the most stupid question on this list by I'm pretty
> new using cocoa (I'm a C++ developer).
> I've created an application with a button "Exit" and I've connected it with
> the method:
>
> - (IBAction)exitApp:(id)sender
> {
>// TODO
> }
>
> Now my question is: "Which call I have to do to quit my application instead
> of // TODO?"
> Is there a NSsomething to call?


-- 
--Luca C.
___

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

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


Re: Exit an Application

2009-04-13 Thread Filip van der Meeren

You could always call exit(); from C
or [NSApp terminate:XXX];

Filip van der Meeren
fi...@code2develop.com
http://sourceforge.net/projects/xlinterpreter

On 13 Apr 2009, at 16:13, Luca Ciciriello wrote:


Hi All.
I Know this, may be, is the most stupid question on this list by I'm  
pretty new using cocoa (I'm a C++ developer).
I've created an application with a button "Exit" and I've connected  
it with the method:


- (IBAction)exitApp:(id)sender
{
// TODO
}

Now my question is: "Which call I have to do to quit my application  
instead of // TODO?"

Is there a NSsomething to call?

Thanks in advance for any help.

Luca.

P.S.
I know you can answer me to read some manual before post these  
questions, but I've to release this app to my boss in less than an  
hour. Sorry.


___

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:
http://lists.apple.com/mailman/options/cocoa-dev/filip%40code2develop.com

This email sent to fi...@code2develop.com




___

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

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


Re: Exit an Application

2009-04-13 Thread Filip van der Meeren

You could always call exit(); from C
or [NSApp terminate:XXX];

Filip van der Meeren
fi...@code2develop.com
http://sourceforge.net/projects/xlinterpreter


On 13 Apr 2009, at 16:13, Luca Ciciriello wrote:


Hi All.
I Know this, may be, is the most stupid question on this list by I'm  
pretty new using cocoa (I'm a C++ developer).
I've created an application with a button "Exit" and I've connected  
it with the method:


- (IBAction)exitApp:(id)sender
{
// TODO
}

Now my question is: "Which call I have to do to quit my application  
instead of // TODO?"

Is there a NSsomething to call?

Thanks in advance for any help.

Luca.

P.S.
I know you can answer me to read some manual before post these  
questions, but I've to release this app to my boss in less than an  
hour. Sorry.


___

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:
http://lists.apple.com/mailman/options/cocoa-dev/filip%40code2develop.com

This email sent to fi...@code2develop.com



___

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

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


Need to find out why I get Cocoa error 256 . . .

2009-04-13 Thread Michael A. Crawford
Where can I find detail on the following error code?  Or, can someone  
point me to information on how to effectively debug a failure for a  
CoreData -[NSManagedObjectContext save] invocation?


2009-04-13 10:17:28.625 SpecialOrders[4923:20b] Failed to save context  
with new data: Error Domain=NSCocoaErrorDomain Code=256  
UserInfo=0xf4b150 "Operation could not be completed. (Cocoa error 256.)"


-Michael

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

Re: Exit an Application

2009-04-13 Thread Luca Ciciriello
Thanks to everybody. You saved my life I'v released the application to  
my Boss just in time.


Bye.

Luca.

___

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

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


Re: NSDocument reference held by NSSavePanel?

2009-04-13 Thread Michael Ash
On Sun, Apr 12, 2009 at 11:33 PM, Quincey Morris
 wrote:
> Here's something strange. I have a NSDocument-based GC app whose data model
> contains an object that uses a resource. (The resource is actually exclusive
> access to a MMC-controlled device, but that's not really relevant.) The
> object has a finalize method in which the resource is released.

The answer here is simple: don't do this.

Even if all of your references get cleared, you have no guarantee that
-finalize will be called in any sort of timely fashion. Garbage
collection is not deterministic. Usually your object will be finalized
within some seconds of having the last strong reference to it go away.
Can you really withstand having that exclusive resource be occupied
for seconds after your document closes? If the GC decides not to
collect that object for a much longer period of time, say, six years,
which it is perfectly within its rights to do, does that work for you?

-finalize should do two things. First, it should clean up any memory
allocations that aren't managed by the collector, like malloc blocks.
Second, it should clean up non-memory resources *as a fail-safe*. It
should close file descriptors, release shared locks, what have you,
but only to ensure that they weren't forgotten. Any object which holds
an external resource like this should have an explicit invalidation
method to release it in a timely fashion, because the collector may
not be timely at all.

> This all works most of the time. The object is created (and therefore
> acquires its resource) when a new document is being created, or when an
> existing document is being opened. When the document window is closed,
> everything gets garbage collected, the finalize method is called, and the
> resource is released.
>
> However, if I close the document window after using the Save As dialog
> (either for the initial save of a new document, or for a save-as of an
> existing document), the resource is NOT released, because the finalize
> method isn't being called, because there's still a reference to that object.
>
> Here's what the debugger says about that reference:
[snip]

Looks like a bug to me. If you can get multiple such documents to leak
then even more so. One at a time, that's not a big problem, but it
still seems like Cocoa ought to be cleaning this stuff up. Still, fix
the dependency on -finalize as I discussed above, and you won't have
to worry about it (much).

Mike
___

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

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


Re: Best way to pass large objects between tasks?

2009-04-13 Thread Michael Ash
On Mon, Apr 13, 2009 at 2:09 AM, Oleg Krupnov  wrote:
> I need to pass objects from one task (child) to another (parent) on
> the same machine.
>
> Currently I am considering two alternatives: Pipes vs Distributed
> Objects, and my main concern is performance, because the object is
> really large.
>
> With pipes, I need to serialize (archive) the object into NSData
> before transmitting, and deserialize (unarchive) back on reception.
> This is going to be very time-taking.
>
> My questions are:
>
> 1) Are DO going to be faster? Do DO also perform implicit
> archiving/unarchiving of passed objects to/from NSData?

DO will serialize certain objects, generally Cocoa collection classes
and things like NSData/NSString. Otherwise it will proxy objects
unless you specifically tell it otherwise. (It *can't* serialize your
custom objects without you telling it that it's ok.)

As for whether it's faster, that depends entirely on what you're
doing. If you're passing a lot of data which will be copied then DO
will be slower, because it just adds overhead. If you're passing a
large tree of proxied objects which will only be lightly queried on
the other side, DO will be faster because it's just going to send
lightweight proxies on demand.

> 2) Are there other ways of passing objects between tasks?

Everything will boil down to either serializing them or proxying them.
There's only one built-in proxying mechanism, DO, and the different
serialization/IPC mechanisms are differentiated more in terms of
capabilities than speed.

Mike
___

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

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


Re: How to open two nibs at app launch ? Beginners question

2009-04-13 Thread Michael Ash
On Mon, Apr 13, 2009 at 6:27 AM, Mario Kušnjer
 wrote:
>
> On 2009.04.13, at 11:15, Quincey Morris wrote:
>>
>> Not exactly. Make your application delegate (let's say its class is
>> MyAppDelegate) separate from your window controller. So, the steps are:
>>
>> -- write a MyAppDelegate class (subclass of NSObject)
>>
>> -- in IB, drag an object into MainMenu.xib, and set its class to
>> MyAppDelegate (that causes an instance to be created automatically when your
>> app starts up)
>>
>> -- in IB, connect the 'delegate' outlet of the (predefined) Application
>> object in MainMenu.xib to the MyAppDelegate object (that causes your
>> MyAppDelegate object to actually *be* the application's delegate)
>>
>> -- in your MyAppDelegate class, add an instance variable
>> mainWindowController, of class MainWindowController
>>
>> -- in your MyAppDelegate class, write an applicationDidFinishLaunching:
>> method something like this:
>>
>>        - (void) applicationDidFinishLaunching: (NSNotification *)
>> aNotification {
>>                mainWindowController = [[MainWindowController alloc] init];
>>                [mainWindowController showWindow: nil];
>>        }
>>
>> -- your MainWindowController's init method should look something like
>> this:
>>
>>        - (id) init {
>>                self = [super initWithWindowNibName: @"MainWindow"];
>>                if (!self) ...
>>                ...
>>                return self;
>>        }
>>
>> -- in IB, set the class of File's Owner in MainWindow.xib to
>> MainWindowController
>>
>> I may have left out something, but that's the basic idea.
>
> It's working !
> Thank you!
>
> Tell me please should and in what cases would I keep MyAppDelegate separate
> from MainWindowController and in what not, because I kinda made it work all
> from one place:
>
> #import 
>
>
> @interface MainWindowController : NSObject
> {
>        NSWindowController *mainWindowController;
> }
>
> @end
> 
>
> #import "MainWindowController.h"
>
>
> @implementation MainWindowController
>
> - (void) applicationDidFinishLaunching:(NSNotification *) aNotification
> {
>        mainWindowController = [[NSWindowController alloc]
> initWithWindowNibName:@"MainWindow"];
>        [mainWindowController showWindow:nil];
> }
>
> @end
>
> And about delegates, so if I want to do something else now I have to create
> another object in MainMenu.nib and make it a delegate of proxy object
> Application again ?
> There can be multiple delegations for one Application object ?
> Or should I make one object that will be a delegate but will hold the code
> for all other stuff ?
> Could you explain this to me a little bit more ?

Read the part about delegation in Cocoa Fundamentals Guide:
Communicating with Objects:

http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html

While you're at it, read the whole guide, it's quite good and will
explain a lot of things.

Mike
___

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

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


Re: How to open two nibs at app launch ? Beginners question

2009-04-13 Thread Filip van der Meeren


On 13 Apr 2009, at 17:21, Michael Ash wrote:


On Mon, Apr 13, 2009 at 6:27 AM, Mario Kušnjer
 wrote:


On 2009.04.13, at 11:15, Quincey Morris wrote:


Not exactly. Make your application delegate (let's say its class is
MyAppDelegate) separate from your window controller. So, the steps  
are:


-- write a MyAppDelegate class (subclass of NSObject)

-- in IB, drag an object into MainMenu.xib, and set its class to
MyAppDelegate (that causes an instance to be created automatically  
when your

app starts up)

-- in IB, connect the 'delegate' outlet of the (predefined)  
Application

object in MainMenu.xib to the MyAppDelegate object (that causes your
MyAppDelegate object to actually *be* the application's delegate)

-- in your MyAppDelegate class, add an instance variable
mainWindowController, of class MainWindowController

-- in your MyAppDelegate class, write an  
applicationDidFinishLaunching:

method something like this:

   - (void) applicationDidFinishLaunching: (NSNotification *)
aNotification {
   mainWindowController = [[MainWindowController  
alloc] init];

   [mainWindowController showWindow: nil];
   }

-- your MainWindowController's init method should look something  
like

this:

   - (id) init {
   self = [super initWithWindowNibName: @"MainWindow"];
   if (!self) ...
   ...
   return self;
   }


Instead of overriding the init method, you could override windowNibName

- (NSString*)windowNibName { return @"MyNibName"; }

and then just call your WindowController alloc init methods...




-- in IB, set the class of File's Owner in MainWindow.xib to
MainWindowController

I may have left out something, but that's the basic idea.


It's working !
Thank you!

Tell me please should and in what cases would I keep MyAppDelegate  
separate
from MainWindowController and in what not, because I kinda made it  
work all

from one place:

#import 


@interface MainWindowController : NSObject
{
   NSWindowController *mainWindowController;
}

@end


#import "MainWindowController.h"


@implementation MainWindowController

- (void) applicationDidFinishLaunching:(NSNotification *)  
aNotification

{
   mainWindowController = [[NSWindowController alloc]
initWithWindowNibName:@"MainWindow"];
   [mainWindowController showWindow:nil];
}

@end

And about delegates, so if I want to do something else now I have  
to create

another object in MainMenu.nib and make it a delegate of proxy object
Application again ?
There can be multiple delegations for one Application object ?
Or should I make one object that will be a delegate but will hold  
the code

for all other stuff ?
Could you explain this to me a little bit more ?


Read the part about delegation in Cocoa Fundamentals Guide:
Communicating with Objects:

http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html

While you're at it, read the whole guide, it's quite good and will
explain a lot of things.

Mike
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/filip%40code2develop.com

This email sent to fi...@code2develop.com


___

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

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


Re: NSDocument reference held by NSSavePanel?

2009-04-13 Thread Corbin Dunn


On Apr 12, 2009, at 8:33 PM, Quincey Morris wrote:



(gdb) info gc-roots 0x1225400
Number of roots: 1
Root:
  0 Kind: global  rc:   0  Address: 0xa03f1214 Symbol: shared.176062
warning: can't find class named `NSToolTipManager' given by ObjC  
class object
  1 Kind: object  rc:   0  Address: 0x01050350  Offset: 0x0008   
Class: NSToolTipManager

warning: can't find class named `a' given by ObjC class object
  2 Kind: object  rc:   0  Address: 0x0104f320  Offset: 0x0010   
Class: NSCFArray

  3 Kind: bytes   rc:   0  Address: 0x013d7200  Offset: 0x0040
warning: can't find class named `NSToolTip' given by ObjC class  
object
  4 Kind: object  rc:   0  Address: 0x010f8d30  Offset: 0x0014   
Class: NSToolTip

warning: can't find class named `a' given by ObjC class object
  5 Kind: object  rc:   0  Address: 0x010f8cd0  Offset: 0x0030   
Class: NSCFDictionary

  6 Kind: bytes   rc:   0  Address: 0x010f8d20
warning: can't find class named `NSNavBrowserCell' given by ObjC  
class object
  7 Kind: object  rc:   0  Address: 0x01326420  Offset: 0x0014   
Class: NSNavBrowserCell
warning: can't find class named `NSNavMatrix' given by ObjC class  
object
  8 Kind: object  rc:   0  Address: 0x01428d60  Offset: 0x0030   
Class: NSNavMatrix
  9 Kind: object  rc:   0  Address: 0x01082380  Class: NSSavePanel   
ivar: _spAuxiliaryStorage
warning: can't find class named `NSSavePanelAuxiliary' given by  
ObjC class object
 10 Kind: object  rc:   0  Address: 0x010c9540  Offset: 0x0010   
Class: NSSavePanelAuxiliary
 11 Kind: object  rc:   0  Address: 0x01096e80  Class: BPMDocument   
ivar: mutableModel


etc, eventually leading to the object that has the resource.  
BPMDocument is the application's NSDocument subclass, and  
mutableModel is the document's data model.


This appears to say that the save panel is holding a reference to  
the document. Does this make any sense to anyone?




This may be a bug in NSSavePanel accidentally referencing something  
too long (with a root!). Please log a bug on this, and if possible,  
provide a test app that reproduces the problem.


As a work around, try setting the delegate to nil on the NSSavePanel  
after you are done using it.


corbin


___

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

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


Re: NSDocument reference held by NSSavePanel?

2009-04-13 Thread Quincey Morris

On Apr 13, 2009, at 08:08, Michael Ash wrote:


Can you really withstand having that exclusive resource be occupied
for seconds after your document closes?


Actually, in this case, yes.


If the GC decides not to
collect that object for a much longer period of time, say, six years,
which it is perfectly within its rights to do, does that work for you?


Not six years. :)

I appreciate your point, and admit your correctness, but in this case  
the timing is insignificant enough to permit me to be lazy and do the  
resource deallocation in -finalize. So, if there are any children  
watching: Don't do this at home. Do as Michael Ash says, not as I do. ;)



Looks like a bug to me. If you can get multiple such documents to leak
then even more so.


AFAICT, it leaks every time. I tried saving a second document to see  
if it would release the first, but it didn't.



___

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

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


Re: NSDocument reference held by NSSavePanel?

2009-04-13 Thread Quincey Morris

On Apr 13, 2009, at 09:05, Corbin Dunn wrote:

This may be a bug in NSSavePanel accidentally referencing something  
too long (with a root!). Please log a bug on this, and if possible,  
provide a test app that reproduces the problem.


As a work around, try setting the delegate to nil on the NSSavePanel  
after you are done using it.


I filed it as #6783800 last night, with a trivial app that  
demonstrates the problem.


The workaround I actually used was to set the document's data model  
instance variable to nil just before the document closed.



___

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

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


Re: How to open two nibs at app launch ? Beginners question

2009-04-13 Thread Quincey Morris

On Apr 13, 2009, at 08:29, Filip van der Meeren wrote:

Instead of overriding the init method, you could override  
windowNibName


- (NSString*)windowNibName { return @"MyNibName"; }

and then just call your WindowController alloc init methods...


This doesn't look correct. This pattern is used inside a NSDocument  
subclass, but the OP's application isn't NSDocument-based.


NSWindowController also has a windowNibName method (which I'd never  
noticed before), but it looks like that's not for *supplying* the name  
but for *returning* the name passed to the initializer.


I'm not sure which of the two you're referring to, but neither seems  
to solve the problem.



___

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

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


Re: NSDocument reference held by NSSavePanel?

2009-04-13 Thread Michael Ash
On Mon, Apr 13, 2009 at 12:34 PM, Quincey Morris
 wrote:
> On Apr 13, 2009, at 08:08, Michael Ash wrote:
>
>> Can you really withstand having that exclusive resource be occupied
>> for seconds after your document closes?
>
> Actually, in this case, yes.
>
>> If the GC decides not to
>> collect that object for a much longer period of time, say, six years,
>> which it is perfectly within its rights to do, does that work for you?
>
> Not six years. :)
>
> I appreciate your point, and admit your correctness, but in this case the
> timing is insignificant enough to permit me to be lazy and do the resource
> deallocation in -finalize. So, if there are any children watching: Don't do
> this at home. Do as Michael Ash says, not as I do. ;)

I'm confused. If you can't stand six years then you can't rely on
-finalize. Nothing guarantees that it will *ever* be called in a
timely fashion. If it's just a temporary hack that's "good enough" for
your purposes, then fine, but it's incorrect if you ever need to
access this mutually-exclusive resource again without restarting your
app.

Mike
___

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

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


Dynamically getting the type of ivars

2009-04-13 Thread Dave DeLong

Hey everyone,

Is there a way to get the class of an ivar that's an object?  I know  
that I can call ivar_getTypeEncoding() on the Ivar and get a c string  
of the type encoding, and I've noticed that many of the Ivars that are  
objects are of the form @"{class name}".  Is that consistent?  Can I  
reliably pull out that stuff in between the quotes to get the class of  
the Ivar?  (This seems sketchy to me...)  Is this the best way to do  
this?  If not, what do I need to do to get the Ivar's type?


Thanks,

Dave DeLong
___

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

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


Simple mac server app seems can't receive incoming connection (code signing problem?)

2009-04-13 Thread Bill So
Hi

I have developed a simple TCP/IP server based on a very simple custom protocol.

It works perfectly fine without enabling Leopard's firewall.

But when firewall is enabled, the server just cannot accept incoming
connection after the system has started up.  This means, every time
the mac is rebooted, I'll have to relaunch my server app.

However, Leopard did prompt me the "Allow" or "Deny" incoming
connection when I launch my server app.  But it seems that Leopard
"forgets" this when I start the system again next time.

What can I do?

Can code signing solve the problem?

Bill
___

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

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


Re: NSDocument reference held by NSSavePanel?

2009-04-13 Thread Quincey Morris

On Apr 13, 2009, at 10:07, Michael Ash wrote:


I'm confused. If you can't stand six years then you can't rely on
-finalize. Nothing guarantees that it will *ever* be called in a
timely fashion.


No need to be confused. I was just admitting your correctness and then  
hiding behind a smiley face.


However, the part I didn't say before was the question of whether a  
garbage collector that didn't collect unreferenced objects in a  
*reasonably* timely fashion was or was not defective. (And, yes,  
"timely" is somewhat elastic here.)


If the answer is that it might take six years (i.e. more or less  
never) then your earlier statement can't be true in any practical sense:



-finalize should do two things. First, it should clean up any memory
allocations that aren't managed by the collector, like malloc blocks.
Second, it should clean up non-memory resources *as a fail-safe*. It
should close file descriptors, release shared locks, what have you,
but only to ensure that they weren't forgotten.


If you can't be sure when finalize will be called, then these *fail- 
safe* activities aren't fail-safe at all. Waiting six years to clean  
up memory allocations that aren't managed by the collector, or waiting  
six years to clean up non-memory resources, even as a fall-back  
position, makes no sense, so there's no sense in coding the cleanup in  
a finalize. In fact, if you have to treat finalize as if it isn't  
going to be called for six years, then there's absolutely no practical  
use of finalize at all.


So, if the garbage collector can be expected to run within a couple of  
seconds (or maybe even tens of seconds, if other application threads  
are busy computing away), it makes sense to use finalize for non-time- 
critical, fail-safe or fall-back resource deallocation. But if it can  
take *much* longer than that, then you either have to give up finalize  
completely, or declare the garbage collector defective.


At least, that's the argument that suggests itself to me. But I'm not  
insisting on its validity, which is why I didn't go OT with it earlier.



___

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

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


Re: Dynamically getting the type of ivars

2009-04-13 Thread Nick Zitzmann


On Apr 13, 2009, at 11:10 AM, Dave DeLong wrote:

Can I reliably pull out that stuff in between the quotes to get the  
class of the Ivar?  (This seems sketchy to me...)  Is this the best  
way to do this?


No.


If not, what do I need to do to get the Ivar's type?



Just use the -class and +class methods. If you need to check to see  
whether an object is, or is a subclass of, a certain class, then use - 
isMemberOfClass: and -isKindOfClass: respectively.


Nick Zitzmann


___

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

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


Re: Dynamically getting the type of ivars

2009-04-13 Thread Dave DeLong

I don't think that'll work.  Here's what I'm doing:

unsigned int numIvars = 0;
Ivar * ivars = class_copyIvarList(aClass, &numIvars);
for (int i = 0; i < numIvars; i++) {
  Ivar thisIvar = ivars[i];
  Class ivarClass = somethingToGetTheIvarClassIfItsAnObject(thisIvar);
}

I can check to see if an Ivar is an object by checking to see if the  
first character of ivar_getTypeEncoding(thisIvar) is the '@' symbol  
(this, I believe, is documented to be true).  However, since all I  
have is an Ivar pointer, I'm not sure how I can get the static type of  
the Ivar (if it's an object).


Thanks,

Dave

On Apr 13, 2009, at 12:12 PM, Nick Zitzmann wrote:



On Apr 13, 2009, at 11:10 AM, Dave DeLong wrote:

Can I reliably pull out that stuff in between the quotes to get the  
class of the Ivar?  (This seems sketchy to me...)  Is this the best  
way to do this?


No.


If not, what do I need to do to get the Ivar's type?



Just use the -class and +class methods. If you need to check to see  
whether an object is, or is a subclass of, a certain class, then use  
-isMemberOfClass: and -isKindOfClass: respectively.


Nick Zitzmann




___

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

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


Re: Need to find out why I get Cocoa error 256 . . . (more info)

2009-04-13 Thread Michael A. Crawford
When I change the persistent-store type from SQLite to Binary, my code  
works.  I'm able to save the Managed Object Context.  On the next run,  
my fetch works because there is not data in the persistent store.   
Anyone have any idea why the store type makes the difference?


/**
 Returns the persistent store coordinator for the application.
 If the coordinator doesn't already exist, it is created and the  
application's store added to it.

 */
- (NSPersistentStoreCoordinator*)persistentStoreCoordinator
{
if ( nil == persistentStoreCoordinator )
{
#if 0
NSURL* storeUrl = [NSURL fileURLWithPath:[[self  
applicationDocumentsDirectory]  
stringByAppendingPathComponent:@"SpecialOrders.sqlite"]];

#else
NSURL* storeUrl = [NSURL fileURLWithPath:[[self  
applicationDocumentsDirectory]  
stringByAppendingPathComponent:@"SpecialOrders.bin"]];

#endif

NSError *error;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator  
alloc] initWithManagedObjectModel:[self managedObjectModel]];

#if 0
if ( ![persistentStoreCoordinator  
addPersistentStoreWithType:NSSQLiteStoreType

configuration:nil URL:storeUrl
  
options:nil error:&error] )

#else
if ( ![persistentStoreCoordinator  
addPersistentStoreWithType:NSBinaryStoreType

configuration:nil URL:storeUrl
  
options:nil error:&error] )

#endif
{
// Handle error
NSLog(@"Error adding persistent store to coordinator");
}
}
return persistentStoreCoordinator;
}



#pragma mark -
#pragma mark AppController methods

- (void)viewDidLoad
{
  [super viewDidLoad];

// Set up the edit and add buttons.
  self.navigationItem.leftBarButtonItem = self.editButtonItem;

  UIBarButtonItem* addButton = [[UIBarButtonItem alloc]  
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self  
action:@selector(insertNewObject)];

  self.navigationItem.rightBarButtonItem = addButton;
  [addButton release];

NSError *error;

if ( ![[self fetchedResultsController] performFetch:&error] )
  {
// Handle the error...
  NSLog(@"Failed to perform initial fetch for view");
}

  //
  // If the fetch resulted in no records, create and save instances  
of each of

  // the model objects.
  //
  NSArray* fetchedObjects = [[self fetchedResultsController]  
fetchedObjects];


  if ( (nil == fetchedObjects) || (0 == fetchedObjects.count) )
  {
  NSLog(@"Nothing returned from fetch; creating dummy objects");

  Language* language = [NSEntityDescription  
insertNewObjectForEntityForName:@"Language"  
inManagedObjectContext:self.managedObjectContext];

  language.name = @"English";
  language.symbol = @"EN";

  Publication* publication = [NSEntityDescription  
insertNewObjectForEntityForName:@"Publication"  
inManagedObjectContext:self.managedObjectContext];

  publication.ID = [NSNumber numberWithInt:5334];
  publication.languages = [NSSet setWithObject:language];
  publication.name = @"Bible Teach";
  publication.symbol = @"bh";

  language.publications = [NSSet setWithObject:publication];

  Publisher* publisher = [NSEntityDescription  
insertNewObjectForEntityForName:@"Publisher"  
inManagedObjectContext:self.managedObjectContext];

  publisher.firstName = @"Michael";
  publisher.lastName = @"Crawford";

  Request* request = [NSEntityDescription  
insertNewObjectForEntityForName:@"Request"  
inManagedObjectContext:self.managedObjectContext];

  request.language= language;
  request.publication = publication;
  request.publisher   = publisher;
  request.timeStamp   = [NSDate date];

  publisher.requests = [NSSet setWithObject:request];
  publication.requests = [NSSet setWithObject:request];

  Order* order = [NSEntityDescription  
insertNewObjectForEntityForName:@"Order"  
inManagedObjectContext:self.managedObjectContext];

  order.ID = [NSNumber numberWithInt:1];
  order.requests = [NSSet setWithObject:request];
  order.timeStamp = [NSDate date];

  request.order = order;

  NSLog(@"language = %@", language);
  NSLog(@"publication = %@", publication);
  NSLog(@"publisher = %@", publisher);
  NSLog(@"request = %@", request);
  NSLog(@"order = %@", order);

  NSError* error;

  if ( ![[fetchedResultsController managedObjectContext]  
save:&error] )

  {
  NSLog(@"Failed to save context with new data: %@", error);
  }

  [self.tableView reloadData];
  }
}


-Michael
--
There are two ways of constructing a software design. One way is to  
make it so simple that there are obviously no deficiencies.
And the other way is to make it so complicated t

Re: Dynamically getting the type of ivars

2009-04-13 Thread Greg Guerin

Dave DeLong wrote:


unsigned int numIvars = 0;
Ivar * ivars = class_copyIvarList(aClass, &numIvars);
for (int i = 0; i < numIvars; i++) {
  Ivar thisIvar = ivars[i];
  Class ivarClass = somethingToGetTheIvarClassIfItsAnObject(thisIvar);
}

I can check to see if an Ivar is an object by checking to see if  
the first character of ivar_getTypeEncoding(thisIvar) is the '@'  
symbol (this, I believe, is documented to be true). However, since  
all I have is an Ivar pointer, I'm not sure how I can get the  
static type of the Ivar (if it's an object).



Call ivar_getTypeEncoding(Ivar) to get its type-encoding string.  To  
decipher the type-encoding string, see this:


http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ 
ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html


In particular, note:
  "Objects are treated like structures."

  -- GG

___

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

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


Re: Dynamically getting the type of ivars

2009-04-13 Thread Dave DeLong

Again, I don't think that's what I'm looking for.

For example, let's say I create a class called "Bogus", that has one  
ivar, a pointer to another Bogus object.  Let's say I get the Ivar  
pointer via the class_copyIvarList function, and then print the  
typeEncoding of the Bogus ivar, like this:

NSLog(@"Bogus ivar: %s", ivar_getTypeEncoding(BogusIvar));

This prints out:
Bogus ivar: @"Bogus"

However, if I simply do:
NSLog(@"Bogus: %s", @encode(Bogus));

Then I get:
Bogus: {bogu...@}

So I got thinking that wasn't what I wanted, so I did:
NSLog(@"Bogus pointer: %s", @encode(Bogus *));

This prints:
Bogus pointer: @

Still not what I'm looking for.  I have an Ivar pointer, and I want to  
get its static type (if it has one).


Dave

On Apr 13, 2009, at 2:25 PM, Greg Guerin wrote:

Call ivar_getTypeEncoding(Ivar) to get its type-encoding string.  To  
decipher the type-encoding string, see this:


http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html

In particular, note:
 "Objects are treated like structures."

 -- GG

___

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

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


Re: Dynamically getting the type of ivars

2009-04-13 Thread Greg Parker

On Apr 13, 2009, at 1:41 PM, Dave DeLong wrote:
Still not what I'm looking for.  I have an Ivar pointer, and I want  
to get its static type (if it has one).


You can't. The runtime metadata for ivars does not include the static  
type for objects. Sorry.


The BridgeSupport metadata for system libraries might include more  
info, but I don't know if it records any ivar information.



--
Greg Parker gpar...@apple.com Runtime Wrangler


___

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

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


NSDecimalNumber nil parameter to -decimalNumberByAdding: causes Mach exception EXC_BAD_ACCESS

2009-04-13 Thread jonat...@mugginsoft.com

Is this a known issue with NSDecimalNumber ?

NSDecimalNumber *n1 = (NSDecimalNumber *)[NSDecimalNumber  
numberWithDouble:1.0];

NSDecimalNumber *n2 = nil;
n = [n decimalNumberByAdding:n2];

result = EXC_BAD_ACCESS

There seems to be nothing in the docs to suggest that the parameter is  
unduly sensitive.


Jonathan Mitchell

Central Conscious Unit
http://www.mugginsoft.com




___

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

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


Re: NSDocument reference held by NSSavePanel?

2009-04-13 Thread David Scheidt


On Apr 13, 2009, at 2:01 PM, Quincey Morris wrote:


On Apr 13, 2009, at 10:07, Michael Ash wrote:


I'm confused. If you can't stand six years then you can't rely on
-finalize. Nothing guarantees that it will *ever* be called in a
timely fashion.


No need to be confused. I was just admitting your correctness and  
then hiding behind a smiley face.


However, the part I didn't say before was the question of whether a  
garbage collector that didn't collect unreferenced objects in a  
*reasonably* timely fashion was or was not defective. (And, yes,  
"timely" is somewhat elastic here.)


If the answer is that it might take six years (i.e. more or less  
never) then your earlier statement can't be true in any practical  
sense:


I don't have deep knowledge of Apple garbage collector, I'm just  
grateful user of it.


In general, though, it's perfectly reasonable to put off garbage  
collection for as long as possible.  It's fairly expensive, and if  
there is no pressure on the resource being garbage-collected, it's  
perfectly reasonable to defer garbage collection until there is  
pressure.  There's a reasonable chance that the application will  
terminate before then, and then you've save the effort.  In  other  
words, it's not the clock that controls whether garbage collection  
need to run, it's the presence of garbage.


___

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

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


Re: NSDecimalNumber nil parameter to -decimalNumberByAdding: causes Mach exception EXC_BAD_ACCESS

2009-04-13 Thread iseecolors
In the third line where you do the assignment, do you mean to work  
with n1, or is there another object somewhere?


Rich

On Apr 13, 2009, at 1:47 PM, jonat...@mugginsoft.com wrote:


Is this a known issue with NSDecimalNumber ?

NSDecimalNumber *n1 = (NSDecimalNumber *)[NSDecimalNumber  
numberWithDouble:1.0];

NSDecimalNumber *n2 = nil;
n = [n decimalNumberByAdding:n2];

result = EXC_BAD_ACCESS

There seems to be nothing in the docs to suggest that the parameter  
is unduly sensitive.


Jonathan Mitchell

Central Conscious Unit
http://www.mugginsoft.com




___

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:
http://lists.apple.com/mailman/options/cocoa-dev/iseecolors%40sbcglobal.net

This email sent to iseecol...@sbcglobal.net


___

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

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


Re: NSDecimalNumber nil parameter to -decimalNumberByAdding: causes Mach exception EXC_BAD_ACCESS

2009-04-13 Thread jonat...@mugginsoft.com

Dumb typo corrected:

NSDecimalNumber *n1 = (NSDecimalNumber *)[NSDecimalNumber  
numberWithDouble:1.0];

NSDecimalNumber *n2 = nil;
n1 = [n1 decimalNumberByAdding:n2];

result = EXC_BAD_ACCESS

There seems to be nothing in the docs to suggest that the parameter is  
unduly sensitive.


On 13 Apr 2009, at 22:00, iseecolors wrote:

In the third line where you do the assignment, do you mean to work  
with n1, or is there another object somewhere?


Rich


Thanks Rich!

Central Conscious Unit
http://www.mugginsoft.com




___

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

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


Re: NSDecimalNumber nil parameter to -decimalNumberByAdding: causes Mach exception EXC_BAD_ACCESS

2009-04-13 Thread Kyle Sluder
On Mon, Apr 13, 2009 at 4:47 PM, jonat...@mugginsoft.com
 wrote:
> NSDecimalNumber *n2 = nil;
> n = [n decimalNumberByAdding:n2];

You can't assume that nil is a valid argument.  So no, the lack of any
documentation stating that "passing nil will blow up" is not a bug.

--Kyle Sluder
___

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

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


typeFromFileExtension in Leopard SDK

2009-04-13 Thread Eric Slosser
When I switched my SDKROOT from 10.4 to 10.5, my calls to - 
[NSDocumentController typeFromFileExtension:] started returning nil.


- with Xcode 3.1.1 on Leopard 10.5.6
- make a new Cocoa NSDocument app
- in the target info window,  properties pane, assign a document type,  
giving it

name: my doc
UTI: com.comp.app.doc1
extensions: doc1
- in MyDocument.m, windowControllerDidLoadNib, throw in:
	NSString* t = [[NSDocumentController sharedDocumentController]  
typeFromFileExtension:@"doc1"];

NSLog(@"filetype = %@", t);
- build-n-run, note that
fileType = (null)
- quit app, go to target info window, build pane, set "Base SDK" to 10.4
- build-n-run, note that
fileType = my doc


I see in the release notes for Leopard that -[NSDocumentController  
typeFromFileExtension:] is deprecated, but that doesn't mean "stops  
working", does it?


Am I doing something wrong?
___

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

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


Re: Dynamically getting the type of ivars

2009-04-13 Thread Dave DeLong
Thanks for the definitive answer.  My observations indicate that every  
statically typed object has a type encoding of @"ClassName", so I'm  
going ahead with my original plan to pull the class out of that (I  
still don't like it, but I need that class).


Dave

On Apr 13, 2009, at 2:44 PM, Greg Parker wrote:


On Apr 13, 2009, at 1:41 PM, Dave DeLong wrote:
Still not what I'm looking for.  I have an Ivar pointer, and I want  
to get its static type (if it has one).


You can't. The runtime metadata for ivars does not include the  
static type for objects. Sorry.


The BridgeSupport metadata for system libraries might include more  
info, but I don't know if it records any ivar information.

___

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

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


Re: NSDecimalNumber nil parameter to -decimalNumberByAdding: causes Mach exception EXC_BAD_ACCESS

2009-04-13 Thread jonat...@mugginsoft.com


On 13 Apr 2009, at 22:13, Kyle Sluder wrote:


On Mon, Apr 13, 2009 at 4:47 PM, jonat...@mugginsoft.com
 wrote:

NSDecimalNumber *n2 = nil;
n1 = [n1 decimalNumberByAdding:n2];


You can't assume that nil is a valid argument.  So no, the lack of any
documentation stating that "passing nil will blow up" is not a bug.


Whatever way you slice it, bug or not, this is fairly toxic behaviour.

Checking the docs again I see that the previously listed method, - 
compare: does carry a caveat:


- (NSComparisonResult)compare:(NSNumber *)decimalNumber

Parameters
decimalNumber
The number with which to compare the receiver.

This value must not be nil. If this value is nil, the behavior is  
undefined and may change in future versions of Mac OS X.




--Kyle Sluder


Jonathan Mitchell

Central Conscious Unit
http://www.mugginsoft.com




___

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

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


Re: typeFromFileExtension in Leopard SDK

2009-04-13 Thread Kyle Sluder
On Mon, Apr 13, 2009 at 5:15 PM, Eric Slosser  wrote:
> I see in the release notes for Leopard that -[NSDocumentController
> typeFromFileExtension:] is deprecated, but that doesn't mean "stops
> working", does it?

Not necessarily.

> Am I doing something wrong?

Did you declare your com.comp.app.doc1 UTI as an exported type in your
Info.plist?

--Kyle Sluder
___

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

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


Re: NSDecimalNumber nil parameter to -decimalNumberByAdding: causes Mach exception EXC_BAD_ACCESS

2009-04-13 Thread Kyle Sluder
On Mon, Apr 13, 2009 at 5:29 PM, jonat...@mugginsoft.com
 wrote:
> Whatever way you slice it, bug or not, this is fairly toxic behaviour.

You can't dereference a null pointer, and you can't divide by zero.
Must every possible occurrence of these be marked?

nil is a very special value.  Sometimes the API attaches a meaning to
it -- for example, "pass nil to specify no options."  Other times, the
API expects you to have an object on hand.  I wouldn't complain if all
I got were strange looks when I asked you to add 3 + Banana.

--Kyle Sluder
___

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

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


Re: Dynamically getting the type of ivars

2009-04-13 Thread Kyle Sluder
On Mon, Apr 13, 2009 at 5:29 PM, Dave DeLong  wrote:
> Thanks for the definitive answer.  My observations indicate that every
> statically typed object has a type encoding of @"ClassName", so I'm going
> ahead with my original plan to pull the class out of that (I still don't
> like it, but I need that class).

There is no such thing as a "statically typed object."  All of the
type information that the compiler has simply disappears after
compilation is done.  The only type information available at runtime
is an object's isa pointer.

--Kyle Sluder
___

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

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


Autosaving the selection in an NSTableView

2009-04-13 Thread Martin Stanley
I have a core-data document-based application that uses a NSTableView  
with an NSArrayController as its data source. I have managed to figure  
out the magic IB incantations required to save the column sort, order  
and hidden data to the shared NSDeafulsController.


What I would like to do is to also save the current selection of the  
table across application invocations. I have tried the obvious:
	- bind the array controller's selected indexes to the Shared Defaults  
controller - no luck
	- bind the tableview's selected indexes to the Shared Defaults  
controller - no luck
I even tried to get the select programmatically, but when I tried the  
callback methods I thought appropriate:

- windowControllerDidLoadNib
- applicationDidFinishLaunching
I found that the array controller was not yet loaded with data and  
therefore had no selection.


Can anyone shed some light on this?

Thanks,
Martin


___

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

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


Re: Best way to pass large objects between tasks?

2009-04-13 Thread Yoshiaki Katayanagi
  Oleg Krupnov wrotes

>I haven't tried either of the methods I mentioned so far (because I'm
>lazy, sorry:), but what I have tried is I created NSData from the
>large object by using NSKeyedArchiver. It has taken forever, so that I
>had to force-quit the process. That's why I am asking if the same
>thing is going to happen with piples and DO? Or maybe I'm doing
>something wrong?

  If your data has many double values and use encodeDouble:forKey: 
use encodeBytes:length:forKey: instead.  encodeDouble:forKey: is very 
very slow. In my case, with encodeDouble:forKey: it takes 4 hour and 
30 minutes, but with encodeBytes:length:forKey: it takes only 21 seconds.
I never tested for float values but maybe the same.

Yoshiaki Katayanagi
http://www.jizoh.jp/english.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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


CGContextClipToMask

2009-04-13 Thread aashram
I need to fill a shape which is in a image with a gradient fill
like progress bar. Looking into CGContextClipToMask and using a mask to
achieve this. Would this be the best way ?

Does anyone have a very simple example where I have a grayspace mask and a
image and doing a gradient fill. I am not very familiar with CG and trying
to get to understand it better.



___

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

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


'Strange' issue with NSOutlineView in NSMenuItem

2009-04-13 Thread Marcel Trapman

Hi,

I have set up an application as 'menuling' (if I am correct).

For that I have created a menu in a nib file as well as an outline view.

I linked the view of one of the menuitems to the outline view.

Following that I have created a doubleclick method and linked that to  
the doubleclick action of the view.


The action and all other things work perfectly fine. When the method  
receives the action the selected row is determined, the item extracted  
and based on the information a url is opened in the default browser.


So far so good.

However, when I go back to the menu I can not select any row in the  
outline view anymore. I can collapse/expand the items but there is no  
way that I can select the row.
This remains so until I show a window from the menu and close the  
window. After that I can again select a row.
That made me think it has to do with either the fact that the  
application/menuling has no focus anymore or that the outline view is  
not enabled.
I think the first because, when I do not open a url everything works  
as expected.


Has anybody any idea how to solve this?

I set up the double click even as follows:

-
[outlineView setTarget:self];
[outlineView setDoubleAction:@selector(outlineViewDoubleClicked:)];
-

And this is the event:

-
NSInteger selectedRow = [sender selectedRow];
if (selectedRow != -1) {
@try {
id item = [sender itemAtRow:selectedRow];

[sender deselectRow:selectedRow];

			[[NSWorkspace sharedWorkspace] openURL:[[NSURL alloc]  
initWithString:[item objectForKey:@"link"]]];

}
@catch (NSException * e) {
NSLog(@"%@", e);
}
}
-

I hope somebody can help me with this.

Thanks,
Marcel
___

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

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


NSSliderCell, lockFocus question

2009-04-13 Thread Frederik Slijkerman

Hi all,

This is my first question here. I'm trying to port a cross-platform app
to OS X using Cocoa. I've already got good results so far, but sometimes
it's difficult to find out how things are supposed to work.

Currently I'm porting a custom slider control that needs to draw parts
of the its interface, like the slider bar and the knob, in the OS style.
The code that I currently have draws this to a temporary bitmap to avoid
flicker on Windows and I'd like to keep it like this as much as possible
to avoid forking the code too much.

It looks like NSSliderCell will be able to draw the necessary parts, but
the documentation says that you need to call lockFocus on the view that
you want to draw to first. But I would like to draw in a CGContextRef
that I have which draws into a bitmap. Now I'm wondering what lockFocus
on NSView does exactly. Does it just activate a graphics context that
works on this view?

Specifically, would it work to do:

NSGraphicsContext *gc = [NSGraphicsContext contextWithGraphicsPort:
myCGContextRef];
[NSGraphicsContext setCurrentContext:gc];

to get NSSliderCell to draw into any custom CGContextRef?

Thanks for any comments!

Best regards,
Frederik Slijkerman

___

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

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


Re: Exit an Application

2009-04-13 Thread Uli Kusterer

On 13.04.2009, at 16:19, Filip van der Meeren wrote:

You could always call exit(); from C
or [NSApp terminate:XXX];



Well,

 calling exit() is the best way to shoot yourself in the foot. That  
would exit the app immediately, without saving any unsaved documents,  
without writing any cached NSUserDefaults changes to the hard disk  
etc. Its effect in a regular Cocoa application is only slightly better  
than choosing "Force Quit" and shooting down the app. In short, don't  
do it.


 [[NSApplication sharedApplication] terminate: nil];

or the slightly shorter and a thoretically a tad more dangerous  
similar call with NSApp in it are really the only option. (Well,  
theoretically you could send yourself a "quit" Apple Event, but that's  
only of academical interest...)


Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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

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


Re: Dynamically getting the type of ivars

2009-04-13 Thread Dave DeLong
I understand the distinction, and your clarification has prompted me  
to think of another way I could do this.  Currently, the code where  
I'm getting the list of Ivars is in a class method.  However, I also  
have an instance method where I'm doing something very similar.  I  
could move the type getting into that method, since in there I'm  
calling [self valueForKey:]...


If this seems mysterious to you, I'll post again when I've got it  
working right and explain what I'm up to.


Thanks again,

Dave

On Apr 13, 2009, at 3:32 PM, Kyle Sluder wrote:

On Mon, Apr 13, 2009 at 5:29 PM, Dave DeLong   
wrote:
Thanks for the definitive answer.  My observations indicate that  
every
statically typed object has a type encoding of @"ClassName", so I'm  
going
ahead with my original plan to pull the class out of that (I still  
don't

like it, but I need that class).


There is no such thing as a "statically typed object."  All of the
type information that the compiler has simply disappears after
compilation is done.  The only type information available at runtime
is an object's isa pointer.

--Kyle Sluder


___

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

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


Re: Dynamically getting the type of ivars

2009-04-13 Thread Chris Hanson
What are you really trying to accomplish using the class information  
of an instance variable?


Generally you should treat instance variables as 100% private to their  
class; their uses can change from version to version?


  -- Chris

On Apr 13, 2009, at 2:29 PM, Dave DeLong  wrote:

Thanks for the definitive answer.  My observations indicate that  
every statically typed object has a type encoding of @"ClassName",  
so I'm going ahead with my original plan to pull the class out of  
that (I still don't like it, but I need that class).


Dave

On Apr 13, 2009, at 2:44 PM, Greg Parker wrote:


On Apr 13, 2009, at 1:41 PM, Dave DeLong wrote:
Still not what I'm looking for.  I have an Ivar pointer, and I  
want to get its static type (if it has one).


You can't. The runtime metadata for ivars does not include the  
static type for objects. Sorry.


The BridgeSupport metadata for system libraries might include more  
info, but I don't know if it records any ivar information.

___

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:
http://lists.apple.com/mailman/options/cocoa-dev/cmh%40me.com

This email sent to c...@me.com

___

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

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


Best way to get a non-repeating random number?

2009-04-13 Thread Eric E. Dolecki
I'd like to make sure a new random (int) number doesn't equal the previous.
In ActionScript 3 I could just run a little while loop check against the
previous value. So while it wasn't equal to the last it would be used. So
this isn't using an Array by any means for anything.
What's the best way to do this in Obj-C? The same way in AS3? I just want to
make sure I set it correctly.

E.
___

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

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


Re: NSSliderCell, lockFocus question

2009-04-13 Thread Kyle Sluder
On Mon, Apr 13, 2009 at 4:30 PM, Frederik Slijkerman  wrote:
> Currently I'm porting a custom slider control that needs to draw parts
> of the its interface, like the slider bar and the knob, in the OS style.
> The code that I currently have draws this to a temporary bitmap to avoid
> flicker on Windows and I'd like to keep it like this as much as possible
> to avoid forking the code too much.

Don't expect your drawing code to be at all similar on the two OSes.
For starters, OS X already double-buffers for you.

In fact, why not just use a regular NSSliderCell, and forego custom
drawing altogether?  Custom UI that deviates significantly from
established convention is usually not well received on the Macintosh
platform.

--Kyle Sluder
___

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

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


Re: NSSliderCell, lockFocus question

2009-04-13 Thread Uli Kusterer

On 13.04.2009, at 22:30, Frederik Slijkerman wrote:

Currently I'm porting a custom slider control that needs to draw parts
of the its interface, like the slider bar and the knob, in the OS  
style.
The code that I currently have draws this to a temporary bitmap to  
avoid
flicker on Windows and I'd like to keep it like this as much as  
possible

to avoid forking the code too much.


 If you can, get the codebase changed in some way that you can get  
rid of the Windows code that isn't needed on the Mac, e.g. by adding  
additional abstractions. It'll hurt much less in the long run.


It looks like NSSliderCell will be able to draw the necessary parts,  
but
the documentation says that you need to call lockFocus on the view  
that

you want to draw to first. But I would like to draw in a CGContextRef
that I have which draws into a bitmap. Now I'm wondering what  
lockFocus

on NSView does exactly. Does it just activate a graphics context that
works on this view?



 That's what it basically does, so yes, this should work. That said,  
many cells expect to be hosted inside a view, and I'm not sure they'll  
work as well in any other graphics context. The main reason for cells  
to exist is not to draw outside views, but rather to support things  
like NSTableView, NSMatrix etc., where you draw several cells in a  
single view for efficiency reasons.


 Another option than a bitmap context (which is a rather low-level  
way to go about things) would be to just use an NSImage.


Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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

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


Re: Obvious NSSegmentedControl Bug?

2009-04-13 Thread Peter Ammon
This looks like a bug.  I appreciate your taking the time to check and  
hopefully to file it.


-Peter

On Apr 12, 2009, at 1:22 PM, Seth Willits wrote:



I need a sanity check before I file a bug report.



sc is a 3-segment NSSegmentedControl with either Select One or  
Select Any as its mode. Segment 1 (the middle one) is selected in  
IB. Triggered as an action:



NSLog(@"Before:");
NSLog(@"  %d", [sc selectedSegment]);
NSLog(@"  %@", [sc isSelectedForSegment:0] ? @"YES" : @"NO");
NSLog(@"  %@", [sc isSelectedForSegment:1] ? @"YES" : @"NO");
NSLog(@"  %@", [sc isSelectedForSegment:2] ? @"YES" : @"NO");

[sc setSelected:NO forSegment:[sc selectedSegment]];

NSLog(@"After:");
NSLog(@"  %d", [sc selectedSegment]);
NSLog(@"  %@", [sc isSelectedForSegment:0] ? @"YES" : @"NO");
NSLog(@"  %@", [sc isSelectedForSegment:1] ? @"YES" : @"NO");
NSLog(@"  %@", [sc isSelectedForSegment:2] ? @"YES" : @"NO");


Before:
 1
 NO
 YES
 NO

After:
 1
 NO
 NO
 NO


selectedSegment: "[Returns t]he index of the currently selected  
segment, or -1 if no segment is selected."



No segment is selected so selectedSegment should clearly be -1, right?


___

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

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


Re: Best way to get a non-repeating random number?

2009-04-13 Thread Luca C.
This isn't objc related, but mostly c related.  In order to get a random int
you may want to use the rand() function.  rand() returns a number between 0
and RAND_MAX, and you have to initialize this random generator by calling
srand().  You can put every (unsigned) value you want in there, though in
general it's used passing (unsigned)time(NULL) as parameter.  This way
you'll always get a different int.

2009/4/14 Eric E. Dolecki 

> I'd like to make sure a new random (int) number doesn't equal the previous.
> In ActionScript 3 I could just run a little while loop check against the
> previous value. So while it wasn't equal to the last it would be used. So
> this isn't using an Array by any means for anything.
> What's the best way to do this in Obj-C? The same way in AS3? I just want
> to
> make sure I set it correctly.


-- 
--Luca C.
___

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

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


Re: Best way to get a non-repeating random number?

2009-04-13 Thread Uli Kusterer

On 14.04.2009, at 01:44, Luca C. wrote:

You can put every (unsigned) value you want in there, though in
general it's used passing (unsigned)time(NULL) as parameter.  This way
you'll always get a different int.



 No you won't. It's a *random* number generator. The seed simply  
means you get a different sequence of random numbers. However, random  
really means RANDOM. I.e. it's perfectly possible to get the same  
number three times in a row during a sequence. That would still be  
random.


 I think it would be best if Eric told us what he's trying to do. For  
example, in some cases, (e.g. sorting) you actually want to build a  
new list and shuffle that by returning random numbers from your sort  
function. In that case, since your list only contains each item once,  
and your random numbers only affect their order, it's perfectly OK to  
just return a random number. You'll still get a shuffled list with  
each item only once.


 OTOH, in other cases, you might actually have to do the looping  
thing and just keep asking for a new random number until you get one  
that isn't the previous number.


Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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

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


Re: Exit an Application

2009-04-13 Thread WT

On Apr 13, 2009, at 11:52 PM, Uli Kusterer wrote:


Well,

calling exit() is the best way to shoot yourself in the foot. That  
would exit the app immediately, without saving any unsaved  
documents, without writing any cached NSUserDefaults changes to the  
hard disk etc. Its effect in a regular Cocoa application is only  
slightly better than choosing "Force Quit" and shooting down the  
app. In short, don't do it.


[[NSApplication sharedApplication] terminate: nil];

or the slightly shorter and a thoretically a tad more dangerous  
similar call with NSApp in it are really the only option. (Well,  
theoretically you could send yourself a "quit" Apple Event, but  
that's only of academical interest...)


Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


And for anyone curious about the same question in relation to the  
iPhone OS, two comments come to mind:


a) you're not supposed to quit your own application; the user is in  
charge and can hit the home button if he/she wants to quit your  
application


b) still, if you really want to programmatically quit your  
application, you can try the analogous


[[UIApplication sharedApplication] performSelector:  
@selector(terminate)];


It works, but the final animation that an application goes through  
when the application quits to the home screen (the zooming effect)  
does not happen, which might confuse the user into thinking that your  
application crashed.


Wagner
___

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

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


Re: NSDocument reference held by NSSavePanel?

2009-04-13 Thread Quincey Morris

On Apr 13, 2009, at 13:56, David Scheidt wrote:

In general, though, it's perfectly reasonable to put off garbage  
collection for as long as possible.  It's fairly expensive, and if  
there is no pressure on the resource being garbage-collected, it's  
perfectly reasonable to defer garbage collection until there is  
pressure.  There's a reasonable chance that the application will  
terminate before then, and then you've save the effort.  In  other  
words, it's not the clock that controls whether garbage collection  
need to run, it's the presence of garbage.


This is a perfectly reasonably argument, and perhaps it's the only  
argument. But I wasn't suggesting earlier that a garbage collector  
which doesn't collect as soon as possible (or nearly so) is defective,  
but that a garbage collector which defers some collections  
indefinitely implies that the finalize method is useless. (Or,  
equivalently, that if you want to use finalize, such a garbage  
collector is defective.)


My reasoning is that finalize is used to manage non-GC resources, not  
GC memory objects. With an indefinitely deferring collector, where you  
can't expect finalize to be called "soon", then you've already lost  
the game in terms of non-GC resource management (because non-GC  
resources don't exert any pressure on the collector), and you may as  
well abandon your finalize-based management strategy.


One caveat: if a GC-object manages a *root* reference to another GC- 
object (for example, object A maintains a reference to object B in a  
global variable), then finalize would be a suitable place to manage  
the root reference, even if it is deferred.



___

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

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


Re: Best way to get a non-repeating random number?

2009-04-13 Thread WT

On Apr 14, 2009, at 1:57 AM, Uli Kusterer wrote:


On 14.04.2009, at 01:44, Luca C. wrote:

You can put every (unsigned) value you want in there, though in
general it's used passing (unsigned)time(NULL) as parameter.  This  
way

you'll always get a different int.


No you won't. It's a *random* number generator. The seed simply  
means you get a different sequence of random numbers. However,  
random really means RANDOM. I.e. it's perfectly possible to get the  
same number three times in a row during a sequence. That would still  
be random.


Sorry to nitpick, but no, it *isn't* a random number generator. It's a  
*pseudo*-random number generator. Using the same seed in two different  
invocations will result in the exact same sequence of generated  
numbers for both invocations. So, technically, even though the  
generated numbers are as close to being random as one can get by non- 
physical (ie, algorithmic) means, the generator cannot be called a  
random number generator.


The remainder of your post is, of course, completely correct. It's  
perfectly possible for a random sequence (even a *truly* random  
sequence, such as one generated by physical means) to have any number  
of repeating numbers in succession.


Wagner
___

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

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


Re: Best way to get a non-repeating random number?

2009-04-13 Thread Uli Kusterer

On 14.04.2009, at 02:17, WT wrote:

On Apr 14, 2009, at 1:57 AM, Uli Kusterer wrote:
No you won't. It's a *random* number generator. The seed simply  
means you get a different sequence of random numbers. However,  
random really means RANDOM. I.e. it's perfectly possible to get the  
same number three times in a row during a sequence. That would  
still be random.


Sorry to nitpick, but no, it *isn't* a random number generator.


 Fully agree. I had that in there, but removed 'pseudo' because I  
thought it might confuse the point: That "random" includes getting the  
same number twice.




Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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

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


Re: NSDocument reference held by NSSavePanel?

2009-04-13 Thread Michael Ash
On Mon, Apr 13, 2009 at 2:01 PM, Quincey Morris
 wrote:
> If the answer is that it might take six years (i.e. more or less never) then
> your earlier statement can't be true in any practical sense:
>
>> -finalize should do two things. First, it should clean up any memory
>> allocations that aren't managed by the collector, like malloc blocks.
>> Second, it should clean up non-memory resources *as a fail-safe*. It
>> should close file descriptors, release shared locks, what have you,
>> but only to ensure that they weren't forgotten.
>
> If you can't be sure when finalize will be called, then these *fail-safe*
> activities aren't fail-safe at all. Waiting six years to clean up memory
> allocations that aren't managed by the collector, or waiting six years to
> clean up non-memory resources, even as a fall-back position, makes no sense,
> so there's no sense in coding the cleanup in a finalize. In fact, if you
> have to treat finalize as if it isn't going to be called for six years, then
> there's absolutely no practical use of finalize at all.
>
> So, if the garbage collector can be expected to run within a couple of
> seconds (or maybe even tens of seconds, if other application threads are
> busy computing away), it makes sense to use finalize for non-time-critical,
> fail-safe or fall-back resource deallocation. But if it can take *much*
> longer than that, then you either have to give up finalize completely, or
> declare the garbage collector defective.
>
> At least, that's the argument that suggests itself to me. But I'm not
> insisting on its validity, which is why I didn't go OT with it earlier.

My apologies, "fail-safe" is the wrong term. The proper term would be
"extra precaution" or something of the like. Belt-and-suspenders,
without a 100% assurance that your suspenders will hold after the belt
fails.

As for the practical use of finalizers, they certainly have a
practical use beyond the "extra precaution" for scare resources:
cleaning up non-GC memory resources, of which there are many. One of
the most common reasons to write a finalizer is to free some structure
allocated with malloc.

You might respond to this with, well, what if you malloc 2GB of memory
from a 16-byte object and the collector decides that this object never
needs to be destroyed? The answer is, don't do that.

You simply can't count on the collector to collect your objects in a
timely fashion. It would be perfectly reasonable to write a GC that
always keeps, say, 10% garbage around at any given time, with no
guarantee that it's always the freshest 10%. Under such a regime your
object may be deemed unimportant and *never* freed.

You may conclude that finalizers aren't really all that useful. And
you'd be right! That's why I keep saying that you shouldn't rely on
the finalizer to be useful for this task.

By the way, this is not in any way a unique feature of Apple's
collector. Indeed, it's found in virtually every collector out there,
and the uselessness of finalizers is a common theme in GC languages.

Mike
___

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

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


Re: Best way to get a non-repeating random number?

2009-04-13 Thread Michael Ash
On Mon, Apr 13, 2009 at 7:57 PM, Uli Kusterer
 wrote:
> On 14.04.2009, at 01:44, Luca C. wrote:
>>
>> You can put every (unsigned) value you want in there, though in
>> general it's used passing (unsigned)time(NULL) as parameter.  This way
>> you'll always get a different int.
>
>  No you won't. It's a *random* number generator. The seed simply means you
> get a different sequence of random numbers. However, random really means
> RANDOM. I.e. it's perfectly possible to get the same number three times in a
> row during a sequence. That would still be random.

Technically, I'm pretty sure you will always get a different int.
rand() is a crappy, crappy random number generator, and I would guess
that its algorithm can never return the same number twice in a row.

(If anyone is wondering what the alternatives are, use random() instead.)

>  I think it would be best if Eric told us what he's trying to do. For
> example, in some cases, (e.g. sorting) you actually want to build a new list
> and shuffle that by returning random numbers from your sort function. In
> that case, since your list only contains each item once, and your random
> numbers only affect their order, it's perfectly OK to just return a random
> number. You'll still get a shuffled list with each item only once.

I agree that we need to know what the need is. Note that writing a
proper shuffling algorithm is harder than it sounds. More properly,
it's easy, but figuring out whether you got the correct one or one of
the zillions of ones that look correct but aren't is difficult. So
look it up rather than trying to just wing it. The proper algorithm
definitely has no requirement that the random number generator not
return the previously used number.

Mike
___

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

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


Re: stopping an application

2009-04-13 Thread Bill Janssen
Nick Zitzmann  wrote:

> 
> On Apr 12, 2009, at 7:48 PM, Bill Janssen wrote:
> 
> > I was afraid of that...  Is there an easy way to do that from the
> > command line given its PID?
> 
> 
> Not really. First, you need a window server connection; you cannot
> send Apple events without one. Second, you need to get a PSN for the
> PID. Third, you need to craft and send a quit event to the PSN. The
> first thing can be accomplished by calling NSApplicationLoad(). For
> the other two, you can probably find sample code on the Web or in the
> archives.

Thanks.  This is pretty easy to do on the commandline with osascript:

  % osascript -e 'tell application foo to quit'

And instead of saying "foo", you can say,
"/Applications/Utilities/foo.app", or whereever it comes from.

  % osascript -e 'tell application "/Applications/Utilities/foo.app" to quit'

Still haven't figured out how to do it from the PID yet.  It's possible,
just not a one-liner.

Bill
___

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

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


Re: stopping an application

2009-04-13 Thread Bill Janssen
Greg Guerin  wrote:

> Bill Janssen wrote:
> 
> > I was afraid of that...  Is there an easy way to do that from the
> > command line given its PID?
> 
> Use the osascript command.
> 
> Form a query using a 'whose' clause to select the process ID.  I
> forget what the exact wording is, or whether to ask Finder or System
> Events, so you'll have to experiment.  To start, open the scripting
> dictionary of System Events and under its Processes Suite, choose the
> 'process' class and find its 'unix id' property.  That's the thing
> you need to use in a 'whose' clause.
> 
> Then tell that application to quit.

In other words, write a little "application quitter" tool in Applescript.

Should already be there, IMO.

Bill
___

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

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


Re: stopping an application

2009-04-13 Thread Bill Janssen
James W. Walker  wrote:

> tell app "System Events" to set x to file of first process whose unix
> id is 902
> tell app (POSIX path of x) to quit

Thanks, that "unix id is xxx" was what I was looking for.

> Hmm, now what did this have to do with Cocoa?

I didn't have to do this till I started using Cocoa.  It's not just
about UI :-).

Bill
___

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

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


Re: stopping an application

2009-04-13 Thread Bill Janssen
"From the command line"...

Luca C.  wrote:

> 2009/4/13 Bill Janssen 
> >
> >
> > I was afraid of that...  Is there an easy way to do that from the
> > command line given its PID?
> 
> 
> Using an AppleEvent given the appropriate bundle id of the application is
> actually pretty easy.I have found this in one my quite old project:
> 
> + (OSStatus)quitApplicationWithBundleID:(NSString *)aBundleID {
> 
>   OSStatus err;
> 
>   AppleEvent event, reply;
> 
>   const char *bundleIDString;
> 
> 
> 
>   bundleIDCString = [aBundleID UTF8String];
> 
> 
> 
>   err = AEBuildAppleEvent(kCoreEventClass, kAEQuitApplication,
> typeApplicationBundleID,
> 
>   bundleIDCString, strlen(bundleIDCString),
> kAutoGenerateReturnID,
> 
>   kAnyTransactionID, &event, NULL, "");
> 
> 
> 
>   if (err == noErr) {
> 
> err = AESendMessage(&event, &reply, kAENoReply, kAEDefaultTimeout);
> 
> AEDisposeDesc(&event);
> 
>   }
> 
>   return err;
> 
> }
> 
> 
> Haven't tested with Leopard yet, but I'm sure it works there.
> 
> 
> HTH
> 
> --Luca C.
> ___
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/janssen%40parc.com
> 
> This email sent to jans...@parc.com
___

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

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


Re: Best way to get a non-repeating random number?

2009-04-13 Thread Uli Kusterer

On 14.04.2009, at 02:36, Michael Ash wrote:

Note that writing a
proper shuffling algorithm is harder than it sounds. More properly,
it's easy, but figuring out whether you got the correct one or one of
the zillions of ones that look correct but aren't is difficult.



 Curious which ones look correct but aren't. Have any examples or a  
link to an article?


Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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

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


Re: NSMatrix of NSButtonCells prototype bindings not applied to instances in matrix

2009-04-13 Thread Ron Lue-Sang


On Apr 6, 2009, at 19:35 , Ben Golding wrote:



I've been trying to create a calendar matrix of days which are  
clickable to select a day in the month.  It's a something of a  
classic example of using NSMatrix from what I've read but I'm trying  
to use bindings to hook it up.


I am using an NSArrayController holding an array of NSButtonCell's  
which is connected as the NSMatrix's content.  I set the bindings on  
the NSMatrix's NSButtonCell prototype connecting the target to my  
controller object (to select the day) and also the enabled attribute  
to the NSButtonCell's isEnabled attribute.


The NSArrayController is populated with NSButtonCell's that I create  
with the correct date placement, etc, using copies of NSMatrix's  
prototype.


Sounds like you're trying to put view level objects into your array  
controller. Bindings don't work that way.
You should just be able to bind the matrix (I'm guessing you're using  
checkboxes) to an arrayController full of *model* objects. These  
objects can represent the days in the month and whether the day is  
selected.


Then the matrix…

 - contents come from the arrayController.arrangedObjects. This way,  
the number of button cells in the matrix will be determined by the  
number of Day objects in your arrayController.


 - contentValues are from the arrayController's arrangedObjects.name.  
These will provide the titles for the button cells. Again, this is  
based on the Day model objects in your arrayController.


 - selectedObjects is the array of model objects that were selected  
in the matrix by checking the day's checkbox button. You'll want to  
bind this property to some object that wants to find out which days  
the user chose. Maybe you have a viewController? With a read/write  
property like selectedDays? Then bind the matrix' selectedObjects  
binding to yourViewControllerInstanceInYourNibWhichMightBeFile'sOwner  
with the keypath selectedDays.


Hope that helps…



When the app runs, the bindings on the button cell instances in the  
matrix don't seem to be observed, that is, button presses aren't  
forwarded to the target and the enabled attribute is ignored.  If I  
set the bindings on the button cells within the NSMatrix directly  
(ie, not using the protoype), they are observed.


I don't quite get what I'm doing wrong.  Should I be creating my  
array of button cells using something other than copy to pick up the  
bindings?  Should I be asking the array controller to create the  
button cell instances?  Is there something that's not working in the  
NSMatrix prototype?  Or am I misunderstanding some concept?


Thanks,

Ben.


___

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

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


Re: stopping an application

2009-04-13 Thread Uli Kusterer

On 14.04.2009, at 02:42, Bill Janssen wrote:
% osascript -e 'tell application "/Applications/Utilities/foo.app"  
to quit'



 Avoid building and executing scripts if there's API. I hate tearing  
people a new one because they build a script and incorrectly escape  
special characters. E.g. imagine the path contained a space, or a  
quote character, all of which are valid. Heck, you can even have  
return characters in filenames, though they're not as easy to get  
these days.


Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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

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


Re: typeFromFileExtension in Leopard SDK

2009-04-13 Thread Eric Slosser


On Apr 13, 2009, at 5:29 PM, Kyle Sluder wrote:


Did you declare your com.comp.app.doc1 UTI as an exported type in your
Info.plist?


Nope.   Since you seemed to be suggesting that was the problem, I  
added the following to Info.plist.  But it didn't help.   Am I missing  
something?


UTExportedTypeDeclarations


UTTypeConformsTo

public.plain-text

UTTypeDescription
some description
UTTypeIdentifier
com.comp.app.doc1
UTTypeTagSpecification

public.filename-extension

doc1




UTImportedTypeDeclarations


UTTypeConformsTo

public.plain-text

UTTypeDescription
some description
UTTypeIdentifier
com.comp.app.doc1
UTTypeTagSpecification

public.filename-extension

doc1





___

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

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


Re: Best way to get a non-repeating random number?

2009-04-13 Thread Eric E. Dolecki
For an example I might want to generate numbers from 1 to 10 over and over.
All I want to do is when I generate a new number is not allow it to equal
the previously held value. I can imagine a few approaches but I just wanted
to make sure I was using the most accepted way of doing it.
E.

On Mon, Apr 13, 2009 at 8:46 PM, Uli Kusterer
wrote:

> On 14.04.2009, at 02:36, Michael Ash wrote:
>
>> Note that writing a
>> proper shuffling algorithm is harder than it sounds. More properly,
>> it's easy, but figuring out whether you got the correct one or one of
>> the zillions of ones that look correct but aren't is difficult.
>>
>
>
>  Curious which ones look correct but aren't. Have any examples or a link to
> an article?
>
> Cheers,
> -- Uli Kusterer
> "The Witnesses of TeachText are everywhere..."
> http://www.zathras.de
>
>
>
>
>
> ___
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/edolecki%40gmail.com
>
> This email sent to edole...@gmail.com
>



-- 
http://ericd.net
Interactive design and development
___

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

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


Re: Best way to get a non-repeating random number?

2009-04-13 Thread Michael Ash
On Mon, Apr 13, 2009 at 8:46 PM, Uli Kusterer
 wrote:
> On 14.04.2009, at 02:36, Michael Ash wrote:
>>
>> Note that writing a
>> proper shuffling algorithm is harder than it sounds. More properly,
>> it's easy, but figuring out whether you got the correct one or one of
>> the zillions of ones that look correct but aren't is difficult.
>
>  Curious which ones look correct but aren't. Have any examples or a link to
> an article?

The most obvious one is this:

for i in 0, length(array):
swap(array[i], array[random(length(array))])

It's probably the first thing you think of when you think "shuffle an
array", but it will produce biased results.

This can be seen if you look at the number of permutations. For
example, a 3-element array has 6 possible orderings. This algorithm
has 27 possible run sequences on a 3-element array (3**3). Since 27 is
not evenly divisible by 6, it's clear that some orderings will appear
more frequently than others.

Wikipedia has a decent discussion of both the proper way and why the
improper ways are improper here:

http://en.wikipedia.org/wiki/Shuffle#Shuffling_algorithms

Mike
___

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

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


Re: NSDocument reference held by NSSavePanel?

2009-04-13 Thread David Scheidt


On Apr 13, 2009, at 8:14 PM, Quincey Morris wrote:


On Apr 13, 2009, at 13:56, David Scheidt wrote:

In general, though, it's perfectly reasonable to put off garbage  
collection for as long as possible.  It's fairly expensive, and if  
there is no pressure on the resource being garbage-collected, it's  
perfectly reasonable to defer garbage collection until there is  
pressure.  There's a reasonable chance that the application will  
terminate before then, and then you've save the effort.  In  other  
words, it's not the clock that controls whether garbage collection  
need to run, it's the presence of garbage.


This is a perfectly reasonably argument, and perhaps it's the only  
argument. But I wasn't suggesting earlier that a garbage collector  
which doesn't collect as soon as possible (or nearly so) is  
defective, but that a garbage collector which defers some  
collections indefinitely implies that the finalize method is  
useless. (Or, equivalently, that if you want to use finalize, such a  
garbage collector is defective.)


My reasoning is that finalize is used to manage non-GC resources,  
not GC memory objects. With an indefinitely deferring collector,  
where you can't expect finalize to be called "soon", then you've  
already lost the game in terms of non-GC resource management  
(because non-GC resources don't exert any pressure on the  
collector), and you may as well abandon your finalize-based  
management strategy.


I don't think you should expect garbage collection to clean up non-GC  
objects; that extends to GC-objects that make use of non-GC objects  
(malloc'd structs, or whatever).  They should clean up after  
themselves, with -finalize being useful for code paths that you didn't  
think of, or if the objects get used in way that there's a case where  
you can't reasonably clean up.


The bright side is that the OS X VM system is pretty good, and if  
there is a system-wide memory shortage, the VM pager will do its best  
to keep your waste from effecting others's performance, and unless  
you're hitting an address space or process limit, yours.   (I'd also  
expect the GC to become more aggressive, but I don't have any  
information on that.)



___

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

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


Re: Need to find out why I get Cocoa error 256 . . .

2009-04-13 Thread Jeremy W. Sherman
Hi Michael,

You'll find the error defined in :
NSFileReadUnknownError = 256,   // Read
error (reason unknown)

—Jeremy

On Mon, Apr 13, 2009 at 10:25 AM, Michael A. Crawford
 wrote:
> Where can I find detail on the following error code?  Or, can someone point
> me to information on how to effectively debug a failure for a CoreData
> -[NSManagedObjectContext save] invocation?
>
> 2009-04-13 10:17:28.625 SpecialOrders[4923:20b] Failed to save context with
> new data: Error Domain=NSCocoaErrorDomain Code=256 UserInfo=0xf4b150
> "Operation could not be completed. (Cocoa error 256.)"
>
> -Michael
> ___
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/jeremyw.sherman%40gmail.com
>
> This email sent to jeremyw.sher...@gmail.com
>
___

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

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


Re: Need to find out why I get Cocoa error 256 . . .

2009-04-13 Thread Scott Anguish

Or, in the docs

search for it in Xcode's Documentation window


On 13-Apr-09, at 9:32 PM, Jeremy W. Sherman wrote:


Hi Michael,

You'll find the error defined in :
   NSFileReadUnknownError = 256,   // Read
error (reason unknown)

—Jeremy

On Mon, Apr 13, 2009 at 10:25 AM, Michael A. Crawford
 wrote:
Where can I find detail on the following error code?  Or, can  
someone point
me to information on how to effectively debug a failure for a  
CoreData

-[NSManagedObjectContext save] invocation?

2009-04-13 10:17:28.625 SpecialOrders[4923:20b] Failed to save  
context with

new data: Error Domain=NSCocoaErrorDomain Code=256 UserInfo=0xf4b150
"Operation could not be completed. (Cocoa error 256.)"

-Michael
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/jeremyw.sherman%40gmail.com

This email sent to jeremyw.sher...@gmail.com


___

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:
http://lists.apple.com/mailman/options/cocoa-dev/scott%40cocoadoc.com

This email sent to sc...@cocoadoc.com


___

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

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


Re: stopping an application

2009-04-13 Thread Jeremy W. Sherman
A caveat: typeApplicationBundleID just picks whichever target if there
is more than one instance of an app with the same bundle id running.
This can be the case if, for example, you're running both the current
version of PowerPoint and an older version. typeProcessSerialNumber
will always target the specified process.

To go from pid to PSN, you can use the Process Manager's
GetProcessForPID(). This will require you to link in -framework
ApplicationServices.

To send high-level events, you'll not only need to have a connection
to the window server, but, depending on what you're doing, the Mach
bootstrap namespace might also be an issue. See TN2083 "Daemons and
Agents" for further details.

—Jeremy

On Mon, Apr 13, 2009 at 8:45 PM, Bill Janssen  wrote:
> "From the command line"...
>
> Luca C.  wrote:
>
>> 2009/4/13 Bill Janssen 
>> >
>> >
>> > I was afraid of that...  Is there an easy way to do that from the
>> > command line given its PID?
>>
>>
>> Using an AppleEvent given the appropriate bundle id of the application is
>> actually pretty easy.I have found this in one my quite old project:
>>
>> + (OSStatus)quitApplicationWithBundleID:(NSString *)aBundleID {
>>
>>   OSStatus err;
>>
>>   AppleEvent event, reply;
>>
>>   const char *bundleIDString;
>>
>>
>>
>>   bundleIDCString = [aBundleID UTF8String];
>>
>>
>>
>>   err = AEBuildAppleEvent(kCoreEventClass, kAEQuitApplication,
>> typeApplicationBundleID,
>>
>>                           bundleIDCString, strlen(bundleIDCString),
>> kAutoGenerateReturnID,
>>
>>                           kAnyTransactionID, &event, NULL, "");
>>
>>
>>
>>   if (err == noErr) {
>>
>>     err = AESendMessage(&event, &reply, kAENoReply, kAEDefaultTimeout);
>>
>>     AEDisposeDesc(&event);
>>
>>   }
>>
>>   return err;
>>
>> }
>>
>>
>> Haven't tested with Leopard yet, but I'm sure it works there.
>>
>>
>> HTH
>>
>> --Luca C.
>> ___
>>
>> 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:
>> http://lists.apple.com/mailman/options/cocoa-dev/janssen%40parc.com
>>
>> This email sent to jans...@parc.com
> ___
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/jeremyw.sherman%40gmail.com
>
> This email sent to jeremyw.sher...@gmail.com
>
___

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

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


Re: Obvious NSSegmentedControl Bug?

2009-04-13 Thread Seth Willits


Filed. #6787552. Thanks.


--
Seth Willits




On Apr 13, 2009, at 4:17 PM, Peter Ammon wrote:

This looks like a bug.  I appreciate your taking the time to check  
and hopefully to file it.


-Peter

On Apr 12, 2009, at 1:22 PM, Seth Willits wrote:



I need a sanity check before I file a bug report.



sc is a 3-segment NSSegmentedControl with either Select One or  
Select Any as its mode. Segment 1 (the middle one) is selected in  
IB. Triggered as an action:



NSLog(@"Before:");
NSLog(@"  %d", [sc selectedSegment]);
NSLog(@"  %@", [sc isSelectedForSegment:0] ? @"YES" : @"NO");
NSLog(@"  %@", [sc isSelectedForSegment:1] ? @"YES" : @"NO");
NSLog(@"  %@", [sc isSelectedForSegment:2] ? @"YES" : @"NO");

[sc setSelected:NO forSegment:[sc selectedSegment]];

NSLog(@"After:");
NSLog(@"  %d", [sc selectedSegment]);
NSLog(@"  %@", [sc isSelectedForSegment:0] ? @"YES" : @"NO");
NSLog(@"  %@", [sc isSelectedForSegment:1] ? @"YES" : @"NO");
NSLog(@"  %@", [sc isSelectedForSegment:2] ? @"YES" : @"NO");


Before:
1
NO
YES
NO

After:
1
NO
NO
NO


selectedSegment: "[Returns t]he index of the currently selected  
segment, or -1 if no segment is selected."



No segment is selected so selectedSegment should clearly be -1,  
right?







___

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

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


Re: Best way to get a non-repeating random number?

2009-04-13 Thread Gwynne Raskind

On Apr 13, 2009, at 8:36 PM, Michael Ash wrote:

You can put every (unsigned) value you want in there, though in
general it's used passing (unsigned)time(NULL) as parameter.  This  
way

you'll always get a different int.
 No you won't. It's a *random* number generator. The seed simply  
means you
get a different sequence of random numbers. However, random really  
means
RANDOM. I.e. it's perfectly possible to get the same number three  
times in a

row during a sequence. That would still be random.

Technically, I'm pretty sure you will always get a different int.
rand() is a crappy, crappy random number generator, and I would guess
that its algorithm can never return the same number twice in a row.

(If anyone is wondering what the alternatives are, use random()  
instead.)


arc4random() is also pretty decent, if you need cryptographically  
strong random numbers.


-- Gwynne, Daughter of the Code
"This whole world is an asylum for the incurable."
___

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

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


Re: typeFromFileExtension in Leopard SDK

2009-04-13 Thread Michael Ash
On Mon, Apr 13, 2009 at 5:29 PM, Kyle Sluder  wrote:
> On Mon, Apr 13, 2009 at 5:15 PM, Eric Slosser  wrote:
>> I see in the release notes for Leopard that -[NSDocumentController
>> typeFromFileExtension:] is deprecated, but that doesn't mean "stops
>> working", does it?
>
> Not necessarily.

It's true that it doesn't mean that. Deprecated means that it's
officially discouraged, that it's likely to disappear the next time
Apple can do so without breaking binary compatibility (in the past
this has happened e.g. when moving to 64-bit) but that it will remain
available *and working* in the current environment.

Of course there is always the opportunity for bugs.

Mike
___

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

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


Re: NSDecimalNumber nil parameter to -decimalNumberByAdding: causes Mach exception EXC_BAD_ACCESS

2009-04-13 Thread Michael Ash
On Mon, Apr 13, 2009 at 5:29 PM, jonat...@mugginsoft.com
 wrote:
>
> On 13 Apr 2009, at 22:13, Kyle Sluder wrote:
>
>> On Mon, Apr 13, 2009 at 4:47 PM, jonat...@mugginsoft.com
>>  wrote:
>>>
>>> NSDecimalNumber *n2 = nil;
>>> n1 = [n1 decimalNumberByAdding:n2];
>>
>> You can't assume that nil is a valid argument.  So no, the lack of any
>> documentation stating that "passing nil will blow up" is not a bug.
>>
> Whatever way you slice it, bug or not, this is fairly toxic behaviour.

Call it what you like, but it's also extremely common behavior. A
crash due to passing a NULL pointer to where it is not explicitly
allowed is extremely common in C, and Objective-C is just an offshoot
of C. Your attitude should not be that you will only avoid passing nil
to methods which say it's not allowed. On the contrary: unless nil is
*explicitly* allowed, you *must not* pass it. The fact that some
methods explicitly disallow it does not change this fact.

Mike
___

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

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


Re: Autosaving the selection in an NSTableView

2009-04-13 Thread Volker in Lists

Hi Martin,

I archive the selectionIndexes of the array controller and store them  
within thecore data document's metadata. I think you need to serialize  
(archive) the selectionIndexes to be able to save it either in  
NSUserDefaults or anywhere else.


When loading a CD document I check if the meta data have the  
appropriate entry, and if  so, call the array controllers  
setSelectionIndexes method with a delay of 0.0 (to get it executed in  
the next run loop). Works like charm.


Volker


Am 13.04.2009 um 05:32 schrieb Martin Stanley:

I have a core-data document-based application that uses a  
NSTableView with an NSArrayController as its data source. I have  
managed to figure out the magic IB incantations required to save the  
column sort, order and hidden data to the shared NSDeafulsController.


What I would like to do is to also save the current selection of the  
table across application invocations. I have tried the obvious:
	- bind the array controller's selected indexes to the Shared  
Defaults controller - no luck
	- bind the tableview's selected indexes to the Shared Defaults  
controller - no luck
I even tried to get the select programmatically, but when I tried  
the callback methods I thought appropriate:

- windowControllerDidLoadNib
- applicationDidFinishLaunching
I found that the array controller was not yet loaded with data and  
therefore had no selection.



___

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

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


Re: NSSliderCell, lockFocus question

2009-04-13 Thread Frederik Slijkerman

Hi Uli,


Currently I'm porting a custom slider control that needs to draw parts
of the its interface, like the slider bar and the knob, in the OS style.
The code that I currently have draws this to a temporary bitmap to avoid
flicker on Windows and I'd like to keep it like this as much as possible
to avoid forking the code too much.


 If you can, get the codebase changed in some way that you can get rid 
of the Windows code that isn't needed on the Mac, e.g. by adding 
additional abstractions. It'll hurt much less in the long run.


I understand, but forking the code will hurt a lot, too. :-)

 That's what it basically does, so yes, this should work. That said, 
many cells expect to be hosted inside a view, and I'm not sure they'll 
work as well in any other graphics context. The main reason for cells to 
exist is not to draw outside views, but rather to support things like 
NSTableView, NSMatrix etc., where you draw several cells in a single 
view for efficiency reasons.


OK, thanks, I try it. I'm basically looking for an equivalent to
Carbon's HITheme API, which allows you to draw theme-compliant control
parts yourself, and it looks like cells are the way to achieve this with
Cocoa. It's just that it isn't obvious how to get it to work.

 Another option than a bitmap context (which is a rather low-level way 
to go about things) would be to just use an NSImage.


Yep, I saw that it has a lockFocus call as well. Again, for the existing
code base it's much easier to be able to work with low-level CG calls
instead of Cocoa objects. Cocoa is a great way to do things, but it's so
different from other APIs (such as Carbon or Win32) that it makes
porting very hard...

Best regards,
Frederik Slijkerman.


___

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

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