Created
December 10, 2014 05:03
-
-
Save kasrak/2bca5b265b16c477c14a to your computer and use it in GitHub Desktop.
Swift: heterogenous generic items in an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Box<T> { | |
let value: T | |
} | |
// This works: | |
let boxes1 = [Box(value: 42), Box(value: "hi")] | |
// This works: | |
let boxes2 = [Box(value: 42), Box(value: "hi")] as [Box<Any>] | |
// This doesn't work: "'Int' is not identical to 'String'" | |
let boxes3 = [Box<Int>(value: 42), Box<String>(value: "hi")] | |
// This doesn't work: "'String' is not identical to 'Any'" | |
let boxes4 = [Box<Int>(value: 42), Box<String>(value: "hi")] as [Box<Any>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment