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
另外一种方法可以不通过
Element
找类型: