sách gpt4 ăn đã đi

objective-c - 无法从 Objective-C 调用 Swift 函数

In lại 作者:搜寻专家 更新时间:2023-11-01 07:29:01 26 4
mua khóa gpt4 giày nike

我想在 Objective-C 中调用 Swift 类中的这个静态函数:

static internal func photoActionSheet(hostAndDelegateViewController:T)

我可以从 ObjC 调用该类中的其他函数,但它不知道只有这个函数

Cảm ơn

câu trả lời hay nhất

具有通用类型约束的函数无法导出到 Objective-C。

作为解决方法,您可以像下面这样定义函数并检查函数实现中的协议(protocol)一致性:

static internal func photoActionSheet(hostAndDelegateViewController: UIViewController) {
guard let vc = hostAndDelegateViewController as? protocol else {
fatalError("hostAndDelegateViewController must conform UINavigationControllerDelegate and UIImagePickerControllerDelegate")
}

// let picker = UIImagePickerController()
// picker.delegate = vc
}

同样,Objective-C 类型 UIViewController *将作为 UIViewController! 导出到 Swift

关于objective-c - 无法从 Objective-C 调用 Swift 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33888719/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress