> On 13 Apr 2016, at 17:04, Erica Sadun via swift-evolution
> <[email protected]> wrote:
>
> The biggest advantage of the with pattern IMO is Cocoa initializers. It
> provides a more unified
> initialization scope. Instead of:
>
> let questionLabel = UILabel()
> questionLabel.textAlignment = .Center
> questionLabel.font = UIFont(name:"DnealianManuscript", size: 72)
> questionLabel.text = currentQuestion.text
> questionLabel.numberOfLines = 0
Whilst I would not mind the `with` pattern, it’s worth noting that Swift
already has some very fine alternatives:
let questionLabel: UILabel = {
let $ = UILabel()
$.textAlignment = .Center
$.font = UIFont(name:"DnealianManuscript", size: 72)
$.text = "?"
$.numberOfLines = 0
return $
}()
Including some lazy options:
private(set) lazy var questionLabel: UILabel = { ... }()
static let questionLabel: UILabel = { ... }()
milos
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution