small medium large xlarge

Photo_6_pragsmall
16 May 2010, 14:07
Stephen Watson (30 posts)

Hello there :-)

Let’s say that I have a class, Item:

class Item : NSObject {

NSNumber *num1; NSNumber *num2;

}

and a class TwoItems:

class TwoItems: NSObject {

Item *item1; Item *item2; }

and finally a class BigController:

class BigController : UIViewController {

TwoItems *twoItems;

UILabel *someTextLabel; }

In -viewDidLoad I do this:

twoItems = [TwoItems alloc];

However, this means that item1 and item2 are 0x0

Later when I write:

self.twoItems.item1.num1 = 23; // Just as an example of an assignment

it doesn’t work because item1 is 0x0 and num1 is ‘out of scope’ and so the above makes no sense.

If I write +alloc and/or +init for TwoItems I can’t set item1 as that’s an instance variable and I’m in a class method.

Any ideas on the general pattern to follow here?

Thanks in advance?

You must be logged in to comment