Swift Section Two(数组与字典)

数组与字典


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

// Playground - noun: a place where people can play

import UIKit

//swift 第二课 数组与字典

//1.数组的声明

var shoppingList = ["catfish","water","tulips","blue paint"]

shoppingList[1] = "bottle of water"

print(shoppingList)

//2.字典的声明

var occupations = ["Malcolm":"Captain","Kaylee":"Mechanic"]

occupations["Jayne"] = "Public Relations"

print(occupations)

//3.空数组和空字典的声明

let emptyArray = [String]()

let emptyDictionary = [String : Float]()

//甚至你可以这样清空数组

shoppingList = []

occupations = [:]

源代码请前往我的github

Comments