Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

ios - How to manually deprecate members

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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the Available tag, for example :

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

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() {
    // ...
}

More details in the Swift documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...