[swift-evolution] Proposal: Bitmask-style syntax for Method Chaining

Jakob Egger jakob at eggerapps.at
Wed Dec 16 05:27:43 CST 2015


> On 15 Dec 2015, at 22:48, Chuquimia, Max via swift-evolution <swift-evolution at swift.org> wrote:
> What I propose is a natural way of assigning properties on layer with a syntax we are all already used to:
> 
> someViewController.view.layer = [
>     .shadowColor = UIColor.grayColor().CGColor,
>     .shadowRadius = 5.0,
>     .shadowOffset = CGSizeMake(0.0, 0.5),
>     .shadowOpacity = 0.75
> ]

You can already do something similar to this using blocks:

({
	$0.shadowColor = UIColor.grayColor().CGColor
	$0.shadowRadius = 5.0
	$0.shadowOffset = CGSizeMake(0.0, 0.5)
	$0.shadowOpacity = 0.75
})(someViewController.view.layer)

or using optional unwrapping:

if let layer = someViewController.view.layer as CGLayer? {
	layer.shadowColor = UIColor.grayColor().CGColor
	layer.shadowRadius = 5.0
	layer.shadowOffset = CGSizeMake(0.0, 0.5)
	layer.shadowOpacity = 0.75
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151216/5a8961b6/attachment.html>


More information about the swift-evolution mailing list