-
Notifications
You must be signed in to change notification settings - Fork 93
/
Contents.swift
54 lines (36 loc) · 1.13 KB
/
Contents.swift
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//: Playground - noun: a place where people can play
import UIKit
var courses = ["玩儿转Swift","玩儿转Swift2(第一季)","玩儿转Swift2(第二季)"]
// 添加元素
courses.append("玩儿转Swift2(第三季)")
print(courses)
// 数组常量
//使用let定义的数组不可以更改任何内容
courses += ["玩儿转Swift2(第四季)"]
print(courses)
// 两个数组相加
courses = courses + ["玩儿转Swift面向协议编程","玩儿转Swift面向函数编程"]
print(courses)
courses.insert("玩儿转Swift设计模式", atIndex: 5)
//courses.insert("玩儿转Swift设计模式", atIndex: 10)
print(courses)
// 删除元素
courses.removeLast()
print(courses)
courses.removeFirst()
print(courses)
courses.removeAtIndex(4)
//courses.removeAtIndex(10)
print(courses)
//courses.removeRange(0..<4)
//courses.removeRange(0..<10)
//print(courses)
//courses.removeAll()
//print(courses)
// 修改元素
courses[0] = "玩儿转Swift3(第一季)"
print(courses)
courses[1...3] = ["玩儿转Swift3(第二季)","玩儿转Swift3(第三季)","玩儿转Swift3(第四季)"]
print(courses)
courses[0...3] = ["玩儿转Swift3"]
print(courses)