swift - Swift:关于使用类型别名屏蔽选项的约定?
问题描述
关于使用掩码可选的类型别名是否有任何约定?例如,如果我想为详细的可选类型(例如 )创建类型别名UnsafeMutablePointer<Bar>?
,我可以执行以下任一操作:
// Approach 1 - mask the optional in the type alias
typealias Foo = UnsafeMutablePointer<Bar>?
func bat(baz: Foo) { ... }
// Approach 2 - include the optional in the typealias usage where needed
typealias Foo = UnsafeMutablePointer<Bar>
func bat(baz: Foo?) { ... }
这些方法完成了同样的事情,尽管我认为第二种方法更可取,因为函数参数是可选的似乎更明确。
是否存在第一种方法可能更可取的情况,是否有任何指导方针支持/反对这种用法?
解决方案
推荐阅读
- javascript - 如何使用 for 循环将对象数组转换为数组列表
- javascript - 即使父进程终止,如何使子进程保持活动状态
- android - 当我们不在 getLastLocation() 中时,最后一个已知位置丢失 - Android
- php - 使用 Codeigniter 3 在电子邮件页脚添加徽标图像
- rust - 使用 Clap 获取自己的参数的 CLI 参数
- python - 如何在熊猫数据框中添加另一个配对列?
- c++ - QT qmysql 驱动程序未加载
- flutter - 在颤动中填充图像的背景颜色
- ios - 将 EnvironmentObject 传递给 ObservableObject 类
- git - 如何使用 git diff 比较不在存储库中的两个远程文件?