# \[Proposal\] Switch Let

**URL:** <https://forums.swift.org/t/proposal-switch-let/2686>\
**Category:** Discussion\
**Created:** [May 19, 2016, 3:28am UTC](https://forums.swift.org/t/proposal-switch-let/2686 "2016-05-19T03:28:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eduardo\_Mourey\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/cc9497/32.png) [@Eduardo\_Mourey\_Lopez](https://forums.swift.org/u/Eduardo_Mourey_Lopez)\
**Post date:** [May 19, 2016, 3:28am UTC](https://forums.swift.org/t/proposal-switch-let/2686/1 "2016-05-19T03:28:38Z")

</div>

Hi

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 {  
&nbsp;&nbsp;&nbsp;&nbsp;case UPCA(Int, Int, Int, Int)  
&nbsp;&nbsp;&nbsp;&nbsp;case QRCode(String)  
}  
var productBarcode = Barcode.UPCA(8, 85909, 51226, 3)

//current:  
switch productBarcode {  
case .UPCA(let numberSystem, let manufacturer, let product, let check):  
&nbsp;&nbsp;&nbsp;&nbsp;print("UPC-A: \(numberSystem), \(manufacturer), \(product), \(check).")  
case .QRCode(let productCode):  
&nbsp;&nbsp;&nbsp;&nbsp;print("QR code: \(productCode).")  
}  
//suggestion:  
switch let p = productBarcode {  
case .UPCA:  
&nbsp;&nbsp;&nbsp;&nbsp;print("UPC-A: \(p.numberSystem), \(p.manufacturer), \(p.product), \(p.check).")  
case .QRCode:  
&nbsp;&nbsp;&nbsp;&nbsp;print("QR code: \(p.productCode).")  
}

---

<div class="post-metadata">

**Author:** ![Jed\_Lewison](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@Jed\_Lewison](https://forums.swift.org/u/Jed_Lewison)\
**Post date:** [May 19, 2016, 3:40am UTC](https://forums.swift.org/t/proposal-switch-let/2686/2 "2016-05-19T03:40:20Z")

</div>

You can already do something pretty close to what you want:

enum Barcode {  
&nbsp;&nbsp;&nbsp;&nbsp;case UPCA(numberSystem: Int, manufacturer: Int, product: Int, check: Int)  
&nbsp;&nbsp;&nbsp;&nbsp;case QRCode(productCode: String)  
}

var productBarcode = Barcode.UPCA(numberSystem: 8, manufacturer: 85909, product: 51226, check: 3)

switch productBarcode {  
case .UPCA(let p):  
&nbsp;&nbsp;&nbsp;&nbsp;print("UPC-A: \(p.numberSystem), \(p.manufacturer), \(p.product), \(p.check).")  
case .QRCode(let p):  
&nbsp;&nbsp;&nbsp;&nbsp;print("QR code: \(p.productCode).")  
}

(Note that you need to label the tuple elements, or use p.0, p.1, etc.)

> **···**
>
> > On May 18, 2016, at 8:28 PM, Eduardo Mourey Lopez Ne via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > Hi
> > 
> > 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 {  
> > &nbsp;&nbsp;&nbsp;&nbsp;case UPCA(Int, Int, Int, Int)  
> > &nbsp;&nbsp;&nbsp;&nbsp;case QRCode(String)  
> > }  
> > var productBarcode = Barcode.UPCA(8, 85909, 51226, 3)
> > 
> > //current:  
> > switch productBarcode {  
> > case .UPCA(let numberSystem, let manufacturer, let product, let check):  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("UPC-A: \(numberSystem), \(manufacturer), \(product), \(check).")  
> > case .QRCode(let productCode):  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("QR code: \(productCode).")  
> > }  
> > //suggestion:  
> > switch let p = productBarcode {  
> > case .UPCA:  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("UPC-A: \(p.numberSystem), \(p.manufacturer), \(p.product), \(p.check).")  
> > case .QRCode:  
> > &nbsp;&nbsp;&nbsp;&nbsp;print("QR code: \(p.productCode).")  
> > }  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
