Re: Initializing an Array
Re: Initializing an Array
- Subject: Re: Initializing an Array
- From: Bob Savage <email@hidden>
- Date: Wed, 30 Jan 2002 00:37:58 -0600
on 1/29/02 10:31 PM, jgo wrote:
>
>
The Italians have an expression having to do with the
>
need for certain persons to eat a lot of bread.
I assure you I eat my fair share of it. :^/
>
Yes I most certainly do understand what classes are, what
>
self is and what super is.
Good. Because the code you posted earlier led me to believe otherwise :P
>
// only if self is not nil do we do our subclass' init
>
x = [[SomeOtherClassWhichWasIntroducedForSomeUnknownReason
>
alloc] init]; // for example
>
>
// but wait, we are in the init for ThisClass, already
>
// so we need to init self's iVars...
>
// unless you meant "x" to be self's iVar?
>
}
Exactly, x is an example of an ivar -- which is the whole purpose of the if
block. Your example showed a test for nil which led conditionally to another
attempt to create an instance of the same class inside of a failed init
method. which is not what you want to do.
Bob :feels like eating something made out of flour: