Avatar ·

How to declare optional methods in Swift protocols?

Hello everyone! I'm new to Swift and trying to understand protocols. I have a protocol `MyDelegate` that contains several methods. I want some of these methods to be optional to implement — meaning the class that adopts the protocol can skip implementing them if they are not needed.\n\nIn Objective-C I just used `@optional`, but this doesn't work in Swift. For example, I have this code:\n\n```swift\nprotocol MyDelegate {\n func didStartTask()\n func didFinishTask()\n func didFailWithError(error: Error) // I want to make this method optional\n}\n```\n\nWhen I try to write `@optional` before the method, the compiler complains: "Optional requirements are only supported in @objc protocols". I don't want to use `@objc` because my class doesn't inherit