Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */,
Expand Down
36 changes: 19 additions & 17 deletions 003_swift_http_test/TestHttp/TestHttp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var word = "swift"
var request = HTTPTask()
var params: Dictionary<String, AnyObject> = ["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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down