美文网首页
swift 语法

swift 语法

作者: ByteBunny | 来源:发表于2019-02-28 23:51 被阅读0次

变量

  • type inference
    var swiftString = "swift is fun"
    var hours = 24
    var PI = 3.14
    var swiftFun = true
    var me = ("Mars", 11, "989791040@qq.com")
    me.0 = "Mars"
    me.1 = 11
  • type annotation
    var str: string
    var x: int

常量

let minute = 30
let fireIsHot = true

整数

(u)int 8, (u)int 16, (u)int 32, (u)int 64.
通常用int or uint即可,swift编译器会根据目标平台把int or uint转换为对应的整数类型

浮点数

  • float:精确到小数点后6位*
  • double: 精确到小数点后15位
    一般尽可能使用double表示浮点数类型
  • 推断类型:
    var four = 4
    type(of:four) int.Type

相关文章

网友评论

      本文标题:swift 语法

      本文链接:https://www.haomeiwen.com/subject/wpiiyqtx.html