1.2 Swift基本数据类型
/** 基本数据类型:整数类型 和 小数类型 Int Int8 Int16 Int32 Int64
UInt UInt8 UInt16 UInt32 UInt64 */ let integer : Int = 10
// -19 的话系统会自动报错 let unInteger :UInt32 = 19
print(integer) print(unInteger)
// 溢出 也有自动提示的 // let overValue: UInt8 = UInt8.max + 1; // print(overValue)
/** 小数类型 也就是浮点数类型 */
let floatValue:Double = 3.2 print(floatValue)
/** 两种基本类型可不可以进行隐式转换 系统提示不可以 */ let intVar: Int = 10 // var doubleVar : Double = intVar print(intVar)
/** 类型推断和类型安全 let str = "world" 这样子写也可以的,它会自动推断出是字符串类型 */ let stringValue: String = "Hello"
let UInt8Value: UInt8 = 9 let UInt16Value: UInt16 = 9 // 在C语言里这个是可以做的,在这里却不可以以 // var UInt32Value:UInt32 = UInt8Value + UInt16Value; // 必须都改成统一类型的
print(stringValue) print(UInt8Value) print(UInt16Value) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |