if (myFloat == nil){
\\Do Method
}
In the above situation, the method will run only if myFloat
is nil
. Will it also run if myFloat
was set to 0
?
if (myFloat == nil){
\\Do Method
}
In the above situation, the method will run only if myFloat
is nil
. Will it also run if myFloat
was set to 0
?
Well, nil is technically 0. However, some of this depends on what type of variable myFloat is. If myFloat is a C float, you can't depend on it being exactly 0. You really should be using nil on id types.
nil only should be used with pointers. Baiscally if says the pointer has not been set to a value.
Floats and other C types just have a value. (Strictly flotas and double possibly can have values like NaN but this is more difficult to manage)
In Objective C you can wrap a float in a class NSNumber. An object of this class is referenced by a pointer so a variable of type NSNumber* can be nil.