From: AceVest Date: Sat, 4 Mar 2017 04:29:41 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=562551d69644382d74fe8d9d99ae6f616080c195;p=acecode.git ... --- diff --git a/learn/AcePlay/AcePlay.playground/Pages/Basics.xcplaygroundpage/Contents.swift b/learn/AcePlay/AcePlay.playground/Pages/Basics.xcplaygroundpage/Contents.swift index 4890fa0..0c860f6 100644 --- a/learn/AcePlay/AcePlay.playground/Pages/Basics.xcplaygroundpage/Contents.swift +++ b/learn/AcePlay/AcePlay.playground/Pages/Basics.xcplaygroundpage/Contents.swift @@ -130,91 +130,3 @@ print() print("The String is: \(str)") -// Print separator & terminator -var company:Array = [ "Apple", "Google", "Facebook", "Tencent" ] -print(company[0], company[1], company[2], company[3], separator: "#", terminator: " $$$$$\n") - -printLine("Count company Array 1") -for (i,v) in company.enumerated() { // enumerate 返回的是 index value 组成的元组 - print(i, v, separator: " - ", terminator: "\n") -} - -printLine("Count company Array 2") -company.insert("Alibaba", at: company.count) -for i in 0..(0.. = [] -var SetB = Set() -var SetC: Set = ["ASM", "C", "C++", "go", "Swift"] -//var SetD: Set = ["mov", "pop", "push", "xchg"] // 可以通过数组类型推断出Set的类型 -SetB.insert("A") -SetB.insert("c") -SetB.insert("c") -SetB.count -//SetC.removeFirst() -SetC.remove("ASM") - -if let removedVal = SetC.remove("ASM") { - print("\(removedVal) I'm over it.") -} else { - print("I never much cared for that.") - SetC.insert("ASM") -} - -if SetC.contains("Swift") { - print("SetC Contains Swift") -} - -for v in SetC.sorted() { - print(v) -} - -printLine("Dictionary") -//var DictA = Dictionary() -//var DictB = ["KA":"VA", "KB":"VB", "KC":"VC"] -//var DictC: [String:String] = [:] -var DictD = [Int:String]() - -DictD[1] = "V1" -DictD[4] = "V2" -DictD[99] = "V3" -DictD[36] = "F4" -if let oldValue = DictD.updateValue("V4", forKey: 36) { // means: if let oldValue = DictD[36] - print("The old value for Key:36 was \(oldValue)") -} - -print("DictD Item Count: ", DictD.count) - -for (k, v) in DictD { - print("Key:", k, " Value: ", v) -} - -for key in DictD.keys.sorted() { - print(key) -} - -for value in DictD.values.sorted() { - print(value) -} - -let keys = [Int](DictD.keys) -print(keys) \ No newline at end of file diff --git a/learn/AcePlay/AcePlay.playground/Pages/CollectionTypes.xcplaygroundpage/Contents.swift b/learn/AcePlay/AcePlay.playground/Pages/CollectionTypes.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..993fb4c --- /dev/null +++ b/learn/AcePlay/AcePlay.playground/Pages/CollectionTypes.xcplaygroundpage/Contents.swift @@ -0,0 +1,147 @@ +//: [Previous](@previous) + +import Foundation + +var str = "Hello, playground" + +//: [Next](@next) + +var company:Array = [ "Apple", "Google", "Facebook", "Tencent" ] + +// Print separator & terminator +print(company[0], company[1], company[2], company[3], separator: "#", terminator: " $$$$$\n") + +// 遍历数组 +for v in company { + print("Company: \(v)") +} + +printLine("Count company Array 1") +for (i,v) in company.enumerated() { // enumerate 返回的是 index value 组成的元组 + print(i, v, separator: " - ", terminator: "\n") +} + +printLine("Count company Array 2") +company.insert("Alibaba", at: company.count) +for i in 0.. = [1, 2] +var someIntsE: [Int] = [1, 2] +var someIntsF = [1, 2] + + +someIntsA.append(1) +someIntsB.replaceSubrange(CountableRange(0.. = [] +var SetB = Set() +var SetC: Set = ["ASM", "C", "C++", "go", "Swift"] +var SetD: Set = ["mov", "pop", "push", "xchg"] // 可以通过数组类型推断出Set的类型 +SetB.insert("A") +SetB.insert("c") +SetB.insert("c") +SetB.count +//SetC.removeFirst() +SetC.remove("ASM") + +if let removedVal = SetC.remove("ASM") { + print("\(removedVal) I'm over it.") +} else { + print("I never much cared for that.") + SetC.insert("ASM") +} + +if SetC.contains("Swift") { + print("SetC Contains Swift") +} + +for v in SetC { + print(v) +} + +for (i, v) in SetD.enumerated() { + print("Iterating Over a Set \(i)\t\(v)") +} + +for (i, v) in SetD.sorted().enumerated() { + print("Iterating Over a Set in Order \(i)\t\(v)") +} + +let oddDigits: Set = [1, 3, 5, 7, 9] +let evenDigits: Set = [0, 2, 4, 6, 8] +let singlePrimeDigits: Set = [2, 3, 5, 7] + +// 并 +print("Set Union: ", oddDigits.union(evenDigits).sorted()) + +// 差 +print("Set Subtracting: ", oddDigits.subtracting(singlePrimeDigits).sorted()) + +// 交 +print("Set Intersection: ", oddDigits.intersection(singlePrimeDigits).sorted()) + +// 补 +print("Set SymmetricDifference: ", oddDigits.symmetricDifference(singlePrimeDigits).sorted()) + + +let houseAnimals: Set = ["🐶", "🐱"] +let farmAnimals: Set = ["🐮", "🐑", "🐶", "🐔", "🐱"] +let cityAnimals: Set = ["🐦", "🐭"] + +print(houseAnimals.isSubset(of: farmAnimals)) // 是否是子集 +print(houseAnimals.isStrictSubset(of: farmAnimals)) // 是否是真子集 +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 DictD = [Int:String]() + +DictD[1] = "V1" +DictD[4] = "V2" +DictD[99] = "V3" +DictD[36] = "F4" +if let oldValue = DictD.updateValue("V4", forKey: 36) { // means: if let oldValue = DictD[36] + print("The old value for Key:36 was \(oldValue)") +} + +print("DictD Item Count: ", DictD.count) + +for (k, v) in DictD { + print("Key:", k, " Value: ", v) +} + +for key in DictD.keys.sorted() { + print(key) +} + +for value in DictD.values.sorted() { + print(value) +} + +let keys = [Int](DictD.keys) +print(keys) \ No newline at end of file diff --git a/learn/AcePlay/AcePlay.playground/contents.xcplayground b/learn/AcePlay/AcePlay.playground/contents.xcplayground index 9140691..9baedd5 100644 --- a/learn/AcePlay/AcePlay.playground/contents.xcplayground +++ b/learn/AcePlay/AcePlay.playground/contents.xcplayground @@ -7,5 +7,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 a208718..423c7fc 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