# How do you properly deprecate a method in a Protocol?

**URL:** <https://forums.swift.org/t/how-do-you-properly-deprecate-a-method-in-a-protocol/13347>\
**Category:** Using Swift\
**Tags:** protocols, deprecation, availability\
**Created:** [June 7, 2018, 3:22pm UTC](https://forums.swift.org/t/how-do-you-properly-deprecate-a-method-in-a-protocol/13347 "2018-06-07T15:22:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arthur](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/arthur/32/1375_2.png) [@Arthur](https://forums.swift.org/u/Arthur)\
**Post date:** [June 7, 2018, 3:22pm UTC](https://forums.swift.org/t/how-do-you-properly-deprecate-a-method-in-a-protocol/13347/1 "2018-06-07T15:22:15Z")

</div>

Without using `@objc @optional`, is there a way to properly deprecate a function in a protocol? I cannot make use of the Objective-C runtime because I tend to have `struct` types conforming to this protocol.

Trivialized example:

```swift
protocol P {
    @available(*, deprecated: 1.0.1, renamed: "g")
    func f(x: Int)

    func g(x: Int, y: String)
}

struct S: P { // Complains that "Type 'S' does not conform to Protocol 'P'"

    func g(x: Int, y: String) {

    }

}

```

Obviously, I could just remove the method, however, I'd like to notify the user that the method was renamed and allow the compiler to offer a fix.

Thanks for your time.

---

<div class="post-metadata">

**Author:** ![nuclearace](https://avatars.discourse-cdn.com/v4/letter/n/51bf81/32.png) [@nuclearace](https://forums.swift.org/u/nuclearace)\
**Post date:** [June 7, 2018, 3:25pm UTC](https://forums.swift.org/t/how-do-you-properly-deprecate-a-method-in-a-protocol/13347/2 "2018-06-07T15:25:48Z")

</div>

You could add a default implementation on the protocol that does nothing.

---

<div class="post-metadata">

**Author:** ![Arthur](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/arthur/32/1375_2.png) [@Arthur](https://forums.swift.org/u/Arthur)\
**Post date:** [June 7, 2018, 3:26pm UTC](https://forums.swift.org/t/how-do-you-properly-deprecate-a-method-in-a-protocol/13347/3 "2018-06-07T15:26:26Z")

</div>

Right, I could do that, but that doesn't inform consumers of previous versions of my library that a method was deprecated.

---

<div class="post-metadata">

**Author:** ![nuclearace](https://avatars.discourse-cdn.com/v4/letter/n/51bf81/32.png) [@nuclearace](https://forums.swift.org/u/nuclearace)\
**Post date:** [June 7, 2018, 3:40pm UTC](https://forums.swift.org/t/how-do-you-properly-deprecate-a-method-in-a-protocol/13347/5 "2018-06-07T15:40:41Z")

</div>

No, but the fact that you've added a new requirement to the protocol is going to do that as well, since they'll suddenly get an error about a new requirement, which they'll have to lookup.

I believe it would be an IDE feature to warn users they're implementing a deprecated method. I'm not sure if that deserves its own language feature. I believe Xcode already shows such methods as being crossed out.

---

<div class="post-metadata">

**Author:** ![Arthur](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/arthur/32/1375_2.png) [@Arthur](https://forums.swift.org/u/Arthur)\
**Post date:** [June 7, 2018, 4:56pm UTC](https://forums.swift.org/t/how-do-you-properly-deprecate-a-method-in-a-protocol/13347/6 "2018-06-07T16:56:19Z")

</div>

Right, they'll be able to get the new requirement, but they won't no the other one was deprecated and renamed to to this new one without looking at the method definition.

My hope is that it would be a feature of the compiler or IDE to error+correct the user like it does for classes and structs.

---

<div class="post-metadata">

**Author:** ![lancep](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lancep/32/1509_2.png) [@lancep](https://forums.swift.org/u/lancep)\
**Post date:** [June 8, 2018, 4:08am UTC](https://forums.swift.org/t/how-do-you-properly-deprecate-a-method-in-a-protocol/13347/7 "2018-06-08T04:08:57Z")

</div>

Swift would need a way for the method in the conforming type to be marked so it's clear it's fulfilling a protocol requirement. This has been discussed in the past here:  
[https://forums.swift.org/t/keyword-for-protocol-conformance](https://forums.swift.org/t/keyword-for-protocol-conformance)

---

<div class="post-metadata">

**Author:** ![Arthur](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/arthur/32/1375_2.png) [@Arthur](https://forums.swift.org/u/Arthur)\
**Post date:** [June 8, 2018, 2:37pm UTC](https://forums.swift.org/t/how-do-you-properly-deprecate-a-method-in-a-protocol/13347/8 "2018-06-08T14:37:56Z")

</div>

Wow! It looks like it's been discussed on multiple occasions, but never to any real solid conclusion.

Thanks, @lancep!

---

<div class="post-metadata">

**Author:** ![Arthur](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/arthur/32/1375_2.png) [@Arthur](https://forums.swift.org/u/Arthur)\
**Post date:** [June 8, 2018, 2:42pm UTC](https://forums.swift.org/t/how-do-you-properly-deprecate-a-method-in-a-protocol/13347/9 "2018-06-08T14:42:54Z")

</div>

Do you have any personal recommendations on how you feel this should be done?
