Is there a way to always import a few libraries on every file? without putting them into a framework
for example, instead of having to do
--MySwiftFile.swift--
import UIKit
import Foundation
import ...
I could do something like:
--SharedImports.swift--
import UIKit
import Foundation
import ...
--MySwiftFile.swift--
import SharedImports.swift
The answer is "No, and that's on purpose". Each file needs to know the context of the code that is contained within that file. It gets that context from the set of imports.
Now in the particular case of UIKit and Foundation, it should be the case that UIKit
imports Foundation
so I don't think you have to explicitly call out both in every file. In the examples above you should be able to get by with just
import UIKit
There are times, when defining your application's model for example, where you may want a file to bring in Foundation
and not UIKit
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With