I am trying to detect if an array isn’t empty in order to be able to do a certain call.
I tried using if (![array ==nil]) however that doesn’t compile.
I’m sure there is a really easy explanation to this.
Update
If array is empty I want to do this:
array = [[NSMutableArray alloc]init];
If it has an object I want to do this:
array = [[userDefaults arrayForKey:@"MyFavorites"] mutableCopy];
If you declared it but did not assign anything to it at all:
Then the array will be
nil, meaning it isn’t there at all so you can’t say if it’s empty or not, so you can’t check anything.If you did assign something to it, and you want to find out if the existing array is empty or not, that would depend on how you created it first.
If the array was assigned from some convenience method, it’s autoreleased, so just do this:
If the array was assigned from an init or copy method, or it was retained previously, store the count in a temporary variable, release the array and use the temporary variable to decide what to do: