]> Zhao Yanbai Git Server - acecode.git/commitdiff
...
authoracevest <zhaoyanbai@126.com>
Sat, 4 Mar 2017 12:53:03 +0000 (20:53 +0800)
committeracevest <zhaoyanbai@126.com>
Sat, 4 Mar 2017 12:53:03 +0000 (20:53 +0800)
learn/AcePlay/AcePlay.playground/Pages/CollectionTypes.xcplaygroundpage/Contents.swift
learn/AcePlay/AcePlay.playground/Pages/ControlFlow.xcplaygroundpage/Contents.swift [new file with mode: 0644]
learn/AcePlay/AcePlay.playground/contents.xcplayground
learn/AcePlay/AcePlay.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate
learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate

index 993fb4c0cc09854dc143c48ac8eada36117d411c..78be21ea0a2033652178183ba388b95698e0fa33 100644 (file)
@@ -116,9 +116,9 @@ print(farmAnimals.isSuperset(of: houseAnimals))
 print(farmAnimals.isDisjoint(with: cityAnimals))    // 是否无交集
 
 printLine("Dictionary")
-//var DictA = Dictionary<Int, String>()
-//var DictB = ["KA":"VA", "KB":"VB", "KC":"VC"]
-//var DictC: [String:String] = [:]
+var DictA = Dictionary<Int, String>()
+var DictB = ["KA":"VA", "KB":"VB", "KC":"VC"]
+var DictC: [String:String] = [:]
 var DictD = [Int:String]()
 
 DictD[1]  = "V1"
@@ -135,6 +135,8 @@ for (k, v) in DictD {
     print("Key:", k, " Value: ", v)
 }
 
+DictD[4] = nil  // 4 has been removed from the Dictionary
+
 for key in DictD.keys.sorted() {
     print(key)
 }
@@ -143,5 +145,10 @@ for value in DictD.values.sorted() {
     print(value)
 }
 
+
+// 把keys 或 values 放到数组中
 let keys = [Int](DictD.keys)
-print(keys)
\ No newline at end of file
+let values = Array<String>(DictD.values)
+print(keys)
+print(values)
+
diff --git a/learn/AcePlay/AcePlay.playground/Pages/ControlFlow.xcplaygroundpage/Contents.swift b/learn/AcePlay/AcePlay.playground/Pages/ControlFlow.xcplaygroundpage/Contents.swift
new file mode 100644 (file)
index 0000000..781d883
--- /dev/null
@@ -0,0 +1,77 @@
+//: [Previous](@previous)
+
+import Foundation
+
+
+//: [Next](@next)
+
+
+for index in 1...5 {
+    print("\(index) * 5 = \(index*5)")
+}
+
+let base = 2
+let power = 10
+var answer = 1
+
+for _ in 1...power {
+    answer *= base
+}
+
+print("\(base) to power of \(power) is \(answer)")
+
+
+while answer > 0 {
+    answer -= 10
+}
+
+print("Answer \(answer)")
+
+repeat {
+    answer += 10
+} while(answer < 1000)
+
+print("Answer \(answer)")
+
+
+var r = arc4random_uniform(100)
+
+if r % 2 == 1 {
+    print("Odd Number \(r)")
+} else {
+    print("Even Number \(r)")
+}
+
+
+r = arc4random_uniform(100)
+if r < 60 {
+    print("Failed. Score: \(r)")
+} else if r < 80 {
+    print("Good. Score: \(r)")
+} else {
+    print("Perfect. Score: \(r)")
+}
+
+
+let approximateCount = arc4random_uniform(100)
+let countedTings = "moon orbiting Saturn"
+var naturalCount = ""
+
+switch approximateCount {
+case 0:
+    naturalCount = "no"
+case 1..<5:
+    naturalCount = "a few"
+case 5:
+    fallthrough                 // 默认不走到下一个case
+case 6..<12:
+    naturalCount = "several"
+case 12..<100:
+    naturalCount = "dozens of"
+case 100..<1000:
+    naturalCount = "hundreds of"
+default:
+    naturalCount = "many"
+}
+
+print("There are \(naturalCount) \(countedTings) [\(approximateCount)]")
\ No newline at end of file
index 9baedd599af3f71cf96b8165157227d4a40f75d6..a6a057a0bd2098378768d1e229d04fd5aea01200 100644 (file)
@@ -8,5 +8,6 @@
         <page name='Classes'/>
         <page name='Properties'/>
         <page name='CollectionTypes'/>
+        <page name='ControlFlow'/>
     </pages>
 </playground>
\ No newline at end of file
index 423c7fc3ef157c481ed35cc158f319e155aab355..35670e3b0b715ecb0994f30d1d0ef34db86ec9b2 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
index 5079663a0e3f7fff8127c4e2fbe7669eb2b4868c..f58186fe55e17e8c3295ed30e447d57f34d8132b 100644 (file)
Binary files a/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate and b/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate differ