What is the importance withe if (!_assets)


#1

Hello

In the BNREmployee.m I create a if verification. But what is the interest of this verification? And what return !_assets?

[code]- (void)addAsset:(BNRAsset *)a
{
// Is assets nil?
if (!_assets) {

    // Create the array
    _assets = [[NSMutableArray alloc] init];
}
[_assets addObject:a];

} [/code]


#2

[quote][code]- (void)addAsset:(BNRAsset *)a
{
// Is assets nil?
if (!_assets) {

    // Create the array
    _assets = [[NSMutableArray alloc] init];
}
[_assets addObject:a];

}[/code][/quote]
That if statement says: If the _assets array has not been created, create it now; otherwise, skip.

The meaning of the expression !_assets: the value of the expression will be true (nonzero) if the value of the _assets expression is nil (zero), otherwise it will be false (zero).


#3

thank you :slight_smile: