[swift-users] matching a protocol value in multiple patterns is not yet supported; use separate cases instead
Zhao Xin
owenzx at gmail.com
Tue Jul 18 20:16:46 CDT 2017
I encounter this error today. "matching a protocol value in multiple
patterns is not yet supported; use separate cases instead"
Sample code:
import Foundation
protocol NameProtocol {
var name:String { get }
}
struct Cat:NameProtocol {
let name:String
}
struct Dog:NameProtocol {
let name: String
}
enum AnimalType {
case catType(cat:NameProtocol)
case dogType(dog:NameProtocol)
}
struct Animal {
let type:AnimalType
func printName() {
switch type {
case .catType(let animal), // matching a protocol value in multiple
patterns is not yet supported; use separate cases instead
.dogType(let animal):
print(animal.name)
}
}
}
let cat = Cat(name: "kitty")
let catType = AnimalType.catType(cat: cat)
let animal = Animal(type: catType)
animal.printName()
I am wondering which proposal this is? And will it be implemented in Swift
4.0? I search the error as keywords, but didn't get the expected results.
Zhao Xin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170719/e2af2786/attachment.html>
More information about the swift-users
mailing list