ios8 swift开发:let var 区别讨论

时间:2014-07-01 14:23:25   收藏:0   阅读:443
localhost:~ hejiasheng$ xcrun swift
Welcome to Swift!  Type :help for assistance.
  1> var a:Int
a: Int = 0
  2> let b:Int
<REPL>:2:5: error: ‘let‘ declarations require an initializer expression
let b:Int
    ^

  2> let b = 5
b: Int = 5
  3> b = 6
  4> println(6)
6

5> println(b)

6

 

很多地方说 let 变量不能改变,我测试发现可以改变。

但定义时候需要 初始化。

bubuko.com,布布扣


playground 情况下,会报错。 能负值。


ios8 swift开发:let var 区别讨论,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!