diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..46ed83d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "003_swift_http_test/TestHttp/TestHttp/SwiftHTTP"] + path = 003_swift_http_test/TestHttp/TestHttp/SwiftHTTP + url = https://github.com/elizhang/SwiftHTTP.git diff --git a/001_swift_counter/SwiftCounter/SwiftCounter/CounterViewController.swift b/001_swift_counter/SwiftCounter/SwiftCounter/CounterViewController.swift index 8238acd..76fb79e 100644 --- a/001_swift_counter/SwiftCounter/SwiftCounter/CounterViewController.swift +++ b/001_swift_counter/SwiftCounter/SwiftCounter/CounterViewController.swift @@ -14,7 +14,7 @@ class CounterViewController: UIViewController { var timeLabel: UILabel? //显示剩余时间 var startStopButton: UIButton? //开始/停止按钮 var clearButton: UIButton? //复位按钮 - var timeButtons: UIButton[]? //设置时间的按钮数组 + var timeButtons: [UIButton]? //设置时间的按钮数组 let timeButtonInfos = [("1分", 60), ("3分", 180), ("5分", 300), ("秒", 1)] var remainingSeconds: Int = 0 { @@ -99,7 +99,7 @@ class CounterViewController: UIViewController { func setuptimeButtons() { - var buttons: UIButton[] = [] + var buttons: [UIButton] = [] for (index, (title, _)) in enumerate(timeButtonInfos) { let button: UIButton = UIButton() diff --git a/003_swift_http_test/TestHttp/TestHttp.xcodeproj/project.pbxproj b/003_swift_http_test/TestHttp/TestHttp.xcodeproj/project.pbxproj index 34ee6bc..d715e1b 100644 --- a/003_swift_http_test/TestHttp/TestHttp.xcodeproj/project.pbxproj +++ b/003_swift_http_test/TestHttp/TestHttp.xcodeproj/project.pbxproj @@ -17,7 +17,6 @@ 3FF1ABB8195A4201008F9130 /* HTTPTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FF1ABB1195A4201008F9130 /* HTTPTask.swift */; }; 3FF1ABB9195A4201008F9130 /* HTTPUpload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FF1ABB2195A4201008F9130 /* HTTPUpload.swift */; }; 3FF1ABBA195A4201008F9130 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 3FF1ABB3195A4201008F9130 /* LICENSE */; }; - 3FF1ABBB195A4201008F9130 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 3FF1ABB4195A4201008F9130 /* README.md */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -244,7 +243,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 3FF1ABBB195A4201008F9130 /* README.md in Sources */, 3FF1ABB8195A4201008F9130 /* HTTPTask.swift in Sources */, 3FF1ABB9195A4201008F9130 /* HTTPUpload.swift in Sources */, 3FF1AB96195A41D6008F9130 /* AppDelegate.swift in Sources */, diff --git a/003_swift_http_test/TestHttp/TestHttp/AppDelegate.swift b/003_swift_http_test/TestHttp/TestHttp/AppDelegate.swift index 2f0b3f0..c901620 100644 --- a/003_swift_http_test/TestHttp/TestHttp/AppDelegate.swift +++ b/003_swift_http_test/TestHttp/TestHttp/AppDelegate.swift @@ -24,26 +24,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var word = "swift" var request = HTTPTask() var params: Dictionary = ["w": word, "key": "30CBA9DDD34B16DB669A9B214C941F14", "type": "json"] - request.GET("http://dict-co.iciba.com/api/dictionary.php", parameters: params, success: {(response: AnyObject?) -> Void in + request.GET("http://dict-co.iciba.com/api/dictionary.php", parameters: params, success: {(response: HTTPResponse) -> Void in - //转换成JSON数据 - let json = JSONValue(response!) - - //得到JSON中第一个解释 - let meaning = json["symbols"][0]["parts"][0]["means"] - - dispatch_async(dispatch_get_main_queue(), { + if let responseObject: AnyObject = response.responseObject { + //转换成JSON数据 + let json = JSONValue(responseObject) - //注意,`SwiftHTTP`回调中如果要操作UI,必须先用gcd切换到主线程 - let alert = UIAlertView() - alert.title = word - alert.message = meaning.description - alert.addButtonWithTitle("确定") - alert.show() + //得到JSON中第一个解释 + let meaning = json["symbols"][0]["parts"][0]["means"] - }) - - println("\(json)") + dispatch_async(dispatch_get_main_queue(), { + + //注意,`SwiftHTTP`回调中如果要操作UI,必须先用gcd切换到主线程 + let alert = UIAlertView() + alert.title = word + alert.message = meaning.description + alert.addButtonWithTitle("确定") + alert.show() + + }) + + println("\(json)") + } },failure: {(error: NSError) -> Void in diff --git a/003_swift_http_test/TestHttp/TestHttp/SwiftHTTP b/003_swift_http_test/TestHttp/TestHttp/SwiftHTTP index f057044..819a77a 160000 --- a/003_swift_http_test/TestHttp/TestHttp/SwiftHTTP +++ b/003_swift_http_test/TestHttp/TestHttp/SwiftHTTP @@ -1 +1 @@ -Subproject commit f057044126069d25d59352f4153d767859ec8951 +Subproject commit 819a77a476f9e8d63c699e3e2771cbbb787703d6 diff --git a/003_swift_http_test/TestHttp/TestHttp/SwiftyJSON/SwiftyJSON.swift b/003_swift_http_test/TestHttp/TestHttp/SwiftyJSON/SwiftyJSON.swift index 3afd205..6bfeb62 100644 --- a/003_swift_http_test/TestHttp/TestHttp/SwiftyJSON/SwiftyJSON.swift +++ b/003_swift_http_test/TestHttp/TestHttp/SwiftyJSON/SwiftyJSON.swift @@ -100,7 +100,7 @@ enum JSONValue: Printable { case let value as NSNull: self = .JNull case let value as NSArray: - var jsonValues = JSONValue[]() + var jsonValues = [JSONValue]() for possibleJsonValue : AnyObject in value { let jsonValue = JSONValue(possibleJsonValue) if jsonValue {