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"),
    ...
)
2 Likes

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

2 Likes

I've run into the NSNotification issue on a large Xcode project. I tried to reproduce it on a small sample project but could not. Both projects use the same minimum iOS version 16.0 and are running from the same Xcode version.

Does anyone have any details on specific conditions when this issues occurs? Or maybe a small sample app that reproduces the issue? I'm hoping I can work around this issue before Swift 6.0.