-
Notifications
You must be signed in to change notification settings - Fork 92
/
Contents.swift
59 lines (46 loc) · 1.12 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
54
55
56
57
58
59
//: Playground - noun: a place where people can play
import UIKit
class UI{
enum Theme{
case DayMode
case NightMode
}
var fontColor: UIColor!
var backgroundColor: UIColor!
var themeMode: Theme = .DayMode{
didSet{
self.changeTheme(self.themeMode)
}
}
init(){
self.themeMode = .DayMode
self.changeTheme(self.themeMode)
}
init(themeMode: Theme){
self.themeMode = themeMode
self.changeTheme(themeMode)
}
func changeTheme( themeMode: Theme ){
switch(themeMode){
case .DayMode:
fontColor = UIColor.blackColor()
backgroundColor = UIColor.whiteColor()
case .NightMode:
fontColor = UIColor.whiteColor()
backgroundColor = UIColor.blackColor()
}
}
}
let ui = UI()
ui.themeMode
ui.fontColor
ui.backgroundColor
ui.themeMode = .NightMode
ui.themeMode
ui.fontColor
ui.backgroundColor
// 以前就见过Nest Type
// String.Index
let str = "Hello World"
let index = str.startIndex.advancedBy(5)
str.substringToIndex(index)