[英]Success & failure block written in Objective C, showing error in swift
I have made a success & failure block in objC and I am trying to use that function in swift. 我已经在objC中创建了成功与失败块,并且我试图快速使用该功能。 Getting error, I'm stuck on it please help me. 遇到错误,我坚持下去,请帮助我。
Objective C : 目标C:
-(void)registerAppWithSuccessBlock:(void (^)(id responseObject))success andFailureBlock:(void (^)(NSError *error))failure{}
I am calling the same function in swift its showing error. 我正在迅速调用同一函数来显示错误。
Swift : 斯威夫特:
USSecService.sharedInstance().registerAppWithSuccessBlock({(responseObject : AnyObject) -> Void in{code}
}, andFailureBlock: { (error : NSError) -> Void in {code}
})
Getting this Error : 出现此错误:
Cannot invoke 'registerAppWithSuccessBlock' with an argument list of type '((AnyObject) -> Void, andFailureBlock: (NSError) -> Void)'
USSecService.sharedInstance().registerAppWithSuccessBlock({ (responseObject) -> Void in
print("Success")
}, andFailureBlock: { (error) -> Void in
print("Failure")
})
You don't need to specify the argument type in those closures. 您无需在这些闭包中指定参数类型。 Change your swift code like below: 如下更改您的快速代码:
Without second closure label syntax: 没有第二个闭包标签语法:
USSecService.sharedInstance().registerAppWithSuccessBlock({ (responseObject) -> Void in
// Your success code
}){ (error) -> Void in
// Your error code
}
or 要么
With second closure label syntax: 使用第二个闭包标签语法:
USSecService.sharedInstance().registerAppWithSuccessBlock({ (responseObject) -> Void in
// Your success code
}, andFailureBlock: ({ (error) -> Void in
// Your error code
}))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.