Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9036] Passing a dictionary as parameter of initializer of ObjC class in Swift, yields "null" value #51539

swift-ci opened this issue Oct 18, 2018 · 3 comments


Copy link

@swift-ci swift-ci commented Oct 18, 2018

Previous ID SR-9036
Radar rdar://problem/45962521
Original Reporter petar.belokonski (JIRA User)
Type Bug

Attachment: Download


Additional Detail from JIRA
Votes 0
Labels Bug, 4.2Regression
Assignee None
Priority Medium

md5: 05dc781faf00fc6c7a8030c7994f7a76

Issue Description:

Weird situation I've stumbled upon once upgrading to XCode 10.

I have an ObjectiveC class which I initialize in Swift. The initializer accepts NSDictionary as a parameter. If I pass in the dictionary directly into the initializer like so:

let car = Car(parts: [myKey : myValue])

Then, back in ObjC world, when printing the contents of the dictionary it shows the value as "(null)".

Everything works fine if I do:

let parts = [myKey : myValue]
let car = Car(parts: parts)

This issue exists on any version of Swift on XCode 10. The issue doesn't exist on XCode 9.

I am attaching a sample project where this is illustrated.

Copy link

@belkadan belkadan commented Oct 31, 2018

Reproduced. Very strange; what Petar didn't mention was that when the dictionary is bridged back to Swift, the value is there.

@swift-ci create

Copy link

@belkadan belkadan commented Oct 31, 2018

The difference between the two invocations is whether we create a [String?: String] dictionary and convert it to [AnyHashable: Any], or whether we just start with [AnyHashable: Any] from the beginning. But they should indeed have the same observable behavior.

Copy link

@lorentey lorentey commented Nov 12, 2018

This is because Optional doesn't currently have a custom AnyHashable representation, making it incompatible with its wrapped values when converted to AnyHashable.

Adding such a representation is tracked in, following the forum discussion at

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

3 participants