Cannot cast NSDictionary to Dictionary

Is NSDictionary not compatible with Dictionary in Silver:

import Foundation

let path = "Defaults.plist"
let userDict = NSDictionary(contentsOfFile: path) as? [String: AnyObject]
// E: Cannot cast from "NSDictionary<id!,id!>!" to "Swift.Dictionary<String,AnyObject>?"

On popular request, Swift Dictionary and Array are not structs, as in Apple Swift, not classes, NSDictionary is a class. You should be able to convert from one to the other, but they are no longer a direct mapping. I checked, and there are cast operators that should allow you to cast between them, but I’m guessing the problem why the above cast fails are the mismatched generic types (id/id vs String/AnyObject)

AnyObject/AnyObject does not work either. Shouldn’t that match id/id?

Hm, yeah, that should work (but, reproduced, it doesn’t). logging.

Thanks, logged as bugs://81824

Latest SBL GitHub commit should have cast operators to let NSArray and NSDictionary be cast from/to [T] and [T:U] with mismatched generic types. I’d appreciate if you can let me know if this works for you.

Doesn’t seem to work. Can libToffee mask the SBL? (I’ve removed libSwift from the compiler directory.)

It shouldn’t.

the .a as well? otherwise you might be linking against the old, installed, binary, even if your project references the new .fx (Apple’s linker is a bit daft).

—marc

Yes, both.

Hm ok. can you send me a quick testcase?

import Foundation

let someObject = Date()
let nsdict: NSDictionary = ["anObject": someObject,
                            "helloString": "Hello, World!",
                            "theAnswer": 42]
let dict1 = nsdict as? [String: AnyObject]  // Invalid cast
let dict2 = nsdict as? [AnyObject: AnyObject]  // Invalid cast
print(dict1)
1 Like

thanx, i’ll have a look.

Thanks, logged as bugs://81978

Reproduced, thanx. this looks like it’s a compiler issue…

bugs://81978 got closed with status fixed.

I guess this didn’t make it to Fire 10.0.0.2377, since the above test case still doesn’t work. Will there be a new build this week?

hmm this was supposed to be fixed back when it was closed. if it still doesn’t work, we’ll have to check. there’ll be a new build today, yes, but it won’t have any changes with regard to this issue, sorry :(.

bugs://81978 got reopened.

bugs://81978 got closed with status fixed.

bugs://81824 got closed with status fixed.