网站大量收购独家精品文档,联系QQ:2885784924

第三章 swift 2.2学习之基本数据类型.pdf

  1. 1、本文档共5页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
在线学习好工作 / swift 2.2 学习之基本数据类型 整数 1.分为有符号整数和无符号整数; 2.有符号: Int8 Int16 Int32 Int64 Int; 3.无符号: UInt8 UInt16 UInt32 UInt64 UInt。 整数类型区别 1.在内存占用空间不同(sizeof(Type)获取); 2.表达的数据范围不同(可用min,max 属性获取)。 Tips 1.特殊整数类型Int,长度与当前平台原生字长一致; 2.32 位机,sizeof(Int)等于sizeof(Int32) ; 3.64 位机,sizeof(Int)等于sizeof(Int64) ; 4.UInt 类似; 5.习惯在一般情况下使用Int,来提高代码一致性和可复用性。 浮点数 1.Float 32 位浮点数; 2.Double 64 位浮点数。 布尔值 Bool(true false) 其他 1.类型转换; 2.类型别名; 3.类型安全。 swift 是类型安全的语言,在编译时进行类型检查。 代码实例 //: Playground - noun: a place where people can play import UIKit //: 声明整数并观察类型推倒结果 let intVal = 1 intVal.dynamicType let int8Val : Int8 = 1 let int16Val : Int16 = 1 let int32Val : Int32 = 1 let int64Val : Int64 = 1 let intVal1 : Int = 1 print(Int8 \t size: \(sizeof(Int8)) \t min: \(Int8.min) \t\t\t\t\t max: \(Int8.max)) print(Int16 \t size: \(sizeof(Int16)) \t min: \(Int16.min) \t\t\t\t max: \(Int16.max)) print(Int32 \t size: \(sizeof(Int32)) \t min: \(Int32.min) \t\t\t max: \(Int32.max)) print(Int64 \t size: \(sizeof(Int64)) \t min: \(Int64.min) max: \(Int64.max)) print(Int \t size: \(sizeof(Int)) \t min: \(Int.min) \t max: \(Int.max)) var uint8Val : UInt8 = 1 var uint16Val : UInt16 = 1 var uint32Val : UInt32 = 1 var uint64Val : UInt64 = 1 print(UInt8 \t size: \(sizeof(UInt8)) \t min: \(UInt8.min) \t max: \(UInt8.max)) print(UInt16 \t size: \(sizeof(UInt16)) \t min: \(UInt16.min) \t max: \(UInt16.max)) print(UInt32 \t size: \(sizeof(UInt32)) \t min: \(UInt32.min) \t max: \(UInt32.max)) print(UInt64 \t size: \(sizeof(UInt64)) \t min: \(UInt64.min) \t max: \(UInt64.max)) print(UInt \t size: \(sizeof(UInt)) \t min: \(UInt.min) \t max: \(UInt.max)) let dVal = 1.1 dVal.dynamicType let floatVal : Float = 1.1 let DoubleVal : Double = 1.1 print(Float \t size: \(sizeof(Float))) print(Double \t size: \(sizeof(Double))) let decimalVal = 10 let bi

文档评论(0)

0520 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档