gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:37:07 25 4
gpt4 key购买 nike

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

Cannot call value of non-function type 'SessionManager'

import Alamofire

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

.
.
.

override init() {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 360
configuration.timeoutIntervalForResource = 360 // seconds

self.alamofireManager = AlamofireAPIManager.sharedManager(configuration)
}

有问题的行是:

self.alamofireManager = AlamofireAPIManager.sharedManager(configuration)

如果我将其更改为:

self.alamofireManager = AlamofireAPIManager.init()

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

您知道他在这里想做什么,以及应该如何将其迁移到 Swift 3?谢谢。

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

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)

最佳答案

正在编译:

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
}

关于swift - 无法调用非函数类型的值 'SessionManager',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42729241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com