Currently, all my imports are scattered throughout my project. I want to place all imports in a single file so that it's easy to see what all libraries are used by the app. Then, I can import this file everywhere.
While this is easy to achieve in C++ with its header files, I'm not sure how to do this in swift... as there are no headers in swift and its not possible to import a file in swift. As explained in this article, it is possible to import a module, functions, classes, enum, variables, type aliases etc... but not file.
I was visualizing a file called SystemImports.swift with the following code:
import Foundation
import UIKit
import SwiftUI
import NotificationCenter
import UserNotifications
import WidgetKit
...
Then I can import this file every other file. Is something like this possible in swift?
My attempt:
I have a static library containing a SwiftUI View which imports SwiftUI.
import Foundation
import SwiftUI
public struct MessageView: View {
....
}
The App protocol is in the App target with the following code:
import <Static Library>
//import SwiftUI
@main
struct HelloIOSApp: App {
...
}
I have imported a Static Library which imports SwiftUI. When I import that Static Library in my App target (as shown above), it doesn't work. I get compilation errors which can be solved by uncommenting the SwiftUI import in the above code. But according to this stackoverflow answer, it should've worked.
While the above approach is not working, what I really wanted was to have a file of only imports and then import that file everywhere. Is this possible in swift?