pragma – silence a warning in Swift?

[ad_1]

There is no such thing as a normal assemble to silence deprecation warnings in Swift, however there’s a workaround that may be utilized in lots of instances.

As an instance you may have a technique getLatestImage() on class Foo which makes use of deprecated strategies/lessons.

Use @out there as Daniel Thorpe described to silence all of the warnings inside the strategy:

@out there(iOS, deprecated: 9.0)
func getLatestImage() -> UIImage? {
    ...
}

Now you wish to name the strategy getLatestImage() with out having a deprecation warning. You possibly can obtain that by first defining a protocol and an extension:

personal protocol GetLatestImage {
    func getLatestImage() -> UIImage?
}
extension Foo: GetLatestImage {}

After which name the strategy and not using a deprecation warning.

If foo is an occasion of Foo:

(foo as GetLatestImage).getLatestImage() // no deprecation warning

If you wish to name a static property/perform of Foo:

(Foo.self as GetLatestImage.Kind).someStaticProperty

The result’s you may have Swift code that makes use of deprecated API with none deprecation warnings.

[ad_2]

Leave a Reply