Created
December 30, 2014 21:33
-
-
Save neonichu/fe11ef46b7d5acd75bd7 to your computer and use it in GitHub Desktop.
Today's Swift WTF - Arrays
This file contains 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
#!/usr/bin/env xcrun swift | |
func info<T>(x: T) { | |
println("\(x) is a \(_stdlib_getDemangledTypeName(x))") | |
} | |
let array = [0, 1, 2] // appending 'as AnyObject' here yields a compiler error | |
info(array) | |
import Foundation | |
let objc_array: AnyObject = [0, 1, 2] as AnyObject | |
info(objc_array) | |
// comparing different array types => compiler error as well | |
//let equal = objc_array == array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
or in other words, ObjC compatibility of arrays is achieved by having two implementations, chosen by the context they are used in and by the presence of a
Foundation
import.