Swift3.1(2)Basic Opetators
来源:互联网 发布:设计软件图标 编辑:程序博客网 时间:2024/06/06 20:53
文档地址:
https://developer.apple.com/library/prerelease/content/documentation/Swift/Conceptual/Swift_Programming_Language/BasicOperators.html#//apple_ref/doc/uid/TP40014097-CH6-ID60
1、swift supports most standard C operators
swfit语言支持大部分c语言的预算符号
2、swift also provides two range operators (a..b and a…b)not found in C
范围符号
3、if the right side of the assignment is a tuple with multiple values,its elements can be decomposed into multiple constants or vairables at once:
let (x,y) = (1,2)
4、Unlike the assignment operator in C and Objective-C ,the assignment operator in swift does not itself return a value.
不像c语言或者oc语言,在swift中的赋值运算符不返回一个值
The following statement is not valid
if x = y {
}
5、arithmetic opetators数学运算符
6、The addition opetater is also supported For String concatnecation.
“hello” + “world”
7、Swift supports all standard C comparison opetators
(==,!=,>)等
8、Swfit also provides two identify operators(=== and !==),which you use to test whether two object references both refer to the same object instance.
用===和!==来测试两个对象指向相同的实例
9、Tuple也能比较,the comparison is already determined by the tuples’ fisrt elements.
如果第一个元素相同,继续看后面的元素
10、Use the ternary conditional operator with care,however.its consiceness can lead to hard-to-read code if overused.Avoid combning multiple instances of the ternary conditional opetator into one compound statement
三元运算符不能滥用,尽量避免将几个三元运算符放进一个复合的语句
11、nil_coalescing Operator
a??b相当于
a != nil ? a! :b
let defaultColorName = “Red”
var userDefinedColorName:String?
var colorNameToUse = userDefinedColorName ??defaultColorName
12、Range Operators
closed Range Operator
range operator(a…b)defines a ranges that runs from a to b, and inludes the values a and b.
for index in 1…5 {
print(“\(index) times 5 is \(index * 5)”)
}
Half-Open Range Operator
The half-open range operator(a..<b) which does not include b
13、logical Operators
!, && , ||
- Swift3.1(2)Basic Opetators
- Swift3.0学习笔记-Basic Operators(基本运算符)
- Swift3.1(6) Functions
- Swift3
- swift3
- 蓝桥杯题—BASIC-1闰年判断 BASIC-2 01字串 BASIC-3 字母图形
- swift3.1(1)The Basics
- Swift3.0 gcd学习(2)
- swift3.0蓝牙开发(2)
- Swift3.0 gcd学习(1)
- Swift3.1-实现自定义Log
- Swift3.1(4)Collection Types
- swift3.1(5)control flow
- OC与swift3.1混编
- 【Swift3.1】闭包(Closures)
- IOS Swift3.1保存数据
- IOS Swift3.1 删除UIViewController
- Swift3.1字符串截取操作
- 让你快速上手Runtime
- 郁闷!ionic中获取ng-model绑定的值为undefined如何解决
- [SSOI3051] 礼物(present)
- 博客开通啦
- FFmpeg 基本用法--此文转载,作为笔记
- Swift3.1(2)Basic Opetators
- BZOJ2179——FFT快速傅立叶
- Linux硬盘相关检测
- Email 的两种方法
- HDU5521Meeting 【Dijkstra】
- [C#]Debug客户端时,关联服务端代码
- linux定时器的使用
- Navicate使用http通道访问数据库
- Python 调用C# 删除所有文件