Swift - 如何弃用 SPM 库中的函数

问题描述

我们正在维护一个私有 SPM 库,我想介绍一个应该使用的函数,而不是现有函数。最终结果应该是某种弃用

到目前为止,我发现可以相对于操作系统版本弃用函数,但我需要相对于库版本弃用它。

例如:

//how do I deprecate this function as of version `1.1.0` of my library?
func oldFunc() {
    ...
}

//It will be awesome if I Could also mention that this function is the newer alternative to `oldFunc`
func newFunc() {
    ...
}

解决方法

你可以使用这样的东西:

@available(*,deprecated,renamed: "newFunction")
func sampleFunction() { }