swift语言点评二
一、数据类型
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、数据类型转化
let three = 3let pointOneFourOneFiveNine = 0.14159let pi = Double(three) + pointOneFourOneFiveNine// pi equals 3.14159, and is inferred to be of type Double
5、Tuples
let http404Error = (404, "Not Found")
let (statusCode, statusMessage) = http404Errorprint("The status code is \(statusCode)")// Prints "The status code is 404"print("The status message is \(statusMessage)")// Prints "The status message is Not Found"
6、Optionals
let possibleNumber = "123"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语言点评二的更多相关文章
- swift语言点评二十一-协议
定义有什么,及哪些必须实现. A protocol defines a blueprint of methods, properties, and other requirements that su ...
- swift语言点评二十-扩展
结论:扩展无法修改原来的数据结构. Extensions can add new functionality to a type, but they cannot override existing ...
- Swift语言指南(二)--语言基础之注释和分号
原文:Swift语言指南(二)--语言基础之注释和分号 注释 通过注释向自己的代码中注入不可执行的文本,作为你自己的笔记或提示.Swift编译器运行时会忽略注释. Swift的注释与C语言极其相似,单 ...
- swift语言点评十二-Subscripts
Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the m ...
- swift语言点评四-Closure
总结:整个Closure的作用在于简化语言表述形式. 一.闭包的简化 Closure expression syntax has the following general form: { () -& ...
- swift语言点评一
一.变量定义 1.常量与变量 Use let to make a constant and var to make a variable. 2.类型与推测 However, you don’t alw ...
- swift语言点评十九-类型转化与检查
1.oc比较: -(BOOL) isKindOfClass: classObj判断是否是这个类或者这个类的子类的实例 -(BOOL) isMemberOfClass: classObj 判断是否是这个 ...
- swift语言点评十八-异常与错误
1.错误类型与枚举的结合 enum VendingMachineError: Error { case invalidSelection case insufficientFunds(coinsNee ...
- swift语言点评十七-Designated Initializers and Convenience Initializers
Swift defines two kinds of initializers for class types to help ensure all stored properties receive ...
随机推荐
- H5自带进度条&滑块
一.H5自带进度条 <div id="d1"> <p id="pgv">进度:0%</p> <progress id= ...
- libz.so.1: cannot open shared object file: No such file or directory
在虚拟机安装xtrabackup工具时候出现的报错:libz.so.1: cannot open shared object file: No such file or directory [ro ...
- [NOIP补坑计划]NOIP2015 题解&做题心得
感觉从15年开始noip就变难了?(虽然自己都做出来了……) 场上预计得分:100+100+60~100+100+100+100=560~600(省一分数线365) 题解: D1T1 神奇的幻方 题面 ...
- gcp – 源于CP的高级命令行文件拷贝工具
作者:linux 出处:http://linux.cn/thread/11868/1/1/ gcp – 源于CP的高级命令行文件拷贝工具 几周前,我们讨论了高级拷贝(修改于cp命令,让其可以显示复制进 ...
- vue实现分页器(仿element)
1.起因 今日看完element中分页器的源码实现,比较简单,遂自己按着理解实现了一个简单的分页器,记录下来,以便日后温习. 2.实现难点 分页器的实现难点主要是什么时候显示分页器的省略, 我的思路是 ...
- [Codeforces 626F]Group Projects
题目大意: 给定\(n\)个数\(a[1]\sim a[n]\),让你把它分为若干个集合,使每个集合内最大值与最小值的差的总和不超过\(K\).问总方案数. 解题思路: 一道很神的dp题. 首先将数进 ...
- BZOJ 2820 luogu 2257 yy的gcd (莫比乌斯反演)
题目大意:求$gcd(i,j)==k,i\in[1,n],j\in[1,m] ,k\in prime,n,m<=10^{7}$的有序数对个数,不超过10^{4}次询问 莫比乌斯反演入门题 为方便 ...
- MHA 主从切换过程及日志分析
本文主要在MHA 切换日志的角度分析MHA切换的过.MHA故障切换过程如下图所示 第一部分:开启MHA 监控 通过分析日志,得到以下步骤: 1.读取MHA manager 节点的配置文件,并检查配置文 ...
- 【【henuacm2016级暑期训练】动态规划专题 I】Gargari and Permutations
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 注意这k个序列每个都是排列. 如果在每个序列中都满足y出现在x之后的话. 那么我们从x连一条有向边至y (有一个序列不满足就不连 ( ...
- Nginx 项目部署和配置
nginx 作为代理服务器,需要代理多个项目的话配置如下: server { listen 80; server_name localhost; #charset koi8-r; #ac ...