本文介绍了如何手动弃用成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与Objective-C不同,Swift没有预处理器,那么还有办法手动弃用类的成员吗?

Unlike Objective-C, Swift has no preprocessor, so is there still a way to manually deprecate members of a class?

我正在寻找类似于此的东西:

I am looking for something similar to this:

-(id)method __deprecated;


推荐答案

您可以使用可用的标签,例如:

You can use the available tag, for example :

@available(*, deprecated)
func myFunc() {
    // ...
}

其中*是平台(iOS,iOSApplicationExtension,macOS,watchOS,tvOS,* for所有等等。)

Where * is the platform (iOS, iOSApplicationExtension, macOS, watchOS, tvOS, * for all, etc.).

您还可以指定介绍的平台版本已弃用已废弃已重命名,以及消息

You can also specify the version of the platform from which it was introduced, deprecated, obsoleted, renamed, and a message :

@available(iOS, deprecated:6.0)
func myFunc() {
    // calling this function is deprecated on iOS6+
}

Or

@available(iOS, deprecated: 6.0, obsoleted: 7.0, message: "Because !")
func myFunc() {
    // deprecated from iOS6, and obsoleted after iOS7, the message "Because !" is displayed in XCode warnings
}

如果您的项目面向多个平台,则可以使用多个像这样的标签:

If your project targets multiple platforms, you can use several tags like so :

@available(tvOS, deprecated:9.0.1)
@available(iOS, deprecated:9.1)
@available(macOS, unavailable, message: "Unavailable on macOS")
func myFunc() {
    // ...
}

关于。

这篇关于如何手动弃用成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 08:44