泛型 – Xcode构建错误时,我添加枚举到泛型类?

为什么在将泛型类添加到枚举时会收到错误:
class TestClass<T>{ 
    enum TestEnum {
        case test
    }  
}

错误:

1.  While type-checking 'ExampleTest' at /Users/xxx/xxx/xx/xx/ExampleTest.swift:11:1
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
Command /Applications/Xcode6-Beta3 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254

但是当我这样做时,我没有收到错误:

class TestClass{ 
    enum TestEnum {
        case test
    }  
}

或这个:

class TestClass<T>{ 
}

解决方法

您不能将任何类型嵌套在通用的类型中,反之亦然.
换句话说,你不能像类,结构和枚举这样做的事情:
class Outer<T> {
    class Inner { }
}

class Outer {
    class Inner<T> { }
}

乃至

class Outer<T> {
    class Inner<T> { }
}

苹果人explained的限制原因:

It’s an implementation limitation. We’ll remove the restriction once
our compiler and runtime are able to correctly handle types nested in
generic contexts.

附:对不起,我发布答案这么晚,但问题仍然存在(XCode 6.2).

有一个很相似的question,顺便说一句.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...