假设我有协议:
protocol FooProtocol{
func bar<Request: Codable, Response: Codable>()
}
我有课:
class Foo: FooProtocol { //Xcode complains here about protocol conformance with a fix button
}
如果我点击Xcode自动完成来修复协议一致性,就会生成以下函数:
class Foo: FooProtocol {
func bar<Request, Response>() where Request : Decodable, Request : Encodable, Response : Decodable, Response : Encodable {
}
}
不是很漂亮。我必须手动重写函数:
func bar<Request: Codable, Response: Codable>()
有没有办法改变Xcode中的这种行为?
否。所有的标准库也是以这种令人发指的方式格式化的。
struct Dictionary<Key, Value> where Key : Hashable {
https://developer.apple.com/documentation/combine/publishers/combinelatest4
https://developer.apple.com/documentation/swift/int/2884879-init