A couple of small issues after enabling C++ interop in my iOS project

After enabling C++ interop in my iOS (+MacCatalyst project) I bumped into 2 issues:

  1. All occurrences of abs(x) where x is a Double started returning this error:

Ambiguous use of 'abs

So I had to replace it with Swift.abs(x). Would this be considered a bug with C++ interop? Is there any cleaner alternatives to this?

2, The following code:

import GameController
...
NotificationCenter.default.addObserver(forName: Notification.Name.GCKeyboardDidConnect, object: nil, queue: .main) { _ in }
NotificationCenter.default.addObserver(forName: Notification.Name.GCKeyboardDidDisconnect, object: nil, queue: .main)  { _ in }

causes these errors:

Type 'Notification.Name' has no member 'GCKeyboardDidConnect'
Type 'Notification.Name' has no member 'GCKeyboardDidDisconnect'

Is there a good workaround for this?

I'm using Xcode 15.1 beta 3.

Looks like someone else had a similar issue.

Edit: Interestingly rewriting code like this compiles but the closures are never triggered:

NotificationCenter.default.addObserver(
    forName: Notification.Name(rawValue: "GCKeyboardDidConnectNotification"),
    ...
)
1 Like

I posted an issue to the Swift repo. Please see below. I would open another issue based on the comments regarding Notification.Name with c++ interop. I've seen new issues as well.

https://github.com/apple/swift/issues/69914

1 Like