AFNetworking 不工作

AFNetworking not working

我是 swift 和 iOS 开发的新手,我在使用 AFNetworking 时遇到了一些问题。我正在使用取自 here 的以下代码:

class AFNetCmd {


final func go () {
    let manager: AFHTTPRequestOperationManager = AFHTTPRequestOperationManager()


    manager.GET( "http://www.google.ca/",
        parameters: nil,
        success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in
            println("JSON: " + responseObject.description)
        },
        failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in
            println("Error: " + error.localizedDescription)
    })

    }
}

let test: AFNetCmd = AFNetCmd()
test.go()'

没有代码打印出来,虽然我知道代码块将在任何请求之前退出 returns 因为 AFNetworking 是异步的,我想知道如何让它执行?

我也 运行 它使用:

dispatch_sync(dispatch_get_main_queue(), { () -> Void in
            self.go()
        })

但我仍然一无所获。

编辑:

根据我试过的评论:

class AFNetCmd {

final func go () {
    let manager: AFHTTPRequestOperationManager = AFHTTPRequestOperationManager()


    manager.GET( "http://www.google.ca/",
        parameters: nil,
        success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in
            println("JSON: " + responseObject.description)
        },
        failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in
            println("Error: " + error.localizedDescription)
    }).start()

    }
}

let test: AFNetCmd = AFNetCmd()
test.go()'

问题依旧。我也尝试了 .waitUntilFinished() 方法。此外,我尝试使用 Alamofire 发送请求,但出现了同样的问题。请注意,我正在创建一个 OSX 命令行应用程序,它在 xcode 中是 运行。是否有一些设置阻止了网络连接?

我不想回答我自己的问题,但出于某种原因,它不会 运行 作为 swift 命令行应用程序。我创建了一个 iOS 应用程序并在模拟器中 运行 它运行良好。它不会 运行 网络代码作为命令行应用程序的任何原因?