swiftswift-protocols

What's the point of conforming to an empty protocol in Swift


I'm just working on a codebase where the most classes conform to an empty protocol. Is there any point of doing so? Actually conforming that protocol does nothing.

Edit as reaction to @vacawama's helpful comment : the protocol is only used once

import Foundation

protocol myUrlRequestConfig {}

extension myUrlRequest: myUrlRequestConfig {
    public static func configGetAppConfig() -> URLRequest {
        let request = ....
        return request
    }
}

Solution

  • Our app has three perfectly legitimate uses for an empty protocol: