Could not build Objective-C module 'Cocoa'

When I open a new blank playground in Xcode the very first line "import cocoa" gets the alert "Could not build Objective-C module 'Cocoa'". Can someone please tell me what I have done wrong and how I can fix it.

Xcode 15.0.1

Ventura 13.6.1

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.

As I search around the internet this seems to be a common problem for the last 10 or 12 years. Someone must have a simple answer without hacks or work arounds. I ended up editing the “ FILEBASENAME.playground ” template files to import SwifyUI instead of Cocoa. That works but seems redundant for some reason.

I’m not sure what’s going on with your setup, but this is working for me:

  1. Using Xcode 15.0 on macOS 13.6.1, I created a new playground from the macOS > Blank template.

  2. It comes prepopulated with this code:

    import Cocoa
    
    var greeting = "Hello, playground"
    
  3. I pressed the Play button.

  4. The playground ran as expected.

Share and Enjoy

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

Updating to Sonoma 14.1 fixes this issue somehow.

I also have this issue. If I create a blank template for MacOS as suggested above and press play, it works.

However, if I add an extra line, something along the lines of:

var temp = greeting.trimmingCharacters(in: .whitespacesAndNewlines)

I'll get the "Could not build Objective-C module 'Cocoa'.

Now, the weirdest part is, sometimes that error prevents the playground from running (as it should), but other times it'll retain that error, but still allow the playground to run.

I haven't been able to make it happen reliably either way, but there's something definitely messed up. This is under Xcode 15.0.1 and Ventura 13.6.1

Now, the weirdest part is, sometimes that error prevents the playground from running (as it should)

Well, you shouldn’t be getting the error in the first place |-:

but other times it'll retain that error, but still allow the playground to run.

Sometimes the editor holds on to an issue even though you’re fixed the original problem. To get around that, choose Product > Clear All Issues.

Share and Enjoy

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

No good answers yet. I'm sure that somewhere along the line I have done something wrong but what that might be has me at a loss. I am still using a work around by having edited the template so that a new macos playground file imports SwiftUI and Cocoa upon opening ( only saves a couple of seconds ) but it still doesn't seem right to me even though it all builds correctly. A new project for macos imports only SwiftUI and so far seems to work ok

No, you didn't do anything wrong. Recently this problem appeared in all of my playgrounds. No Quinn, Product > Clear all issues doesn't fix it. XCode is broken.

MacOS 14.0 XCode 15.0.1

[Oi vey, I should write this up generically some day.]

Recently this problem appeared in all of my playgrounds.

If you create a new user account on your Mac, does it have the same problem?

Share and Enjoy

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

This started happening to all of my playgrounds. No, you didn't do anything wrong. Clearing errors won't fix it. XCode is broken. Also this is the second time I have posted this - it was deleted by administrators. Why?

Could not build Objective-C module 'Cocoa'
 
 
Q