Xcode 15b3 Swift 5.9 C++ Interop with Network Extension

Just a quick observation.

I find that the NSNotification.Name NEVPNStatusDidChange is not visible when the Swift Compiler setting: C++ and Objective-C Interoperability is set to C++/Objective-C++.

Simply switching between C/Objective-C and C++/Objective-C++, a successfully building app is no longer able to build with error: Type 'NSNotification.Name?' has no member 'NEVPNStatusDidChange'.

The Swift code being used is: NotificationCenter.default.addObserver(self, selector: #selector(self.updateNetworkStatus(_:)), name: .NEVPNStatusDidChange, object: nil)

Replies

That’s a weird one. Please file a bug about it, and post your bug number, just for the record.


It seems that NEVPNStatusDidChangeNotification is being imported as a String rather than an element of NSNotification.Name. What’s interesting is that:

  • The declaration in the header is this:

    NEVPN_EXPORT NSString * const NEVPNStatusDidChangeNotification …;
    

    where NEVPN_EXPORT expands to extern. Most of our notifications are declared like this:

    FOUNDATION_EXPORT NSNotificationName const NSSystemTimeZoneDidChangeNotification …;
    

    where the NSNotificationName is how Swift knows that this is member of the NSNotification.Name extensible enum.

  • NEVPNStatusDidChangeNotification has no entry in the .apinotes file.

Given that, it’s not clear how NEVPNStatusDidChangeNotification getting mapped to a notification name in the normal case O-:

Regardless, a bug report is in order.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Add a Comment
GAMECONTROLLER_EXTERN NSString *const GCKeyboardDidConnectNotification API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0));
GAMECONTROLLER_EXTERN NSString *const GCKeyboardDidDisconnectNotification API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0));

These have the same issue so should probably do an audit (this is from the RC of Xcode 15).

this is from the RC of Xcode 15

Indeed.

One of the nice things about Swift bugs is that you can check on their status in the Swift open source. In this case:

Sadly, the fix seems to have missed the Xcode 15.0 train.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"