Why do I get an error when I add enum to generic class:
class TestClass<T>{
enum TestEnum {
case test
}
}
Error:
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
But I don't get an error when I do this :
class TestClass{
enum TestEnum {
case test
}
}
or this:
class TestClass<T>{
}
You can't nest any type inside a generic one and vice versa. In other words, you can't do things like these for classes, structs, and enums:
class Outer<T> {
class Inner { }
}
and
class Outer {
class Inner<T> { }
}
and even
class Outer<T> {
class Inner<T> { }
}
Apple folks explained the reason for the restriction:
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.
P.S. Sorry that I post the answer so late but the issue is still there (XCode 6.2).
There was a very similar question, by the way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With