[swift-evolution] [Proposal] Switch Let

Eduardo Mourey Lopez Ne edmourey at icloud.com
Wed May 18 22:28:38 CDT 2016


I will like to make the proposal to allow a switch let, similar to a if let, this will avoid having to repeat every variable name

enum Barcode {
    case UPCA(Int, Int, Int, Int)
    case QRCode(String)
var productBarcode = Barcode.UPCA(8, 85909, 51226, 3)

switch productBarcode {
case .UPCA(let numberSystem, let manufacturer, let product, let check):
    print("UPC-A: \(numberSystem), \(manufacturer), \(product), \(check).")
case .QRCode(let productCode):
    print("QR code: \(productCode).")
switch let p = productBarcode {
case .UPCA:
    print("UPC-A: \(p.numberSystem), \(p.manufacturer), \(p.product), \(p.check).")
case .QRCode:
    print("QR code: \(p.productCode).")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160518/d3156f18/attachment-0001.html>

More information about the swift-evolution mailing list