Created
September 27, 2015 13:14
-
-
Save crazytonyli/6b9983d41d667b573018 to your computer and use it in GitHub Desktop.
Get generic type
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
struct Stack <Element> { | |
let values: [Element] | |
var elementType: Any { | |
get { | |
return Element.self | |
} | |
} | |
} | |
let intStack = Stack<Int>(values: [1, 2, 3]) | |
print(intStack.elementType) | |
let vcStack = Stack<UIViewController>(values:[UIViewController()]) | |
print(vcStack.elementType) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@eyeplum 想取的不是
values
的泛型类型,而是Stack
的泛型类型。可能这个栗子有点歧义……