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 ...
随机推荐
- javascript动画函数封装
function animate(obj, target) { clearInterval(obj.timer); obj.timer = setInterval(function () { var ...
- WCF(二)配置文件
上篇文章中对WCF的配置放到App.config中,这样可以使程序更灵活.更具有扩展性. 下面说下配置文件中各个节点的含义. 服务端: WCF配置文件节点放在<system.serviceMod ...
- win7系统桌面上图标都变成lnk后缀
1.右键点击空白处,选择“新建”,点击“文本文档”: 2.将文档命名为“1”,后缀名改为inf: 3.双击打开,复制以下内容: [Version] Signature="$Chicago$& ...
- requests模块的高级用法
SSL Cert Verification #证书验证(大部分网站都是https) import requests respone=requests.get('https://www.12306.cn ...
- EntityFramework 一
EntityFramework EF核心库 EntityFramework.SqlServer EF针对sqlsever的库 引用 system.Data.Entity EF相比SQL语句方便,但 ...
- python在不同情况下写入csv文件
情况一(解法一):将列表存储为csv文件.列表的每一项代表csv文件的一行. 列表中的每一项包含多个属性.list=[[属性1,属性2,属性3,……],[属性1,属性2,属性3,……],[属性1,属性 ...
- SVN提交代码时报405 Method Not Allowed
原因: 1.删除了某个文件夹,然后又创建了一个同名文件夹 2.之前执行过Add操作,但没上传代码,在电脑上提交了同路径的代码,再次上传时会报错 解决方法: 1. 删除出现错误的文件夹 2. SVN U ...
- 关于thinkpadU盘系统盘启动不了解决方法
http://www.laomaotao.org/softhelp/bios/382.html(原文章地址,比较全面) thinkpad笔记本uefi无法启动详细解决教程 最近有个别用户反映说thin ...
- HDU 4318 Contest 2
简单的一题,使用类DIJK的算法就可以了. #include <iostream> #include <cstdio> #include <queue> #incl ...
- 一步一步跟我学习hadoop(7)----hadoop连接mysql数据库运行数据读写数据库操作
为了方便 MapReduce 直接訪问关系型数据库(Mysql,Oracle).Hadoop提供了DBInputFormat和DBOutputFormat两个类.通过DBInputFormat ...