Swift(2)Basic Opetators
文档地址: 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 !,&&,|| (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |