On Mar 29, 2008, at 08:32, Davide Benini wrote:

- (void) dealloc
{
        [repetitions release];
        [variantEnding release];

        [body release];
        [super dealloc];
}
- (id) init
{
        self = [super init];
        if (self != nil) {
                repetitions = [[NSNumber alloc] init];
                variantEnding = [[NSNumber alloc] init];
                body = [[NSMutableArray alloc] init];
        }
        return self;
}

I assign their value when it is needed.
Let's say I have an instance of this class, called *thisObject. How do I check whether I have assigned a value to thisObject.variantEnding or if the property is inialized but empty?

There's no intrinsic "initialized but empty" state of Objective C objects. 'variantEnding' can be initialized to nil (or, rather, allowed to remain nil, since everything in a new object is guaranteed to be zeroes) or it can be given a NSNumber value.

If you really *need* an 'empty' state, you can choose to regard nil as 'empty' if it suits your purposes -- that's often how it's done -- or you can choose use a specific value to mean 'empty' (e.g. [NSNumber numberWithInteger:NSNotFound] might be a possibility).

By the way, '[[NSNumber alloc] init]' is not likely to be a useful way to initialize a NSNumber instance variable. The NSNumber object *has* a value, even if you don't care what the value is at that point, so you may as well be explicit.


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to