|Subject:||Re: Question about object initialization and autorelease|
|Date:||Fri, 30 Mar 2012 15:16:55 -0600|
I've been reading the tutorials at http://www.gnustep.it/nicola/Tutorials/ and trying them out from memory, but using ProjectCenter instead of manually creating the GNUMakefile. When running my app, I kept getting an illegal operation. Upon closer inspection, I found the problem to be the following line:
AUTORELEASE doesn't initialize an object; AUTORELEASE(x) is the same as [x autorelease] - so you don't want to send the -autorelease message to an uninitialized NSWindow. What you probably want on that line is to call the NSWindow initializer, -initWithContentRect:styleMask:backing:defer:.
Also, coming from a iOS background, I am used to seeing [[objectClass alloc] init] for initialization, yet in GNUStep, it is done with [new]. What's the difference? Or when should I use [[alloc] init]?
There is no difference; [x new] is the same as [[x alloc] init].
However, my suggestion is to stick to [x autorelease] and [[x alloc] init] instead of AUTORELEASE(x) or [x new].
Hope this helps,
|[Prev in Thread]||Current Thread||[Next in Thread]|