Build errors with C++ interop enabled

I have a large legacy code base mostly in Objective-C that I'm eager to convert piecemeal to Swift, but it has a lot of C++ that it has to talk to. I've been looking forward to C++/Swift interop for a long time, and I'm really excited to see it happening!

When I build my project with the C++ interop enabled in Xcode 15 (15A240d, public release), I get some errors that I don't understand. Should I file issues for any of these? Are there workarounds? Please advise how I can get around them and/or file helpful issues if needed.

/...../..../DerivedSources/BibleReader-Swift.h:1604:1: Static assertion failed due to requirement 'swift::isUsableInGenericContext<UIColor *>': type cannot be used in a Swift generic context

This has a sub-item "In instantiation of template class 'swift::Array<UIColor *>' requested here" that points to a generated header:

SWIFT_INLINE_THUNK swift::Array<UIColor *_Nonnull> SkeletonGradient::getColors() const {
  return swift::_impl::_impl_Array<UIColor *_Nonnull>::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
    _impl::swift_interop_returnDirect_BRFree_void_ptr_0_8(result, _impl::$s6BRFree16SkeletonGradientV6colorsSaySo7UIColorCGvg(_impl::swift_interop_passDirect_BRFree_void_ptr_0_8(_getOpaquePointer())));

It appears to be generated from part of a third-party library I use called SkeletonView. The relevant Swift code is here, I think.

And another error, likely related:

/...../..../DerivedSources/BibleReader-Swift.h:7532:230 No member named 'getOpaquePointer' in 'swift::_impl::_impl_Array<UIColor *>'

This one points to this in a generated header:

SWIFT_INLINE_THUNK SkeletonGradient SkeletonGradient::init(const swift::Array<UIColor *_Nonnull>& colors) {
  return _impl::_impl_SkeletonGradient::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
    _impl::swift_interop_returnDirect_BRFree_void_ptr_0_8(result, _impl::$s6BRFree16SkeletonGradientV6colorsACSaySo7UIColorCG_tcfC(_impl::swift_interop_passDirect_BRFree_void_ptr_0_8(swift::_impl::_impl_Array<UIColor *_Nonnull>::getOpaquePointer(colors))));

And finally, this one:

/...../..../DerivedSources/BibleReader-Swift.h:402:78 Expected a type

Pointing at this generated header, specifically at EditActions:

@interface AnnotationNoteEditorView (SWIFT_EXTENSION(BRFree)) <NSTextStorageDelegate>

- (void)textStorage:(NSTextStorage * _Nonnull)textStorage didProcessEditing:(EditActions)editedMask range:(NSRange)editedRange changeInLength:(NSInteger)delta;


Likely generated from this Swift code of mine, extending a UITextView subclass called AnnotationNoteEditorView:

extension AnnotationNoteEditorView : NSTextStorageDelegate {
    public func textStorage(_ textStorage: NSTextStorage, didProcessEditing editedMask: NSTextStorage.EditActions, range editedRange: NSRange, changeInLength delta: Int) {
//...handling here
1 Like

Possibly related: [🍒][cxx-interop] Correctly import fields with type `NS_OPTIONS`. by zoecarver · Pull Request #66563 · apple/swift · GitHub

Found via "Expected a type" error on Appkit NSEvent.ModifierFlags enum