From: AceVest Date: Mon, 4 Jul 2016 07:27:14 +0000 (+0800) Subject: swift convert X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=78e477a220a5f984afbb7a53597e4b1f63686c99;p=acecode.git swift convert --- diff --git a/learn/AcePlay/AcePlay.playground/Pages/Properties.xcplaygroundpage/Contents.swift b/learn/AcePlay/AcePlay.playground/Pages/Properties.xcplaygroundpage/Contents.swift index e636094..24da0c4 100644 --- a/learn/AcePlay/AcePlay.playground/Pages/Properties.xcplaygroundpage/Contents.swift +++ b/learn/AcePlay/AcePlay.playground/Pages/Properties.xcplaygroundpage/Contents.swift @@ -76,3 +76,22 @@ print("square center is (\(squareCenter.x), \(squareCenter.y))") square.center = Point(x: 15.0, y: 15.0) print("square new origin is (\(square.origin.x), \(square.origin.y))") + + +class Cuboid { + var width = 0.0, height = 0.0, depth = 0.0 + + // 更简单的getter的写法 + var volume: Double { + return width*height*depth + } + + init(width: Double, height: Double, depth: Double) { + self.width = width + self.height = height + self.depth = depth + } +} + +let fourByFiveByTwo = Cuboid(width:4.0, height:5.0, depth:2.0) +print(fourByFiveByTwo.volume) \ 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 1e2cf8b..cdb9f75 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.pbxproj b/learn/AppleSwift/AppleSwift.xcodeproj/project.pbxproj index 79dc39c..c288f4c 100644 --- a/learn/AppleSwift/AppleSwift.xcodeproj/project.pbxproj +++ b/learn/AppleSwift/AppleSwift.xcodeproj/project.pbxproj @@ -88,6 +88,8 @@ 5063B29A1B390AAF009C5821 /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftMigration = 0730; + LastSwiftUpdateCheck = 0730; LastUpgradeCheck = 0630; ORGANIZATIONNAME = Ace; TargetAttributes = { @@ -236,6 +238,7 @@ 5063B2AB1B390AAF009C5821 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; 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 596ab3f..d2eabf6 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 diff --git a/learn/AppleSwift/AppleSwift/main.swift b/learn/AppleSwift/AppleSwift/main.swift index da38bb1..15506f8 100644 --- a/learn/AppleSwift/AppleSwift/main.swift +++ b/learn/AppleSwift/AppleSwift/main.swift @@ -23,22 +23,22 @@ let ss = str + " " + String(Variable) // 类型必需显示转换 // 可以通过在客串中加\()的方式把值转换成字符串 let Int2Str = "translate int in string with \(VarInt) \(ss)" -println(Int2Str) +print(Int2Str) // 数组 var arrayList = ["apple", "microsoft", "xx", "google", "tencent", "twitter"] arrayList[2] = "amazon" -println(arrayList) +print(arrayList) // 字典 var dict = [ "apple" : "USA", "tencnet" : "CN" ] -println(dict) -println(dict["apple"]) -println(dict["apple"]!) +print(dict) +print(dict["apple"]) +print(dict["apple"]!) // 创建空数组和空字典 var EmptyArray = [String]() @@ -48,7 +48,7 @@ var EmptArrayWithNoType = [] var EmptDictWithNoType = [:] for cp in arrayList { - println(cp) + print(cp) } @@ -56,11 +56,11 @@ for cp in arrayList { var OptionalVar:String? = "hehe" //OptionalVar = nil if let name = OptionalVar { - println("Hello \(OptionalVar)") + print("Hello \(OptionalVar)") } else { - println("sssssss") + print("sssssss") } @@ -68,81 +68,81 @@ let word = "ff" switch word { case "dd" : - println("unknown") + print("unknown") case "ff" : - println("fallthrough") + print("fallthrough") fallthrough // 会走到下一个case case "red apple", "blue apple" : - println("red") + print("red") default: // 必须在最后。。。 - println("default"); + print("default"); } // 闭区间 for i in 0...3 { - print(i) + print(i, terminator: "") } -println("") +print("") // 开区间 for i in 0..<3 { - print(i) + print(i, terminator: "") } for i in 0..