Swift 错误:'manager()' 不可用:使用对象构造 'AFHTTPRequestOperationManager()'
Swift errors: 'manager()' is unavailable: use object construction 'AFHTTPRequestOperationManager()'
我有这个 swift 代码,我认为它应该可以工作,但它不能处理 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()
我有这个 swift 代码,我认为它应该可以工作,但它不能处理 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()