swift出世时,断断续续看了一些。在PlayGround耍了耍还是挺好玩的:]
有OC作为基础,上手swift还是挺快的。但是有一些语法还是要留意下。这个就作为学习笔记吧,记录学习过程中的注意点。
swift官网
The Swift Programming Language
if nil
在OC中我们在判断一个值是不是nil时,一般就是
但在swift中,是会报错的
Apple 在GuidedTour中写道:
In an if statement, the conditional must be a Boolean expression—this means that code such as if score { … } is an error, not an implicit comparison to zero.
You can use if and let together to work with values that might be missing. These values are represented as optionals. An optional value either contains a value or contains nil to indicate that a value is missing. Write a question mark (?) after the type of a value to mark the value as optional.
正确的写法
这样写也可以
In-Out Parameters
函数中的输入输出参数,可以改变函数参数。
|
|
好奇的看下内存地址有没有改变
before swap:0x00007fff595d6ac0, value:3)
after swap:0x00007fff595d6ac0, value:107
结果内存中的地址是没有变的
###
|