无法调用非函数类型的值' SessionManager'

时间:2017-03-10 23:10:22

标签: swift session swift3 migration alamofire

我试图将其他人的代码迁移到Swift 3.一切都进行得很顺利,除了我无法弄清楚的一条线路。它在Swift 2.2中工作正常,但不能在Swift 3中编译。它返回错误:

  

无法调用非功能类型的值' SessionManager'

self.alamofireManager = AlamofireAPIManager.sharedManager(configuration)

有问题的一行是:

self.alamofireManager = AlamofireAPIManager.init()

如果我将其更改为:

import Alamofire

struct AlamofireAPIManager {
    static let sharedManager: Manager = {
        let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
        configuration.timeoutIntervalForRequest = 360 // 120 seconds
        configuration.timeoutIntervalForResource = 360
        return Manager(configuration: configuration)
    }()
}

.
.
. 

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.timeoutIntervalForRequest = 360
configuration.timeoutIntervalForResource = 360 // seconds

self.alamofireManager = Alamofire.Manager(configuration: configuration)

它会编译,但是应用程序无法正常工作。

你知道他在这里做了什么,以及将它迁移到Swift 3应该怎么做?感谢。

**编辑:这是原始代码,在任何迁移之前:

v0.14.0

Changed

Firefox process is now terminated and session ended when the last window is closed
WebDriver library updated to version 0.20.0

1 个答案:

答案 0 :(得分:0)

这是编译:

import AlamoFire

struct AlamofireAPIManager {
    static let sharedManager: SessionManager = {
        let configuration = URLSessionConfiguration.default
        configuration.timeoutIntervalForRequest = 360 // 120 seconds
        configuration.timeoutIntervalForResource = 360
        return SessionManager(configuration: configuration)
    }()
}

func i() {
    let alamofireManager = AlamofireAPIManager.sharedManager
}