Re: Newbie Question re Allocation & Initialization

2008-05-19 Thread Nick Zitzmann
On May 19, 2008, at 7:07 PM, Brad Gibbs wrote: It all makes perfect sense, I just didn't know that not alloc'ing and init'ing was a fully legit move. Well, you do need to set the pointer to point to something, or else accessing it will in the best case raise an exception, and in the wor

Re: Newbie Question re Allocation & Initialization

2008-05-19 Thread Brad Gibbs
Thanks to all who replied. It all makes perfect sense, I just didn't know that not alloc'ing and init'ing was a fully legit move. I will add Masters of the Void to the already tall stack of reading material. On May 19, 2008, at 6:03 PM, Jack Repenning wrote: On May 19, 2008, at 5:18 PM,

Re: Newbie Question re Allocation & Initialization

2008-05-19 Thread Jack Repenning
On May 19, 2008, at 5:18 PM, Brad Gibbs wrote: Is it because numberToPrint is simply pointing to newNumber objects in the array that have already been allocated and initialized? Yes, both newNumber and numberToPrint are merely pointers to some object. These objects are created in the first

Re: Newbie Question re Allocation & Initialization

2008-05-19 Thread Simon Wolf
On 20 May 2008, at 01:18, Brad Gibbs wrote: On pages 36-7 of Aaron Hillegass' new book, he provides sample code for a Foundation Tool called Lottery. The code is below: NSMutableArray *array; array = [[NSMutableArray alloc] init]; int i; for (i = 0; i < 10; i++) {

Re: Newbie Question re Allocation & Initialization

2008-05-19 Thread Frank McGeough
The first loop is allocating an object an initializing it with the value of the loop variable (i) multiplied by 3. The second loop is just assigning a pointer to that allocated object. It could have also been written : for (i = 0 i < 10; i++) { NSLog(@"The number at index %d is %@", i,

Re: Newbie Question re Allocation & Initialization

2008-05-19 Thread Nick Zitzmann
On May 19, 2008, at 6:18 PM, Brad Gibbs wrote: It compiled and ran as expected, too. But, when I tried to eliminate allocation and initialization for newNumber in the first 'for loop', the app threw an exception. I don't see an explanation in the book re why numberToPrint can be, but doe

Newbie Question re Allocation & Initialization

2008-05-19 Thread Brad Gibbs
On pages 36-7 of Aaron Hillegass' new book, he provides sample code for a Foundation Tool called Lottery. The code is below: NSMutableArray *array; array = [[NSMutableArray alloc] init]; int i; for (i = 0; i < 10; i++) { NSNumber *newNumber = [[NSNum