1

According to this answer on the question Value of type 'String' does not conform to expected dictionary value type 'AnyObject', importing Foundation should implicitly bridge a Swift String struct to NSString, so it can be used in [String : AnyObject] dictionaries. But I'm not seeing that behavior in Xcode 8/Swift 3:

import Foundation
let dict: [String : AnyObject] = ["hello" : "world"] // Value of type 'String' does not conform to expected dictionary value type 'AnyObject'

Are Swift Strings no longer implicitly bridged to NSString? Are my only options to cast my String value as AnyObject or NSString, or use a [String : Any] dictionary type instead?

Community
  • 1
  • 1
JAL
  • 41,701
  • 23
  • 172
  • 300
  • 4
    The *implicit* bridging between Swift and Foundation types was removed in Swift 3: https://github.com/apple/swift-evolution/blob/master/proposals/0072-eliminate-implicit-bridging-conversions.md. – Martin R Oct 07 '16 at 18:59
  • 1
    @MartinR ah ok. So my only options are to cast or use `Any`? Meh, these changes will take some getting used to... – JAL Oct 07 '16 at 18:59

0 Answers0