UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Xcode 15: Could not build Objective-C module 'Cocoa;

Forums > iOS

Hey y'all - not sure if this is the right place to post, but I opened xcode today to see an error mesage: "Could not build Objective-C module 'Cocoa'"

I'm a newbie (day 2 of 100 days) so am really not sure how to fix this -- lmk if you have any ideas! TIA

4      

Deactivate the "Enables modules (C and objective C) in build settings.

3      

This is happening to me too, but in a Playground. I don't see a Build Settings for a Playground - is there one? If so, where is it?

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Removing the import statement seems to have worked for me.

3      

Ah yes @buxley - this is happening to me in when I use xcode's playground! In the inspector (click the icon to the right of the '+' button in the top right corner to open the inspector), under playground settings, I changed the platform to 'iOS'; then I changed the import statement to "import UIKit" (or import SwiftUI), and now I don't have any errors.

But if I change the playground settings back to 'macOS', the issue with 'import Cocoa' still persists. Tried importing other libraries too, but same error each time. Not sure how to fix it, but I'm trying to learn to build an iOS app (rather than a mac app; and in any case, I'm just practicing with playgrounds and haven't actually started a project), so maybe I can just ignore the issue for now lol

3      

got same error. Could not build Objective-C module 'Cocoa' anyone know how to fix this? TIA

3      

+1 to this. I have a MacBook on Ventura still and it does not have the issue, but my MacBook on Sonoma does. @lil-pizza 's workaround got rid of the error for me.

3      

If you can import Foundation and AppKit without an error, that combination is equivalent to import Cocoa.

4      

This is frustrating, not having a real solution. :-(

Wonder if Paul has looked into this? I sent him an email as I'm sure he wouldn't want all us newbie's confused right out of the box.

3      

I've been having the same problem ever since I had upgraded Xcode to version 15.0.1 (I didn't have this problem with Xcode 15.0) and tried every solution/workaround I could find on the Internet (including clean re-installation of Xcode) but to no avail. After seeing the reports from others for the same problem here (led by a DuckDuckGo search), I was convinced that this was a bug with either Xcode 15.0.1 or macOS 14.0 or both (a compatibility issue?). So I gave up on trying and waited for Apple to release a fix in some way.

Today, after learning that Apple released macOS Sonoma 14.1, I gave it another try by upgrading macOS from 14.0 to 14.1, deleting my original Playground as well as all the content of the ~/Library/Developer/Xcode/DerivedData directory. After all that preparation, I started Xcode and created a new, empty Playground for macOS and voila, problem solved! No more "Could not build Objective-C module 'Cocoa'" error in the Playground!

I hope this helps and happy hacking!

7      

14.1 fixed it for me as well. I didn't even have to make a new playground. Cocoa imported right out of the gate.

4      

14.1 Fixed it for me as well.

Thanks @finalfantasia

3      

It seems doing something with important statement.

2      

I have 14.3 and it is still doing it to me I'm just frustrated... anyone have any idea how I should fix this?

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.