将外部函数的部分数据另存为xcode中的全局变量

时间:2018-08-16 22:51:57

标签: swift variables urlsession

我正在从主ViewController调用外部函数,但是该外部函数只能打印。

该函数包含一些URL会话数据(称为megabytesPerSecond),我想将其另存为我的主ViewController中的变量,但是我无法将那部分信息存储到我的主ViewController中可以识别的变量中。

connectedSpeed().testDownloadSpeedWithTimout(timeout: 5.0) { (megabytesPerSecond, error) -> () in
    if ((error == nil) && isReachable && !needsConnection) {
        if megabytesPerSecond!>=0.05 {
            //print("\n       | Connected |")
            print("=======Network Speed=======\nMBps: \(megabytesPerSecond!)\nerror: \(String(describing: error))\n=======-------------=======\n")
        }else{
            //print("\n       ? Connected ?")
            print("*======| WEAK SIGNAL |======*\nMBps: \(megabytesPerSecond!)\nerror: \(String(describing: error))\n*=======-------------=======*\n")
        }
    }else{
        print("NETWORK ERROR: \(String(describing: error))")

        return
    }
}

0 个答案:

没有答案