[swift-evolution] Modernize Switch/Case Statements?
Erica Sadun
erica at ericasadun.com
Sun Jan 31 11:27:51 CST 2016
> On Jan 31, 2016, at 1:34 AM, Thorsten Seitz via swift-evolution <swift-evolution at swift.org> wrote:
>
>
>
>> Am 30.01.2016 um 10:39 schrieb Haravikk via swift-evolution <swift-evolution at swift.org>:
>>
>> Actually, one thing we don’t have in Swift is the ability to just put blocks (curly braces) wherever we like, which in some languages is a useful tool for variable scope when you know you only need something for a short time, but might want to re-use the name.
>
> You can use a "do" block for that.
>
> do { ... }
>
> -Thorsten
do blocks don't let you introduce parameters for short-lived items:
// this is how I have to do things now
let _ : UILabel = {
view.addSubview($0)
CenterViewInSuperview($0,
horizontal: true, vertical: false)
$0.text = "Toggle me"
$0.font = UIFont.boldSystemFontOfSize(36)
ConstrainViews("V:[view1]-30-[view2]",
views: $0, mySwitch)
return $0
}(UILabel())
// vs (this does not exist in the language)
do {
view.addSubview($0)
CenterViewInSuperview($0,
horizontal: true, vertical: false)
$0.text = "Toggle me"
$0.font = UIFont.boldSystemFontOfSize(36)
ConstrainViews("V:[view1]-30-[view2]",
views: $0, mySwitch)
}(UILabel())
-- E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160131/10d16293/attachment.html>
More information about the swift-evolution
mailing list