【发布时间】:2014-06-05 20:54:59
【问题描述】:
是否可以在structs 或classes 中使用typealias?例如:
struct Foo {
typealias type = Int
}
这编译没有错误。但是,当我使用这个结构时:
let f = new Foo
let bar: f.type
这给了我一个:
使用未声明的类型'f'
你如何检索这个存储的类型?
这对泛型结构很有用,例如:
struct TypeHolder<T> {
typealias type = T
}
let type1 = new TypeHolder<Int>
let fooint: type1.type
【问题讨论】: