Initialize with positional constants
suggest changeThis is Swift 2 ("action" and .TouchUpInside). It has to run in a method where self and view already exist. It does not work as a stored-property initializer. The "action" method must exist.
let mySwitch: UISwitch = {
view.addSubview($0)
$0.addTarget(self, action: "action", forControlEvents: .TouchUpInside)
return $0
}(UISwitch())
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents