Skip to content

Instantly share code, notes, and snippets.

@jepers
Last active October 9, 2015 01:38
Show Gist options
  • Save jepers/b3ba6469fc2e935d4376 to your computer and use it in GitHub Desktop.
Save jepers/b3ba6469fc2e935d4376 to your computer and use it in GitHub Desktop.
Four types that (to me) should be "the same" (although they are different types of course) needs to be initialized differently, why?
struct SA<T> {
let v: T
init(_ v: T) { self.v = v }
}
typealias SB = SA<(Int, Int)>
typealias SC = SA<W>
typealias W = (Int, Int)
struct SD {
let v: (Int, Int)
init(_ v: (Int, Int)) { self.v = v }
}
let a = SA(1, 2) // Works with ZERO OR MORE parens around 1, 2 (not counting arg list parens).
let b = SB(1, 2) // Works ONLY WITH ZERO parens.
let c = SC((1, 2)) // Works with with ONE OR MORE parens.
let d = SD((1, 2)) // Works with with ONE OR MORE parens.
// To me, the types of a, b, c and d are as similar as different types can be.
// Yet they are very different in the way they can be initialized, why?
// How come SB and SC must be initialized differently for example?
//
// (Xcode 7.1 beta 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment