-
區(qū)間[a,b]在swift語言中的表達(dá)式是a...b
區(qū)間[a,b)在swift語言中的表達(dá)式是a..<b
那么我猜(a,b]=a>..b
可是(a,b)怎么表示呢?
查看全部 -
question?answer1:answer2,基礎(chǔ)運算的意思是
判斷“question的Bool值”,若返回“true”則執(zhí)行“answer1”,若返回“false”則執(zhí)行“answer2”
其實際是對if else語句的省略使用,相當(dāng)于
if question
{
????answer1
}
else
{
????answer2
}
查看全部 -
比較運算符的解釋:
==,比較符號左右兩側(cè)的值是否相等,若相等返回Bool值“true”
!=,比較符號左右兩側(cè)的值是否不相等,若不相等返回Bool值“true”
> ,比較符號左右兩側(cè)的值是否左大于右,若左大于右,則返回Bool值“true”
剩余“< ”,“>=”,“<=”的運算語意以此類推,但需注意的是,比較運算符號占兩個半角位置
查看全部 -
+=,-=,*=,/=,%= ?的語法意義是“前數(shù)”與“后數(shù)”運行第一個運算符號的計算值,然后再將該運算值結(jié)果賦值給“錢數(shù)”
例:
C = 1
C +=2 \\解釋為C=1+2,即該命令行的結(jié)果是C=3
查看全部 -
c++ 指讀取C的值,再進(jìn)行+1操作,但此時c++命令行中,c的值為C的初始值,即0
++c 指+1給C的值,則此時++c命令行中,C的值為“0+1”,即1
查看全部 -
Int、Var、String
查看全部 -
swift中if語言的格式是
if “條件(判斷等式或Bool邏輯值(true 或者 false)”
{
指令 //“大括號代替了then”
}
查看全部 -
1+2==3 表述意義為“判斷1+2是否等于3”,如果等于則返回“true”,如果不等于則返回“false”
查看全部 -
Int 整型量不能作為Bool的邏輯值判斷
查看全部 -
Bool 型變量的值是 true 或者 false,特別注意true 和false的寫法全都是小寫!小寫!小寫!
查看全部 -
漢字也可以作為 通用字符
姓名 = “慕課女神”
姓名 + “,你好”
同類型數(shù)字間才可以運算
Int + Float 錯誤,應(yīng)該轉(zhuǎn)換后再計算
Float(整型)+ 浮點型= 正確
查看全部 -
//: Playground - noun: a place where people can play
import UIKit
var array = ["AA", "BB", "CC", "D", "E", "F"]
array.count
array.isEmpty
array.append("G")
array += ["H"]
array += ["I", "J", "K"]
array.insert("Hello", atIndex: 0)
array
array.removeAtIndex(0)
array
array.removeLast()
array
array.removeRange(Range<Int>(0..<3))
array
array[0] = "AA"
array
array[2...4] = ["CC", "DD", "EE"]
array
for index in 0..<array.count {
? ? print(array[index])
}
for item in array {
? ? print(item)
}
for (index, item) in array.enumerate() {
? ? print("\(index) - \(item)")
}
查看全部 -
swift 3.0 version
//: Playground - noun: a place where people can play
import UIKit
var str = "Welcome to Play Swift! Step by Step learn Swift language from now!"
// range
str.rangeOfString("Step")
str.rangeOfString("Step", options: NSStringCompareOptions.BackwardsSearch)
str.rangeOfString("welcome", options: NSStringCompareOptions.CaseInsensitiveSearch)
str.startIndex
str.endIndex
let strRage = Range<String.Index>(str.startIndex..<str.endIndex)
let startIndex = str.startIndex
let endIndex:String.Index = str.startIndex.advancedBy(10)
let searchRange = Range<String.Index>(startIndex..<endIndex)
str.rangeOfString("Step", options: NSStringCompareOptions.CaseInsensitiveSearch, range: searchRange)
//substring
var toIndex = str.startIndex.advancedBy(4)
str.substringToIndex(toIndex)
var fromIndex = str.startIndex.advancedBy(14)
str.substringFromIndex(fromIndex)
str.substringWithRange(Range<String.Index>(toIndex..<fromIndex))
//insert
var insertIndex = str.startIndex.advancedBy(22)
str.insert("!", atIndex: insertIndex)
//remove
str.removeAtIndex(insertIndex)
str
str.removeRange(Range<String.Index>(str.startIndex..<insertIndex))
//replace
var replaceEndIndex = str.startIndex.advancedBy(13)
str.stringByReplacingCharactersInRange(Range<String.Index>(str.startIndex..<replaceEndIndex), withString: "Step-by-step")
運行效果圖:
查看全部 -
let courseName = "區(qū)間運算符"
switch courseName {
????case let str where str.hasSuffix("運算符"):
????print("課程《\(courseName)》是運算符的課程")
????default:
????????print("《\(courseName)》是其他課程")
}
查看全部 -
switch case 截圖查看全部
舉報