[swift-evolution] Object declarations

Andrey Tarantsov andrey at tarantsov.com
Fri Dec 11 19:29:02 CST 2015


I think that anonymous classes got lost amongst all the singletonphobia here, and yet making an anonymous local delegate class is often helpful.

Perhaps we don't need an additional keyword, though; something like this could work too:

view.delegate = class: SomeDelegate {
  ...
}()

or perhaps you want a slightly customized object:

view = class: UITextField {
  func canBecomeFirstResponder() -> Bool { return false }
}()

Of course, we could just use a named local class, like others have pointed out, but unless you really want to name that thing (and the name would often be stupid), that's a just workaround for a lack of anonymous classes.

A.



More information about the swift-evolution mailing list