我正在使用 AWS Cognito,在文档中它说我必须添加此功能。
但是我收到了这个错误:
通用 Objective-C 类的扩展无法在运行时访问该类的通用参数
extension AWSTask {
public func continueWithExceptionCheckingBlock(completionBlock:@escaping (_ result: Any?, _ error: Error?) -> Void) {
self.continue({(task: AWSTask) -> Any? in
if let exception = task.exception {
print("Fatal exception: \(exception)")
kill(getpid(), SIGKILL);
}
let result: AnyObject? = task.result
let error: NSError? = task.error as NSError?
completionBlock(result, error)
return nil
})
}
}
最佳答案
对于那些在 Swift 5 中遇到此问题的人,请尝试在方法中添加 @objc
修饰符。请在下面找到示例:
extension NSLayoutAnchor {
@objc func constrainEqual(_ anchor: NSLayoutAnchor<AnchorType>, constant: CGFloat = 0) {
let constraint = self.constraint(equalTo: anchor, constant: constant)
constraint.isActive = true
}
}
关于objective-c - 扩展无法在运行时访问通用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41700331/