1.常量:使用let声明
let str = "kuangjunjie"
2.变量:使用var声明
var str = "kuangjunjie"
3.整型
有符号整形:Int,Int8,Int16,Int32,Int64
无符号整形:UInt,UInt8,UInt16,UInt32,UInt64
4.浮点型
Float:32位浮点数类型
Double:64位浮点数类型
5.布尔型:Bool
let bool1 = true
let bool2 = false
6.字符串
// (1)判断是否为空:isEmpty
let str = ""
if str.isEmpty {
print("空字符串")
}
// (2)获取字符数量: str.characters.count
let str = "kuangjunjie"
print("\(str.characters.count)个字符")
// (3)检查字符是否有特定的前缀/后缀:
let str = "kuangjunjie"
if str.hasPrefix("kuang") {
print("str字符串有kuang前缀")
}
if str.hasSuffix("jie") {
print("str字符串有jie后缀")
}
//(4)还可以用“\()”在字符串里包裹变量,常量
let age = "18"
let say = "我永远\(age)岁"
// (5)大小写转换:通过字符串的uppercaseString、lowercaseString属性来访问一个字符串的大写/小写
let str = "name: Kuangjunjie"
var uppercasedStr = str.uppercased()//NAME: KUANGJUNJIE
var lowercasedStr = str.lowercased()//name: kuangjunjie
7.字符: Character
var character : Character = "@"
8.元组: ( , )
let tuple = (frist: "1",second:"2")
print(tuple.frist) // 1