Basics
【Basics】
1、You can declare multiple constants or multiple variables on a single line, separated by commas:

2、You can use almost any character you like for constant and variable names, including Unicode characters:

当声明一个变量后,你无法改变其类型,也无法从const发为非const。
3、注释可以多行嵌套:

4、Semicolons are required, however, if you want to write multiple separate statements on a single line:

5、通过min、max属性可以获得一个类型的最大最小值。
6、Int类型的数据范围随平台的不同而不同:

7、Numeric Literals

8、带指数的浮点数


9、Both integers and floats can be padded with extra zeroes and can contain underscores to help with readability.
可以添加额外的前缀0,以及添加增可读性的_。

10、类型不同的Int不能直接相加,必须进行类型转换。

11、Floating-point values are always truncated when used to initialize a new integer value in this way. This means that 4.75 becomes 4, and -3.9 becomes -3.
浮点数会被截断,即舍弃小数部分,直接返回整数部分。
12、typealias类型于C++中的typedef:


13、Tuple中的值可以分别为不同的类型。

Tuple的内容也可被解放出来:

也可只释放出tuple中的部分值:

也可通过index来访问tuple中的内容:

也可以给tuple中的每个元素命名:

命名后可以通过名字来访问:

14、optional value可以在其名字后面加上!来直接引用其值,叫unwrapping。如果不加!,runtime会进行判空逻辑。
15、=号不返回值,即不可以写a=b=c。

16、两个Character类型相加会得到String类型。

17、%是remainder运算符,a%b与a%(-b)结果是一样的。

%也可用在浮点数上:

18、unary plus operator (+)

19、 ===与!==用于判断两个reference是否引用同一个内存。
20、The closed range operator (a...b) defines a range that runs from a to b, and includes the values a and b.
The half-closed range operator (a..b) defines a range that runs from a to b, but does not include b.


21、Swift’s String type is bridged seamlessly to Foundation’s NSString class.
22、You can find out whether a String value is empty by checking its Boolean isEmpty property:

23、Swift’s String type is a value type. If you create a new String value, that String value is copied when it is passed to a function or method, or when it is assigned to a constant or variable。
To retrieve a count of the characters in a string, call the global countElements function and pass in a string as the function’s sole parameter:

Basics的更多相关文章
- Assembler : The Basics In Reversing
Assembler : The Basics In Reversing Indeed: the basics!! This is all far from complete but covers ab ...
- The Basics of 3D Printing in 2015 - from someone with 16 WHOLE HOURS' experience
全文转载自 Scott Hanselman的博文. I bought a 3D printer on Friday, specifically a Printrbot Simple Metal fro ...
- Cadence UVM基础视频介绍(UVM SV Basics)
Cadence关于UVM的简单介绍,包括UVM的各个方面.有中文和英文两种版本. UVM SV Basics 1 – Introduction UVM SV Basics 2 – DUT Exampl ...
- C basics
C 日记目录 C basics ................ writing Numeration storage , structor space assigning pointer, a ...
- Xperf Basics: Recording a Trace(转)
http://randomascii.wordpress.com/2011/08/18/xperf-basics-recording-a-trace/ This post is obsolete ...
- Xperf Analysis Basics(转)
FQ不易,转载 http://randomascii.wordpress.com/2011/08/23/xperf-analysis-basics/ I started writing a des ...
- Radio Basics for RFID
Radio Basics for RFID The following is excerpted from Chapter 3: Radio Basics for UHF RFID from the ...
- 【IOS笔记】View Controller Basics
View Controller Basics 视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...
- NSInvocation Basics
In this article I'm going to cover the basics and usages of NSInvocation. What is NSInvocation? Appl ...
- Qt 线程基础(Thread Basics的翻译,线程的五种使用情况)
Qt 线程基础(QThread.QtConcurrent等) 转载自:http://blog.csdn.net/dbzhang800/article/details/6554104 昨晚看Qt的Man ...
随机推荐
- C++使用初始化列表的方式来初始化字段
几个月之前,接触Android recovery源代码的时候,看ScreenRecoveryUI类的时候,那时候C++基础还不是特别好,一直不明白以下的初始化方式: 下面这个是Recovery的一个构 ...
- 作为一名Java开发工程师需要掌握的专业技能
在学习Java编程完之后,学员们面临的就是就业问题.作为一名Java开发工程师,企业在招聘的时候,也是有一定的标准的. 为了帮助大家更好的找到适合自己的工作,在这里分享了作为一名Java开发工程师需要 ...
- 第二章 Linux目录介绍
一级目录 /bin (普通用户)二进制命令所在目录 备注 /boot LINUX内核及系统引导程序所需的文件目录 常见分区:128M swap内存的1.5倍 /dev 设备文件的目录 比如声卡.磁盘. ...
- xml(带有命名空间的)读写操作
xml文件: <?xml version="1.0" encoding="UTF-8"?><!-- This file contains jo ...
- VS2010中使用 SpecFlow + Selenium.WebDriver
安装(VS扩展.程序包) [工具]->[扩展管理器],安装SpecFlow [工具]->[库程序包管理]->[程序包管理器控制台] PM> Install-Package Sp ...
- PTA L3-023 计算图 (dfs+数学推导)
“计算图”(computational graph)是现代深度学习系统的基础执行引擎,提供了一种表示任意数学表达式的方法,例如用有向无环图表示的神经网络. 图中的节点表示基本操作或输入变量,边表示节点 ...
- 设计模式之访问者(visitor)模式
在患者就医时,医生会根据病情开具处方单,很多医院都会存在以下这个流程:划价人员拿到处方单之后根据药品名称和数量计算总价,而药房工作人员根据药品名称和数量准备药品,如下图所示. 在软件开发中,有时候也需 ...
- deep Learning 之入门一 (ps:知乎上看到的大佬写的非常好,所以自己记录下)
作者:Jacky Yang 链接:https://www.zhihu.com/question/26006703/answer/129209540 来源:知乎 著作权归作者所有.商业转载请联系作者获得 ...
- matlab的fda工具使用方法
MATLAB中用FDATool设计滤波器及使用 该文章讲述了MATLAB中用FDATool设计滤波器及使用. 1. 在Matlab中键入fdatool运行Filter Design and Analy ...
- 转载.Avalon-MM 阿窝龙妹妹应用笔记
Avalon Interface Special http://www.altera.com.cn/literature/manual/mnl_avalon_spec.pdf Avalon总线是SOP ...