The difference between a variable set to nil and 0

if (myFloat == nil){
    \\Do Method
}

In the above situation, the method will work only if myFloat- nil. Will it start if the parameter is myFloatset to 0?

+3
source share
2 answers

nil should only be used with pointers. It indicates that the pointer is not set to a value.

Floats and other types of C just matter. (Strictly swims and doubles, maybe it can have values ​​like NaN, but it's harder to manage)

In Objective-C, you can put a float in the NSNumber class. An object of this class refers to a pointer, so a variable of type NSNumber * may be nil.

+2

, 0. myFloat. myFloat C, , . nil id.

0

Source: https://habr.com/ru/post/1750420/


All Articles