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 ...
随机推荐
- 神奇的TextField(2)
var text_content:TextField=new TextField(); text_content.autoSize="left"; // text_content. ...
- 【整理】石子合并问题(四边形不等式DP优化)
有很多种算法: 1,任意两堆可以合并:贪心+单调队列. 2,相邻两堆可合并:区间DP (O(n^3)) ). 3,相邻,四边形不等式优化DP (O(n^2) ). 4,相邻,GarsiaWach ...
- 高级C/C++编译技术之读书笔记(五)之动态库版本控制
最近有幸阅读了<高级C/C++编译技术>深受启发,该书深入浅出地讲解了构建过程(编译.链接)中的各种细节,从多个角度展示了程序与库文件或代码的集成方法,提出了面向代码复用和系统集成的软件架 ...
- 使用 ip 进行系统网络配置
检查是否有安装iproute工具 rpm -qa | grep iproute 查看所有可用接口 ip link show 启用或禁用接口 ip link set down eth1 ip link ...
- World、Excel利用流下载
/** * 下载excel * @param request * @param response * @param filePath * @param fileName */public static ...
- bzoj 3230 相似子串——后缀数组
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3230 作出后缀数组,从 LCP 看每个位置对于本质不同子串的贡献,而且他们已经按前面部分排好 ...
- (转)android平台下使用点九PNG技术
“点九”是andriod平台的应用软件开发里的一种特殊的图片形式,文件扩展名为:.9.png 智能手机中有自动横屏的功能,同一幅界面会在随着手机(或平板电脑)中的方向传感器的参数不同而改变显示的方向, ...
- float和clear
简介 float CSS属性指定一个元素应沿其容器的左侧或右侧放置,允许文本和内联元素环绕它.该元素从网页的正常流动中移除,尽管仍然保持部分的流动性. 浮动元素是float值不为none的元素. 可能 ...
- Linux 多路复用 select / poll
多路复用都是在阻塞模式下有效! linux中的系统调用函数默认都是阻塞模式,例如应用层读不到驱动层的数据时,就会阻塞等待,直到有数据可读为止. 问题:在一个进程中,同时打开了两个或者两个以上的文件,读 ...
- grep 命令使用指南
grep 命令 grep参数: -E:等同于egrep -o:只匹配你想要的内容,下面是示例: [root@localhost ~]# cat /data/game/config/server_con ...