master-nevi / UPnAtom

An open source Universal Plug and Play library with a focus on media streaming coordination using the UPnP A/V profile; written in Swift but for both Objective-C and Swift apps.
MIT License
137 stars 55 forks source link

Swift 1.2: Enums with more than one associated value can't hold a generic value. #12

Closed master-nevi closed 8 years ago

master-nevi commented 9 years ago

Because enum Result could contain a generic value or an NSError, the original compiler error was: unimplemented IR generation feature non-fixed multi-payload enum layout.

The original workaround was to use an autoclosure to enclose the generic value in a block that returned the value. As of Swift 1.2, the @autoclosure attribute is now an attribute on a parameter, not an attribute on the parameter’s type, and can only be used in functions, not init or for an enum's associated value.

New workaround is to use a boxing object to wrap the generic value in. Discussions:

master-nevi commented 8 years ago

Fixed as of Swift 2! See: http://stackoverflow.com/a/27258522/1704079

However most cases where this is used will be replaced with Swift 2's new error handling model.