[Beginner] Unsure if I need Foundation import, and how to auto-import it

I'm working in Xcode for the first time in over a decade (coming from VS Code and Zed), so bear with me on this one.

I've just started up a new project and got things running, and I'm adding the following struct to my project:

struct HttpRequest: Codable {
    let body: String?
    let headers: [String: String]
    let id: UUID
    let method: HttpMethod
    let url: String
}

The UUID type is from Foundation, of course. However, when I hit Ctrl+Space to auto-complete it, it says "Foundation is not imported."

If I hit enter to select that entry, it does not auto-import Foundation, and gives me an error that it "Cannot find type 'UUID' in scope".

I can click that error and it then click "import Foundation" to add the import, but this seems like a lot of effort just to "automatically" add an import that Xcode is already aware I need to add.

On the other hand, I found a number of threads online during my search for answers that suggested I shouldn't even need this import, despite Xcode's insistence.

TL;DR, my questions are: 1) Do I need the Foundation import to use UUID in Swift? and 2) If I do need it, how can I auto-import the Foundation module when I auto-complete the UUID type?

What happens if you ignore the warning ?

What happens if you import Foundation at top of the file ?

import Foundation not needed if for instance you already import UIKit

Which version of Xcode ? If you use Xcode 26 (with Swift 6.1), you should check in your build settings the MemberImportVisibility flag.

See details here: https://www.hackingwithswift.com/articles/276/whats-new-in-swift-6-1, reading Member import visibility

What happens if you ignore the warning ?

It's flagged at the error level so I can't even build the project.


What happens if you import Foundation at top of the file ?

Yup, this works. So having the "auto import" when doing Ctrl+Space on UUID would be ideal.


Which version of Xcode ? If you use Xcode 26 (with Swift 6.1), you should check in your build settings the MemberImportVisibility flag.

I was on Swift 5 but I just updated my build to use Swift 6, and I validated that MemberImportVisibility is set to Yes in the build settings (though I do still get the same build error if I set it to No).


What I'm gathering from this is that the import is definitely required—so my question would then be: Is there an easier way to get these imports to get automatically added when I select a type using Ctrl+Space?

[Beginner] Unsure if I need Foundation import, and how to auto-import it
 
 
Q