I’ve been wanting tuple-initializable in Swift for Core Graphics, where it’s a drag to always use long and cumbersome initializers when I’m not building production code:
let point: CGPoint = (100, 50)
Yeah, it is better form to use labeled initializers but I’m anyone using
CGPoint understands the correspondence between (x, y) coordinates. And I don’t want to just build
CGPoint.init(_ x:, _ y:) extensions. I like the tuple form.
Right now, the closest you can get is the silly:
let point = (CGPoint.init as (CGFloat, CGFloat) -> CGPoint)(100, 50)
And that’s (pardon the pun) pointless.
It would be pretty cool to allow memberwise tuples with or without labels in place of initializers when the tuple field types could be unambiguously determined:
let point: CGPoint = (x: 100, y: 50) // instead of: let point = CGPoint(x: 100, y: 50) let person: Person = ("Mary", nil, "Santos") // instead of: let person = Person(first: "Mary", middle: nil, last: "Santos")
It may be ugly but it would be hella useful in Playgrounds.