Re: Display NSImage in a NSTableView
Re: Display NSImage in a NSTableView
- Subject: Re: Display NSImage in a NSTableView
- From: Fritz Anderson <email@hidden>
- Date: Wed, 27 Jun 2007 12:00:43 -0500
On 27 Jun 2007, at 10:11 AM, Frederic JECKER wrote:
NSImage *image=[[NSImage alloc]init];
[image initByReferencingFile:path];
This is wrong.
init* methods are free to return objects other than the ones they
were called on. If you were to do this:
NSImage * image1 = [NSImage alloc];
NSImage * image2 = [image1 init];
NSImage * image3 = [image2 initByReferencingFile: path];
There is no guarantee that any of the NSImage pointers will be equal
to any other. They could all be separate objects. In fact, in
NSImage, I'd expect it.
Also, the attempt to re-initialize image2 (the third line) will
probably result in a crash or serious bug.
Search the Cocoa documentation for "class cluster" for a detailed
explanation.
The explanation should also make clear why passing more than one
init* message to an object will probably break your program.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden