From: acevest Date: Sat, 4 Mar 2017 12:53:03 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=c0efbfec4d422dfa252c9fbec861943366397b12;p=acecode.git ... --- diff --git a/learn/AcePlay/AcePlay.playground/Pages/CollectionTypes.xcplaygroundpage/Contents.swift b/learn/AcePlay/AcePlay.playground/Pages/CollectionTypes.xcplaygroundpage/Contents.swift index 993fb4c..78be21e 100644 --- a/learn/AcePlay/AcePlay.playground/Pages/CollectionTypes.xcplaygroundpage/Contents.swift +++ b/learn/AcePlay/AcePlay.playground/Pages/CollectionTypes.xcplaygroundpage/Contents.swift @@ -116,9 +116,9 @@ print(farmAnimals.isSuperset(of: houseAnimals)) print(farmAnimals.isDisjoint(with: cityAnimals)) // 是否无交集 printLine("Dictionary") -//var DictA = Dictionary() -//var DictB = ["KA":"VA", "KB":"VB", "KC":"VC"] -//var DictC: [String:String] = [:] +var DictA = Dictionary() +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(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 index 0000000..781d883 --- /dev/null +++ b/learn/AcePlay/AcePlay.playground/Pages/ControlFlow.xcplaygroundpage/Contents.swift @@ -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 diff --git a/learn/AcePlay/AcePlay.playground/contents.xcplayground b/learn/AcePlay/AcePlay.playground/contents.xcplayground index 9baedd5..a6a057a 100644 --- a/learn/AcePlay/AcePlay.playground/contents.xcplayground +++ b/learn/AcePlay/AcePlay.playground/contents.xcplayground @@ -8,5 +8,6 @@ + \ No newline at end of file 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 423c7fc..35670e3 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 diff --git a/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate b/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate index 5079663..f58186f 100644 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