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>()
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>()
相关文章推荐
- swift开发环境搭建[零基础学习Swift开发](二)
- Swift基础学习二
- Swift学习笔记1——基础部分
- Swift教程_通过改造官方Sample学习Swift(三)_Swift基础(对象和类、枚举和结构、协议和扩展、泛型)
- Swift教程_通过改造官方Sample学习Swift(二)_Swift基础(简单值、控制流、方法和闭包)
- 介绍篇[零基础学习Swift开发](一)
- Swift基础学习中
- 【Swift】学习笔记(一)——初识 基础数据类型,代码风格,元组,断言
- Swift学习——Swift基础详解(八)
- swift基础知识学习
- Swift学习——Language Guide 基础
- Swift学习——Swift基础详解(四)
- Swift学习——Swift基础详解(三)
- swift学习日志-1基础篇 基础运算符
- Swift学习——Swift基础详解(六)
- Swift 学习笔记之基础
- Swift学习——Swift基础详解(二)
- Swift学习——Swift基础详解(五)
- S008 - iOS 应用基础 swift版 - 系统学习 iOS 界面编程
- swift基础学习上