ios - typealias 泛型函数变量
问题描述
我在A 类中有以下函数声明
typealias Callback<T> = (Result<T>) -> ()
试图在B 类中声明变量
var callbackVariable: A.Callback<T>?
编译器说:使用未声明的类型“T”
如何在 B 类中声明变量?
解决方案
您需要:
- 为 T 指定类型
- 或者,也将 B 类设为通用。
// 1. Specify a type for T
class B {
var callbackVariable: A.Callback<String>? // Or some other type
}
// 2. Or, make the B class generic as well.
class B<T> {
var callbackVariable: A.Callback<T>?
}
推荐阅读
- excel - 如何在excel中提取特定文本?
- python - Python Tkinter:在帧之间传递日历选择
- python - python 3.8的Openssl问题
- javascript - 如何在游戏状态为暂停时停止游戏的播放列表,并在游戏完成暂停状态后重新播放?JavaScript
- reactjs - React & Axios - 从对象内部的对象中获取值
- python - 在电子邮件主题中添加变量
- tailwind-css - How to create alert in tailwindcss like the alert api in material-ui?
- c# - Why the reverse is not working ? and how can I add the rotation part?
- java - 如何从另一个类访问主类中的变量
- javascript - 如何使用 React Hooks 执行错误边界