美文网首页
swift-基本数据类型

swift-基本数据类型

作者: 不写昵称 | 来源:发表于2018-08-28 22:30 被阅读0次

基本数据类型
1、Int 整型
2、Float, Double 浮点型(分别为精确到6位和15位小数)
3、String 字符串类型 无“@”符号
4、Bool(true, false) 布尔类型,不能用0、1表示

swift中,如果开发环境是32位,那么Int = Int32,如果开发环境是64位,那么Int = Int64,Int16表示2字节(16位)的整形
Float--4字节32位
Double--8字节64位,不写明类型,则默认double
Bool--1字节8位

获取类型长度:
swift2.0:sizeof( Int)
swift3.0: 没有了sizeof,改用MemoryLayout结构体

方法1:print(MemoryLayout<Int>.size)
方法2:let a:Int16 = 100;print(MemoryLayout.size(ofValue: a))
方法3:
var b = MemoryLayout<Int>.size b = 12; print(MemoryLayout.size(ofValue: b))

swift打印方式
1、print(),可直接输出字符串,基本数据类型,如print("he")/print(12)/print(a),没有%@,%d等格式符
2、NSLog("%d", 12):不用“@”,要用格式符,句尾不用“;”,不能直接输出基本数据类型

相关文章

  • swift-基本数据类型

    基本数据类型1、Int 整型2、Float, Double 浮...

  • C++基础

    1.C的基本数据类型 java基本数据类型 C基本数据类型 基本数据类型所占字...

  • 2019年安卓面试题--------Java 基础篇

    java 的基本数据类型 java的数据类型分为基本 数据类型和 引用数据类型基本数据类型: byte sho...

  • Java基本数据类型转换

    一:Java的基本数据类型和引用数据类型 1:基本数据类型 2:引用数据类型 二:基本数据的类型转换 基本数据类型...

  • Swift-数据类型

    注意:在swift中,是不存在基本的数据类型的,所谓的数据类型,其实都只是结构体。 下表列举的是常见的数据类型变量...

  • Hive-3.1.2(三)数据类型

    常用的基本数据类型 基本数据类型所占字节intbooleanfloatdoublestring 复杂数据类型 基本...

  • Kotlin学习第一天

    打印HelloWorld 基本数据类型代码展示: kotlin只有基本数据类型 没有包装数据类型 基本数据类型范...

  • java数据类型(八种基本数据类型+三种引用类型)

    数据类型分类 java数据类型分为基本数据类型和引用数据类型 基本数据类型 基本数据类型包括4个分类,分配的存储空...

  • JS数据类型判断

    js中可以通过typeof来判断基本的数据类型。 数据类型 js的数据类型分为基本数据类型和引用数据类型,基本数据...

  • Java基础数据类型和引用类型的区别

    一、数据类型 Java中的数据类型分为两大类,基本数据类型和引用数据类型。 1、基本数据类型 基本数据类型只有8种...

网友评论

      本文标题:swift-基本数据类型

      本文链接:https://www.haomeiwen.com/subject/edjcwftx.html