1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
# Deprecated Declaration Warnings (`DeprecatedDeclaration`)
This diagnostic group includes warnings related to deprecated APIs that may be removed in future versions and should be replaced with more current alternatives.
The `DeprecatedDeclaration` group covers the following warnings:
- Use of a function annotated with `@available(<platform>, deprecated: <version>)`
```swift
@available(iOS, deprecated: 10.0)
func oldFunction() {
// This function is deprecated and should not be used.
}
oldFunction() // 'oldFunction()' is deprecated
```
- Use of a function annotated with `@available(<platform>, deprecated: <version>, renamed: "<new name>")`
```swift
@available(iOS, deprecated: 10.0, renamed: "newFunction")
func oldFunction() {
// This function is deprecated and should not be used.
}
oldFunction() // 'oldFunction()' is deprecated: renamed to 'newFunction'
```
- Use of a type as an instance of a protocol when the type's conformance to the protocol is marked as deprecated
```swift
struct S {}
protocol P {}
@available(*, deprecated)
extension S: P {}
func f(_ p: some P) {}
func test() {
f(S()) // Conformance of 'S' to 'P' is deprecated
}
```
- When a protocol requirement has a default implementation marked as `deprecated` and the type conforming to the protocol doesn't provide that requirement
```swift
protocol P {
func f()
func g()
}
extension P {
@available(*, deprecated)
func f() {}
@available(*, deprecated, message: "write it yourself")
func g() {}
}
struct S: P {} // deprecated default implementation is used to satisfy instance method 'f()' required by protocol 'P'
// deprecated default implementation is used to satisfy instance method 'g()' required by protocol 'P': write it yourself
```
- When a protocol requirement has been deprecated
```swift
struct S: Hashable {
var hashValue: Int { // 'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'S' to 'Hashable' by implementing 'hash(into:)' instead
...
}
}
final class C: Executor {
func enqueue(_ job: __owned Job) {} // 'Executor.enqueue(Job)' is deprecated as a protocol requirement; conform type 'C' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead
}
```
## Usage Example
```sh
swiftc -Werror DeprecatedDeclaration file.swift
swiftc -warnings-as-errors -Wwarning DeprecatedDeclaration file.swift
```
|