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 ...
随机推荐
- P1343 地震逃生
题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带,每条边都只能容纳一定量 ...
- P2216 [HAOI2007]理想的正方形(二维RMQ)
题目描述 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入输出格式 输入格式: 第一行为3个整数,分别表示a,b,n的值 第二行至 ...
- 开源UWP总结
1.UWP第三方简书客户端分享:http://www.cnblogs.com/youngytj/p/4889010.html 2.知乎日报:http://www.cnblogs.com/xiaozhi ...
- github踩坑之git命令收集与整理(windows)
最近开始又捡起git,第一家公司用的就是git,一直掌握的也不深刻,就知道常用的几个命令,虽然现在用svn,但是觉得git还是不能丢,遂又捡起来了.先总结一部分目前练习用到的,慢慢填补吧~ githu ...
- NGUI 按钮点击事件的两种绑定形式
面板属性栏绑定 写一个脚本,定义一个Public的方法 Notify中选择物体时,选中自己 然后就可以选择通知到写的那个脚本的里边的public方法 代码绑定 创建一个代码文件,挂载到按钮对象上 代码 ...
- Java基础——Servlet
什么是Servlet Servlet是Java Web的三大组件之一,它属于动态资源.Servlet的作用是处理请求,服务器会把接收到的请求交给Servlet来处理,在Servlet中通常需要: l ...
- “肥宅快乐数”-python暴力版
编写一个函数来判断一个数是不是“快乐数”.一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1.如 ...
- Pyhton学习——Day33
#并发式编程# 操作系统是一个用来协调.管理和控制计算机硬件和软件资源的系统程序,它位于硬件和应用程序之间.# (程序是运行在系统上的具有某种功能的软件,比如说浏览器,音乐播放器等.)# 操作系统的内 ...
- 使用highcharts动态绘制折线图——so easy
之前学习highcharts发现网上的教程大部分是对highcharts数据的注释,如何动态绘制数据大部分一笔带过,让那些初涉开发的小白云里雾里,所以我就写了一篇这样的博客. <html> ...
- LeetCode 856 递归思路详解
题目描述 给定一个平衡括号字符串 S,按下述规则计算该字符串的分数: () 得 1 分. AB 得 A + B 分,其中 A 和 B 是平衡括号字符串. (A) 得 2 * A 分,其中 A 是平衡括 ...