Re: how to check if a property is empty?
Re: how to check if a property is empty?
- Subject: Re: how to check if a property is empty?
- From: Quincey Morris <email@hidden>
- Date: Sat, 29 Mar 2008 10:04:38 -0700
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@hidden)
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:
This email sent to email@hidden