数据类型 swift

1整形
Int,Int8,Int16,Int32,Int64
UInt,UInt8,UInt16,UInt32,UInt64
其中Int,UInt始终和当前平台的原生字长相同(32位机,64位机)
查看属性
UInt8.min
UInt8.max
初始化
var sampleInteger:Int
var tmpInteger = 12
var tmpInteger = Int.init(12)

let binaryInt:Int = 0b10001
let octalInt:Int = 0o21
let hexadecimalInt:Int = 0x11

let bignum_a = 1000000
let bignum_b = 1_000_000
let bignum_c = 1_0000_0000

2浮点型
Float
Double(默认)

let float_a = 0.012
let float_b = 1.2e-2

3布尔
Bool

4字符串
String
字符串插值
println("The current value of friendlyWelcome is (friendlyWelcome)")
// 输出 "The current value of friendlyWelcome is Bonjour!
计算长度countElements()
比较字符串可以用 ==
hasPrefix() hasSuffix()判断是否有前缀和后缀
uppercaseString() lowercaseString()
isEmpty属性
capitalizedString(每个单词首字母大写,需要导入Foundation库)
stringByTrimmingCharactersInSet() (trim)
componentSeperatedByString() (split)
//join
var str4 = "-"
str4.join(["1","2","4"])
rangeOfString() 匹配查找
substringToIndex()
substringFromIndex()
substringWithRange()
insertIndex()
insert()
removeAtIndex()
removeRange()
replaceEndIndex()

5字符
Character

6可选
Optional 等同于type?

7元组

类型别名
typealias ShortInteger = Int8

posted @ 2016-12-17 00:01  乱笙歌  阅读(140)  评论(0编辑  收藏  举报