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

SOLVED: Question: Import Foundation or Import SwiftUI

Forums > 100 Days of SwiftUI

@boat  

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

2      

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.

4      

@boat  

Thank you again @roosterboy

2      

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!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.