简体   繁体   中英

Swift compiler error with generic type array as parameter

I am trying to do something simple: Passing objects of a particular class MyClass into a function like so

func addObjects<T:MyClass>(objects:[T]){
}

But I get a compiler error

<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.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254

If this truly is the compiler's fault, is there some workaround for this issue ?

Is that all of your code? This is working fine for me in Beta 3.

class MyClass{
}
func addObjects<T:MyClass>(objects:[T]){
}
addObjects([MyClass(), MyClass()])
func addObjects<T where T == MyClass>(objects: [T])

虽然当然您不需要泛型:

func addObjects(objects: [MyClass])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM