Swift 基本数据类型,常/变量声明(一)

来源:互联网 发布:win7一拖二软件 编辑:程序博客网 时间:2024/04/27 23:28

https://github.com/Zhangjingwang1993/Swift.git
/// 项目不太忙, 撸撸Swift

变量 使用var声明

var str:String = "dd"str = "GG"print(str)

常量 使用let声明

let count:Int = 16print(count)

整型

Int, Int8, Int16, Int32, Int64UInt, UInt8, UInt16, UInt32, UInt64

浮点型 ,布尔型

Float, Double, Bool

获取字符串的数量 // str = GG

print(str.characters.count) // 2

检查字符串是否有特定的前缀和后缀 pre/suf

let sttPre = "hello.com"if sttPre.hasSuffix(".com33"){   print("YES")  }else{   print("NO")       }

还可以”()”

let name1 = "helloworld"let msg = "Welcome to \(name1)"print(msg) // Welcome to helloworld

大小写转换

通过字符串的uppercaseString、lowercaseString、capitalizedString属性来访问一个字符串的大写/小写/首字母大写

字符

var char:Character = "$"print(char)

元组

let myCode = (one:"ZJwang", two:123)print("\(myCode.one)")
4 0
原创粉丝点击