Have we always been able to pass a Swift struct to Obj-C?

I just discovered today that I seem to be able to pass a Swift struct in a userInfo dictionary in a NotificationCenter notification. Has that always been possible, or was that added to the language later?

Because I've been going to great lengths to either avoid doing that, or to marshal the object into primitive bridged types. I'm delighted (and a bit frightened and chagrined) to learn I don't need to do that.

1 Like

Since Swift 3, I think. Swift structs get boxed up in an opaque id-compatible type that you can unbox with downcasts. They even pass through Hashable conformance. See Objective-C id as Swift Any - Swift Blog - Apple Developer (skip down to "Swift Value Types in Objective-C").

1 Like

Man. It's so easy to miss new features when they're added. I've been operating under the assumption I couldn't do that for soooo lonng.

1 Like
Terms of Service

Privacy Policy

Cookie Policy