您的位置:首页 > 移动开发 > Swift

Swift基础学习一

2014-06-12 14:06 211 查看
String

hasPrefix(“”) 前缀

uppercaseString 大写

lowercaseString 小写

unicodeScalars 所有字符

Array

var array:String[] = [“string1”,”string2”]

count 数目

isEmpty 是否空

append(3) 添加一项

shoppingList.insert("MapleSyrup",
atIndex: 0) 插入一项

shoppingList.removeAtIndex(0) 删除一项

shoppingList.removeLast() 删除最后一项

enumerate(list)分解数组

var threeDoubles
= Double[](count:
3, repeatedValue:
0.0)//初始化3个数都为0.0

var anotherThreeDoubles
= Array(count:
3, repeatedValue:
2.5)

Dictionary

var airports:
Dictionary<String,
String> = ["TYO":
"Tokyo", "DUB":
"Dublin"]

airports.count//数目

airports["LHR"] =
"London"//添加一项

let oldValue
= airports.updateValue("DublinInternational",
forKey: "DUB")//

airports["APL"] =
nil//删除APL

let removedValue
= airports.removeValueForKey("DUB")//删除DUB

for (airportCode,
airportName) inairports
{//遍历airports
println("\(airportCode):
\(airportName)")
}

for airportCode
in airports.keys{//根据key遍历

println("Airportcode:
\(airportCode)")
}

for airportName
inairports.values//根据value遍历

let airportCodes
= Array(airports.keys)

let airportNames
= Array(airports.values)

var namesOfIntegers
= Dictionary<Int,
String>()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: