一、数据类型

1、基础类型的封装

Swift provides its own versions of all fundamental C and Objective-C types, including Int for integers, Doubleand Float for floating-point values

2、新类型

Swift introduces advanced types not found in Objective-C, such as tuples.

Tuples enable you to create and pass around groupings of values.

3、类型安全语言

Swift is a type-safe language, which means the language helps you to be clear about the types of values your code can work with.

4、数据类型转化

  1. let three = 3
  2. let pointOneFourOneFiveNine = 0.14159
  3. let pi = Double(three) + pointOneFourOneFiveNine
  4. // pi equals 3.14159, and is inferred to be of type Double

5、Tuples

  1. let http404Error = (404, "Not Found")
  1. let (statusCode, statusMessage) = http404Error
  2. print("The status code is \(statusCode)")
  3. // Prints "The status code is 404"
  4. print("The status message is \(statusMessage)")
  5. // Prints "The status message is Not Found"

6、Optionals

  1. let possibleNumber = "123"
  2. let convertedNumber = Int(possibleNumber)

  类型推断 convertedNumber:Int?

7、Optional Binding

  if let firstNumber = Int("4")

  You use optional binding to find out whether an optional contains a value

8、Implicitly Unwrapped Optionals

. You write an implicitly unwrapped optional by placing an exclamation mark (String!) rather than a question mark (String?) after the type that you want to make optional.

swift语言点评二的更多相关文章

  1. swift语言点评二十一-协议

    定义有什么,及哪些必须实现. A protocol defines a blueprint of methods, properties, and other requirements that su ...

  2. swift语言点评二十-扩展

    结论:扩展无法修改原来的数据结构. Extensions can add new functionality to a type, but they cannot override existing ...

  3. Swift语言指南(二)--语言基础之注释和分号

    原文:Swift语言指南(二)--语言基础之注释和分号 注释 通过注释向自己的代码中注入不可执行的文本,作为你自己的笔记或提示.Swift编译器运行时会忽略注释. Swift的注释与C语言极其相似,单 ...

  4. swift语言点评十二-Subscripts

    Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the m ...

  5. swift语言点评四-Closure

    总结:整个Closure的作用在于简化语言表述形式. 一.闭包的简化 Closure expression syntax has the following general form: { () -& ...

  6. swift语言点评一

    一.变量定义 1.常量与变量 Use let to make a constant and var to make a variable. 2.类型与推测 However, you don’t alw ...

  7. swift语言点评十九-类型转化与检查

    1.oc比较: -(BOOL) isKindOfClass: classObj判断是否是这个类或者这个类的子类的实例 -(BOOL) isMemberOfClass: classObj 判断是否是这个 ...

  8. swift语言点评十八-异常与错误

    1.错误类型与枚举的结合 enum VendingMachineError: Error { case invalidSelection case insufficientFunds(coinsNee ...

  9. swift语言点评十七-Designated Initializers and Convenience Initializers

    Swift defines two kinds of initializers for class types to help ensure all stored properties receive ...

随机推荐

  1. HDU 2111 Saving HDU【贪心】

    解题思路:排序后贪心,和fatmouse's  trade 类似 Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: ...

  2. 学习ZBrush到底需不需要用数位板?

    在学习ZBrush时,要控制下笔的力度,而这一点是鼠标办不到的.这时就需要拥有一块手绘板.手绘板可以控制笔刷的力度. 在雕刻之前,要先来了解CG设计领域广泛应用的硬件产品—数位板,如图所示. 数位板又 ...

  3. day01 编程概述及计算机组成原理

    目录 编程概述 计算机硬件的五大组成部分 Central Processing Unit(cpu中央处理器) 存储器 输入,输出设备 打开QQ的流程 计算机五大组成部分补充 多核CPU ×64/x86 ...

  4. 注解实战aftersuite和beforesuite

    package com.course.testng;import org.testng.annotations.*; public class BasicAnnotation { //最基本的注解,用 ...

  5. oracle中nvl函数用法

    1.返回两个字段中非空字段的值,第一个字段非空,返回第一个字段的值,第二个字段值为null,则返回第二个字段的值,如果都为null 则返回null. select nvl(a,b) from tabl ...

  6. IOS - Autorelease for CGMutablePathRef?

    http://stackoverflow.com/questions/2819548/autorelease-for-cgmutablepathref Autorelease pools exist ...

  7. IOS - No provisioning profiles with a valid signing identity 一种解决方法

    1.删除原有“钥匙串访问”中疑是过期的的证书: 2.在Member Center中Certificate中删除疑是有问题的Certificate,重新添加新的Certificate: 3.在“钥匙串访 ...

  8. HTML中使用 js 添加 data-toggle

    情况:<li class="active"><a href="#server1" data-toggle="tab"> ...

  9. python基础知识部分练习大全

    python基础知识部分练习大全   1.执行 Python 脚本的两种方式 答:1.>>python ../pyhton.py 2. >>python.py   #必须在首行 ...

  10. thinkPHP的Excel插件

    原文地址 http://www.thinkphp.cn/topic/14005.html 总结的注意事项 1实例化第三方类,要在类名前加\ ,不然引用地址不对. 实现步骤:一:在http://phpe ...