Xcode 9 playground error: No such module ‘UIKit’ (or ‘AppKit’)

While creating a new Xcode playground on my MacBook Pro today, I got the most bizarre error message: “No such module ‘UIKit'”. I was using Xcode Version 9.2 (9C40b). Yes, I know there are more recent versions, but I haven’t had the need to upgrade my MacBook Pro. Parenthetically, I do have Xcode 9.4.1 (9F2000) and Xcode 10 beta 6 (10L232m) loaded on my main development machine. I’ll share the solution to this problem with you in the hopes that you, like me, will learn something new about Xcode today.


It started today with the creation of an iOS Single View playground as shown in the next two images (click to enlarge):

I chose a location for the new playground and as soon as the IDE interface booted up, I got this error (click to enlarge):

The console also showed the error:

“No such module ‘UIKit'”?!?!?!! Huh?!?!?! Sometimes things happen with Xcode that are completely inexplicable, baffling, weird — and downright exasperating! The error I experienced today was simple to fix, that is, after beating my head against the wall. Maybe it should’ve been obvious to me, but it wasn’t.

I’m used to playgrounds being a bit flaky (unstable, crashing and disappearing, getting stuck “Running,” etc.), but today’s error was too weird. I specifically didn’t look on the web for an answer because part of my job as an iOS developer and blogger is coming up with and sharing solutions to problems. I poked around for awhile, restarted Xcode, and looked at all settings… except one. For some reason, I didn’t show the Utilities panel. I generally never have the need to look at the Utilities panel because there’s only a few settings there and I generally never have the need to inspect or change those settings, but I finally did — and then I saw the problem here (click to enlarge):

I looked at some folders where I keep my iOS Brain Xcode playgrounds, workspaces, and projects, and guess what I found out? The last action I took with Xcode was to create a playground based on the macOS Single View template. When I create a new playground, Xcode should respect the OS template (“platform”) I’ve selected. But the Platform is always stuck on the last OS it was set to no matter what options you select when creating a new playground. I can consistently repeat this behavior. This is a bug.

The fix to this problem is to show the Utilities panel, go to the Playground Settings section, and change the Platform dropdown to iOS, like so (click to enlarge):

I don’t know why the “No such module ‘UIKit'” error message lingers even after UIKit is recognized and the playground’s code is compiled and run successfully. Oh well, another bug. AND, after using Xcode to reproduce these errors, look what eventually occurred:

Anyway, now you know. If you create a playground targeting iOS and get the “No such module ‘UIKit'” error message, show the Utilities panel and switch the Platform to iOS. If you create a playground targeting macOS and get the “No such module ‘AppKit'” error message, show the Utilities panel and switch the Platform to macOS.

Oh boy…


Author: Andrew Jaffee

Avid and well-published author, software engineer, designer, and developer, now specializing in iOS mobile app development in Objective-C and Swift, but with a strong background in C#, C++, .NET, JavaScript, HTML, CSS, jQuery, SQL Server, MySQL, Oracle, Agile, Test Driven Development, Git, Continuous Integration, Responsive Web Design, blah, blah, blah ... Did I miss any fad-based catch phrases? My brain avatar was kindly provided by http://icons8.com under a Creative Commons Attribution-NoDerivs 3.0 Unported license.

Leave a Reply

Your email address will not be published. Required fields are marked *