[swift-evolution] Properties with parameters

Tim Vermeulen tvermeulen at me.com
Sat Apr 23 08:42:21 CDT 2016

Properties are great. They allow us to write the more naturally looking

myButton.hidden = true

instead of


However, they don't take any parameters. That’s why we still have to write

myButton.setImage(myImage, forState: .Normal)

instead of

myButton.imageForState(.Normal) = myImage

The syntax to write such a function would be pretty straight-forward:

var imageForState(state: UIControlState): UIImage? {
    get { … }
    set { … }

Functions such as setHidden(_:forState:) are basically setters of properties, disguised as functions. This proposal would take away this ambiguity.

More information about the swift-evolution mailing list