Skip to content

Instantly share code, notes, and snippets.

@jbrennan
Created July 16, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbrennan/5dbbc52c9670c2846c2c to your computer and use it in GitHub Desktop.
Save jbrennan/5dbbc52c9670c2846c2c to your computer and use it in GitHub Desktop.
Bug related to having an optional enum in a struct in Swift
import Foundation
public struct FeaturedItem {
public enum ImageSource {
case Bundled(name: String) // simplified enum with one case to illustrate the bug.
}
public let localizedTitleImageSource: ImageSource? // This optional causes Swift to barf. If it's non-optional, it compiles fine
// Workaround in this case is to just use an optional String instead of the enum.
}
extension FeaturedItem {
public static let bundledItems = [ // this needs to have at least one object in the array
FeaturedItem(
localizedTitleImageSource: .Bundled(name: "some name")
)
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment