objective-c - 扩展无法在运行时访问通用参数

标签 objective-c swift amazon-web-services swift3 amazon-cognito

我正在使用 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/

相关文章:

amazon-web-services - Route53 域名不工作(godaddy 域)

ios - 从 Facebook 或 gmail 或任何其他云 iOS 获取与 cncontactstore 的联系

ios - uipageviewcontroller 内的 uiwebview 阻止点击以翻页

iphone - 左侧的 UITableView 图像

ios - 如何使用 Swift 仅对图像的某些角进行圆角处理

amazon-web-services - AWS SES 554-无适用于 web.de 和 GMX 电子邮件地址的 SMTP 服务

postgresql - AWS RDS Proxy 可以直接与读复制实例配对吗?

ios - Objective C 中是否需要 init()

ios - 类方法中的实例方法swift

ios - 从不同的文件更新 TableView - 无法不带参数调用 'reloadData'