Skip navigation.
 
mlRe: how to check if a property is empty?
FROM : Quincey Morris
DATE : Sat Mar 29 18:04:38 2008

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.

Related mailsAuthorDate
mlhow to check if a property is empty? Davide Benini Mar 29, 16:32
mlRe: how to check if a property is empty? Quincey Morris Mar 29, 18:04
mlRe: how to check if a property is empty? Davide Benini Mar 29, 18:11
mlRe: how to check if a property is empty? Jens Alfke Mar 29, 18:16
mlRe: how to check if a property is empty? Jens Alfke Mar 29, 18:22