Ios 通过类函数中的关键字“self”初始化泛型类
我有一门课看起来像这样:Ios 通过类函数中的关键字“self”初始化泛型类,ios,swift,Ios,Swift,我有一门课看起来像这样: class MyContainer<T> { required init() {} class func giveMeAContainer() -> MyContainer<Any?> { let container: MyContainer<Any?> = self() return container } } 但是很明显,这对编译器来说是不合法的。你想做什么 你想
class MyContainer<T> {
required init() {}
class func giveMeAContainer() -> MyContainer<Any?> {
let container: MyContainer<Any?> = self()
return container
}
}
但是很明显,这对编译器来说是不合法的。你想做什么 你想回归自我吗 你想退回我的集装箱吗
谢谢回复。我在更新中写下了我想要的东西。
class func giveMeAContainer() -> Self<Any?> {
return self<Any?>()
}
class func giveMeAContainer() -> MyContainer<T> {
let container: MyContainer<T> = self()
return container
// or
// return self()
}
class func giveMeAContainer() -> MyContainer<Any?> {
let container: MyContainer<Any?> = MyContainer<Any?>()
return container
// or
// return MyContainer<Any?>()
}