Swift 5.9 import Cocoa complains about missing AppKit

I noticed that is new in Swift 5.9 from Xcode 15 beta 7. import Cocoa is no longer enough to import AppKit. I think this is for the first time in the history of the Cocoa module.

import Cocoa

open class Foo: NSView { // Cannot use class 'NSView' here; 'AppKit' was not imported by this file

worth noting that the Cocoa module itself is an umbrella for:

import AppKit
import CoreData
import Foundation

since I woke up to 169 warnings on a small project, I dare to ask if this is a feature or a bug?

1 Like

Doesn't look expected to me, and I wasn't able to reproduce it with a sample project containing just the example you provided. Does it reproduce trivially for you in a brand new project? I wonder if there's additional context required.

For me this happens only for classes from Swift Packages (SPM).

e.g. I'm using GitHub - sindresorhus/KeyboardShortcuts: ⌨️ Add user-customizable global keyboard shortcuts (hotkeys) to your macOS app in minutes via SPM, which emits warnings about NSEvent, NSSearchField and NSSearchFieldDelegate.

1 Like