I'm running into this issue on Sonoma as well. The only workaround I found was to import AppKit and Foundation instead of Cocoa or create an iOS playground instead. Also, Xcode's inline hints and error messages seem to be gone.
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Tags: