gpt4 book ai didi

objective-c - swift 错误 : 'manager()' is unavailable: use object construction 'AFHTTPRequestOperationManager()'

转载 作者:搜寻专家 更新时间:2023-10-31 08:16:59 24 4
gpt4 key购买 nike

我有这个快速代码,我认为它应该可以工作,但它不能处理 objective-c 静态字段。我尝试在多个地方添加“()”,但没有任何效果。

func AFHTTPRequestOperationManagerDispatchOnMainQueue(mainQueue: Bool) -> AFHTTPRequestOperationManager {
var manager = AFHTTPRequestOperationManager.manager
manager.responseSerializer = AFJSONResponseSerializer(readingOptions: NSJSONReadingOptions.AllowFragments)
manager.requestSerializer = AFJSONRequestSerializer(readingOptions: NSJSONReadingOptions.AllowFragments)
if (!mainQueue) {
manager.completionQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
}
return manager;
}

字段和属性如下所示:

+ (instancetype)manager;
@property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer;
@property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer;

我收到这些错误消息:

Error: 'manager()' is unavailable: use object construction 'AFHTTPRequestOperationManager()'
Error: '() -> AFHTTPRequestOperationManager!' does not have a member named 'responseSerializer'
Error: '() -> AFHTTPRequestOperationManager!' does not have a member named 'requestSerializer'
Error: '() -> AFHTTPRequestOperationManager!' does not have a member named 'completionQueue'
Error: function produces expected type 'AFHTTPRequestOperationManager!'; did you mean to call it with '()'?

最佳答案

当 Objective-C 导入 Swift 时,正如您在此处使用 AFNetworking 所做的那样,可识别的工厂方法将转换为简单的初始化程序。在这种情况下,这意味着(正如@Martin 指出的那样)您应该改用该表格:

var manager = AFHTTPRequestOperationManager()

关于objective-c - swift 错误 : 'manager()' is unavailable: use object construction 'AFHTTPRequestOperationManager()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27925127/

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