• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa Open GL help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa Open GL help


  • Subject: Re: Cocoa Open GL help
  • From: email@hidden
  • Date: Wed, 12 Sep 2001 19:27:38 -0700

Le mercredi 12 septembre 2001, ` 08:53 , Vince DeMarco a icrit :
> Yes this is true. If you select a NSButton and in IB make a subclass of
> NSButton called MyButton, when you set the custom class of NSButton to
> MyButton, we actually write out (encode) and NSButton, but tell
> NSArchiver to swap an instance of NSButton with MyButton.

The way I manage this aspect of IB use is to override initWithCoder: ,
because I think that the code intrinsic to the initialization of an
object need to be in the init method, not in awakeFromNib.

But in initWithCoder you have to take care if you are unencoding an
object from a nib file that is not aware of the real class of your
object.

For example when I use NSOpenGLView instance from the IB palette, to set
easily the pixel format, I override initWithCoder as following:

//
**************************************************************************
***

- (id)initWithCoder:(NSCoder*)aCoder
{
self = [super initWithCoder:aCoder];

// if the class doesn't exist in the archive then we need to
completely initialize the instance, it means that we are unarchiving
from a Nib for example
if ([aCoder versionForClassName:@"GI3DKitView"] == NSNotFound){
// specific initialization

GILog(@"GI3DKitView unarchiving specific initializing");
camera = [[G3DCamera alloc] initWithSize:[self frame].size];
[camera setRenderDelegate:self];
[self syncCamera];
}

return self;
}



Because I know that if a coder don't know the version number of my real
class, then I need to initialize the specific part of the object as it
would be the specific part of the normal init method. And the interest
of this method is that it is not related specifically to nib unarchiving.

Hope that this will help.

Sincerely.

Gerard

PS: I don't know the exact word, but my though for american people,
regardless of ideology and this kind of things. A very bad day for all
of us.


References: 
 >Re: Cocoa Open GL help (From: Vince DeMarco <email@hidden>)

  • Prev by Date: Re: *That* book
  • Next by Date: Re: an interesting delegate design issue raised by IB...
  • Previous by thread: Re: Cocoa Open GL help
  • Next by thread: RE: Cocoa Open GL help
  • Index(es):
    • Date
    • Thread