]> Zhao Yanbai Git Server - acecode.git/commitdiff
...
authorAceVest <zhaoyanbai@126.com>
Wed, 8 Mar 2017 15:49:01 +0000 (23:49 +0800)
committerAceVest <zhaoyanbai@126.com>
Wed, 8 Mar 2017 15:49:01 +0000 (23:49 +0800)
learn/AcePlay/AcePlay.playground/Pages/Classes.xcplaygroundpage/Contents.swift
learn/AcePlay/AcePlay.playground/Pages/Properties.xcplaygroundpage/Contents.swift
learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate

index 7a81ad822aa4212625e9eb448882e0d7a55623a7..bc7279c7d561745c5acbaf5c43fe5b66ed9b97bc 100644 (file)
@@ -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
+}
index 24da0c4ac7d9fc37b6dc3629dfcc485d7f6b6b9d..d343e4d12f3c7bea1a0a359ba4829683ccb7ddd5 100644 (file)
@@ -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<String> = []
+}
+
+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)
index a5bd0eda41a23e5c276d7a45825adfa46ff6f58d..4a9ccd94eec012a448adcb0d43fe1d392dd1d5bc 100644 (file)
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