Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode build error when I add enum to generic class?

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>{ 
}
like image 666
Jimmy Avatar asked Jul 22 '14 22:07

Jimmy


1 Answers

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.

like image 96
Pavel Vergeev Avatar answered Oct 12 '22 07:10

Pavel Vergeev