Last active
July 29, 2016 21:18
-
-
Save jtbandes/7624fef93eb23010c032b2d1fd3674be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol P { | |
var dynamicTypeAsMember: P.Type { get } | |
} | |
struct T: P {} | |
extension P { | |
var dynamicTypeAsMember: P.Type { | |
return self.dynamicType | |
} | |
} | |
func type<T>(of value: T) -> T.Type { | |
return value.dynamicType | |
} | |
let t = T() | |
let p: P = T() | |
let typeofT = type(of: t) // == T.self | |
let typeofP = type(of: p) // == P.self??? | |
t.dynamicTypeAsMember // == T.self | |
p.dynamicTypeAsMember // == T.self |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment