I have a sample app which i downloaded from net
In this i was unable to understand following code
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
also
if (!array1)
return;
does this code means if object does not exists then return…..
HELP
In Cocoa, an initialiser will either return an object pointer if the call was successful, or a nil if it was unable to create the object.
Both cases are checking for the existence of the object. Actually, checking for the existence of a pointer to the object and simply returning if the object does not exist. As an example, here is a common form of initialiser for an object.
However, the snippets you have provided are not enough to tell whether the code is correct. For example, the first example is incorrect if it is part of an initialiser method because it is not returning any kind of object.
Edit
From your further examples both of these print hiiiiiiii
and
In the first case you are declaring arr to be a pointer to an NSArray, but because it hasn’t been initialised this pointer is just a garbage value of random numbers. But it isn’t
nilSo your if-statement evaluates as true. That doesn’t mean that it is a valid pointer to an NSArray.In your second example you declare an NSArray pointer and initialise it. This was successfully initialised so the pointer is not nil and the if-statement evaluates as true. In this case you do have a valid NSArray pointer.
Declaration is not initialisation!
Maybe if you explain what it is that you are trying to do we’ll be able to better answer your questions.