Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to avoid importing the same Framework on every swift file

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
like image 316
Edward Ashak Avatar asked Mar 22 '16 21:03

Edward Ashak


1 Answers

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.

like image 126
Scott Thompson Avatar answered Nov 15 '22 21:11

Scott Thompson