Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 通过类函数中的关键字“self”初始化泛型类_Ios_Swift - Fatal编程技术网

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?>()
}