Dear Swift Evolution Community,
I am writing to formally initiate a discussion on a design enhancement proposal that concerns the current limitations surrounding optional method declarations in Swift protocols.
As previously outlined, the existing approach — which mandates the use of @objc
and its associated runtime — introduces a reliance on Objective-C semantics that runs counter to Swift's guiding principles of type safety, clarity, and native expressiveness. More critically, it restricts the use of Swift-native types such as structs and enums in optional protocol methods, resulting in compiler diagnostics that obstruct certain architectural designs.
This proposal suggests two avenues for language evolution:
- Introducing Swift-native syntax for optional methods within protocols, e.g.:
swift
protocol MyDelegate {
@required func didTapButton()
@optional func didUpdate(value: Int)
}
Such a syntax would allow for clearer declaration intent, while removing the dependency on Objective-C interop for optionality. This aligns with Swift’s ongoing evolution toward a self-contained and purely Swift-native ecosystem.
2. Extending compiler support to permit optional methods with Swift-native parameter types — potentially through default implementations, compiler synthesis, or static analysis. This would preserve compile-time safety while enabling greater flexibility in protocol design.
These additions would serve to enhance the ergonomics of protocol-oriented programming in Swift, particularly in patterns such as delegation or event handling, without incurring the conceptual or technical costs of bridging to Objective-C.
I would very much welcome feedback from this community — both in terms of the merits of such a direction, and on the feasibility and scope of implementation — before pursuing a formal Swift Evolution proposal (pitch).
Thank you for your time and thoughtful consideration.
Warm regards
keisuke yamagishi