Last active
April 17, 2016 18:28
-
-
Save stevecass/0f4b79c088f128cbe7a1ec939d5739e2 to your computer and use it in GitHub Desktop.
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
import UIKit | |
let nonOptionalVar: [String] = ["a", "b", "c"] | |
let optionalVar:String? = "jimmy" | |
// this compiles OK with import UIKit present | |
let ex1: [String: AnyObject] = ["key" : nonOptionalVar, "notherkey": ["content": optionalVar!]] | |
// Here we forget the ! character that unwraps the optional | |
// error: contextual type 'AnyObject' cannot be used with dictionary literal | |
let ex2: [String: AnyObject] = ["key" : nonOptionalVar, "notherkey": ["content": optionalVar]] | |
/* | |
If we omit import UIKit both both cases error with a different message | |
error: value of type '[String]' does not conform to expected dictionary value type 'AnyObject' | |
[Sratches head] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment