From: AceVest Date: Wed, 8 Mar 2017 15:49:01 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=0d5ea3e5ae965fd0140936cf1f9becb4b50fc7bf;p=acecode.git ... --- diff --git a/learn/AcePlay/AcePlay.playground/Pages/Classes.xcplaygroundpage/Contents.swift b/learn/AcePlay/AcePlay.playground/Pages/Classes.xcplaygroundpage/Contents.swift index 7a81ad8..bc7279c 100644 --- a/learn/AcePlay/AcePlay.playground/Pages/Classes.xcplaygroundpage/Contents.swift +++ b/learn/AcePlay/AcePlay.playground/Pages/Classes.xcplaygroundpage/Contents.swift @@ -28,6 +28,19 @@ cinema.width = 2048 print("HD: \(hd.width)x\(hd.height)") print("Cinema: \(cinema.width)x\(cinema.height)") +// Enumeration 也是值类型 +enum CompassPoint: String { + case North + case South + case East + case West +} + +var originDirection = CompassPoint.East +var currentDirection = originDirection +currentDirection = .West +print("originDirection: \(originDirection) currentDirection: \(currentDirection)") + class VideoMode { var resolution = Resolution() @@ -58,4 +71,4 @@ if anotherTenEighty === tenEighty { if someVideoMode !== tenEighty { print("someVideoMode & tenEighty refer to different VideoMode instance") -} \ No newline at end of file +} diff --git a/learn/AcePlay/AcePlay.playground/Pages/Properties.xcplaygroundpage/Contents.swift b/learn/AcePlay/AcePlay.playground/Pages/Properties.xcplaygroundpage/Contents.swift index 24da0c4..d343e4d 100644 --- a/learn/AcePlay/AcePlay.playground/Pages/Properties.xcplaygroundpage/Contents.swift +++ b/learn/AcePlay/AcePlay.playground/Pages/Properties.xcplaygroundpage/Contents.swift @@ -27,6 +27,30 @@ printLine("Lazy Stored Properties") // lazy 属性在声明前加上 lazy 关键字 // 如果一个被标记为 lazy 的属性在没有初始化时就同时被多个线程访问,则无法保证该属性只会被初始化一次 +class DataImporter { + var name: String = "" + init() { + self.name = "DataImporter" + print("...\(self.name)...") + } +} + +class DataManager { + lazy var importer = DataImporter() + var data: Array = [] +} + +let dataManager = DataManager() +dataManager.data.append("Data_0") +dataManager.data.append("Data_1") +dataManager.data.append("Data_2") +// lazy 变量还未初始化 +print("the DataImporter instance for the importer property has not yet been created") + +// 主动调用才初始化 +dataManager.importer + + printLine("Computed Properties") @@ -94,4 +118,4 @@ class Cuboid { } let fourByFiveByTwo = Cuboid(width:4.0, height:5.0, depth:2.0) -print(fourByFiveByTwo.volume) \ No newline at end of file +print(fourByFiveByTwo.volume) diff --git a/learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate b/learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate index a5bd0ed..4a9ccd9 100644 Binary files a/learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate and b/learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate differ