您好,登錄后才能下訂單哦!
Today ,蘋(píng)果剛剛發(fā)布了Swift語(yǔ)言,我們來(lái)看下Swift的幾個(gè)主要特性:
1 Safe
func configureLabels(labels: UILabel[]) {
let labelTextColor = UIColor.greenColor()
for label in labels {
// label inferred to be UILabel
label.textColor = labelTextColor
}
}
2 Modern
let cities = ["London", "San Francisco", "Tokyo", "Barcelona", "Sydney"]
let sortedCities = sort(cities) { $0 < $1 }
if let indexOfLondon = find(sortedCities, "London") {
println("London is city number \(indexOfLondon + 1) in the list")
}
let size = (20, 40)
switch size {
case let (width, height) where width == height:
println("square with sides \(width)")
case (1..10, 1..10):
println("small rectangle")
case let (width, height):
println("rectangle with width \(width) and height \(height)")
}
4 Interactive
5 Fast。
-------------------------------------
基本數(shù)據(jù)類(lèi)型:
1 簡(jiǎn)單屬性:
let: 恒定常量
var:可變常量
1.1 定義常量不用指定其固定類(lèi)型,編譯器會(huì)處理,如需更多識(shí)別,請(qǐng)?zhí)砑忧熬Y:
let implicitInteger = 70
let implicitDouble = 70.0
let explicitDouble: Double = 70
println("int:\(implicitInteger) double:\(implicitDouble) explicitDoubledss:\(explicitDouble)");
2 類(lèi)型之間的轉(zhuǎn)化,必須是顯示的:
let label = "width is :";
let width = 54;
let widthLabel = label + String(width)
println("LabelWidth:\(widthLabel)");
3 使用反斜杠在String中插入內(nèi)容,代碼參考2
4 使用中括號(hào)創(chuàng)建數(shù)組和字典:
var shoppingList = ["catfish", "water", "tulips", "blue paint"]
shoppingList[1] = "bottle of water"
var occupations = [
"Malcolm": "Captain",
"Kaylee": "Mechanic",
]
occupations["Jayne"] = "Public Relations"
println("array is \(shoppingList)")
println("dictionary is :\(occupations)")
//create Empty
let emptyArray = String[]()
let emptyDictionary = Dictionary<String, Float>()
下一篇文章將介紹控制語(yǔ)句
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。