Sei sulla pagina 1di 1

Its often very useful to have variables that can sometimes have no value.

For exa
mple, you might have a variable that stores a number to display to the user, but
you dont know what that number is yet. As weve seen already, Swift variables need
to have a value. One solution might be to use the number zero to represent no va
lue; indeed, many languages, including C, C++, Java, and Objective-C, do just thi
s. However, this creates a problem: there is no way to distinguish between the v
alue zero and no value at all. What if the value you want to show is actually ze
ro?
To deal with this issue, Swift makes a very clear distinction between no value and
all other values. No value is referred to as nil and is a different type from all
others.

While the publisher and the authors have used good faith efforts to ensure that
the information and instructions contained in this work are accurate, the publis
her and the authors disclaim all responsibility for errors or omissions, includi
ng without limitation responsibility for damages resulting from the use of or re
liance on this work. Use of the information and instructions contained in this w
ork is at your own risk. If any code samples or other technology this work conta
ins or describes is subject to open source licenses or the intellectual property
rights of others, it is your responsibility to ensure that your use thereof com
plies with such licenses and/or rights.

Potrebbero piacerti anche