NEW: Learn to build amazing SwiftUI apps for macOS with my new book! >>

SOLVED: Question: Import Foundation or Import SwiftUI

Forums > 100 Days of SwiftUI

Hello,

I tried to create separate files in one project.

As my last question answered, I figure there's no big differences between clicking on Swift or Swift UI when creating the file.

However I found if I click on Swift, the editor import Foundation, if I choose SwiftUI, the editor shows import SwiftUI

When Do I need Foundatio and and when Do I need SwiftUI to be imported ?

Thank you in advance,

Boat

1      

You need import SwiftUI if you are writing SwiftUi Views or using other APIs from SwiftUI.

You need import Foundation if you are using things like Date or AttributedString or other APIs that aren't a part of the Swift Standard Library or a specialized framework (see below).

Note that import SwiftUI also includes Foundation for you, so you don't need both.

Further, you may need to import other frameworks when you do other things. Like MapKit when working with maps or WebKit when doing web stuff or AVFoundation when doing audiovisual stuff or UIKit for pre-SwiftUI style of GUIs, etc.

2      

Thank you again @roosterboy

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Spend less time managing in-app purchase infrastructure so you can focus on building your app. RevenueCat gives everything you need to easily implement, manage, and analyze in-app purchases and subscriptions without managing servers or writing backend code.

Get Started

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.