Search code examples
iosswiftswiftuiuikit

No such module 'UIKit' for SwiftUI project


It's been about 10 years since I last worked with iOS. I was experimenting with using an API to check if the user has CarPlay open, but the solution I found depends on UIKit, specifically UIScreen.

Is it possible to add UIKit to my project, or could I do this with SwiftUI?

UIScreen.main.traitCollection.userInterfaceIdiom == .carPlay

enter image description here


Solution

  • Are you sure you created an iOS project? The thing is, you shouldn't have any problems importing UIKit and SwiftUI if it's iOS. This could happen if, for instance, you created a macOS project, as macOS doesn't support UIKit.