📦 SwiftyLaunch Modules
🌱 App
Overview

App Module Overview

SwiftyLaunch Module - App

The App module is the starting point of your application. It initializes the app, sets up the app structure, and combines code from differnet modules to create a cohesive app experience. Apps generated with SwiftyLaunch will have include following features in the App out of the box:

  • App Initialization: Setup and integration of the App, and other Modules in App.swift
  • Launch Screen: A customizable, pre-designed launch screen storyboard. Read more.
  • Developer View: A set of small examples, demos and toggles to test features during development. Read more.
  • App Settings Screen: A pre-designed, native-looking settings screen to manage app settings. Read more.
  • Privacy Manifest: SwiftyLaunch automatically generates a privacy manifest file for your app. Read more.
  • Onboarding Screen: A pre-designed onboarding screen to introduce users to your app. Read more.
  • What's New Screen: A pre-designed screen showing what has been added after an app update. Read more.

App Initialization in App.swift

In App.swift we set up everything for the app to run.

MainApp struct

In the MainApp struct, we initialize the AuthKit and FirebaseKit objects and attach them as environment objects to the ContentView. We also attach the app-wide view modifiers, like the ShowRequestSheetWhenNeededModifier, which will show a capability request sheet when the app needs to access the user's location, camera, or photo library. In the MainApp struct we also define the app delegate, that additionally handles the app lifecycle.

App.swift
@main
struct MainApp: App {
 
	@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
	@StateObject var db = DB()
	@StateObject var iap = InAppPurchases()
    // ...
 
	var body: some Scene {
		WindowGroup {
			ZStack {
				ContentView()
                // ...
					.modifier(ShowRequestSheetWhenNeededModifier())
                    // ...
					.modifier(ShowPaywallSheetWhenCalledModifier(iap))
                    // ...
					.environmentObject(db)
					.environmentObject(iap)
			}
		}
	}
}

AppDelegate class

Here, we initialize all of our providers (example, AnalyticsKit is initialized with Analytics.initPostHog()), connect all the providers to use a common user ID (from Firebase), as change the UIScene to include an additional app-wide overlay view (opens in a new tab) that we use to display in-app notifications.

Additionally, if NotifKit is selected during project generation, this will also make the AppDelegate conform to OneSignals observers to detect when user interacts with push notification.

App.swift
class AppDelegate: NSObject, UIApplicationDelegate, OSNotificationLifecycleListener, /* ... */ {
 
	func application(
		_ application: UIApplication,
		didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
	) -> Bool {
 
		// ...
		Analytics.initPostHog()
        // ...
		DB.initFirebase()
        // ...
 
		// ... detect if there was a crash during last app run
 
        // ... add onesignal observers
 
		// ... connect all providers to use the same user ID
 
		return true
	}
 
    // ... Set SceneDelegate as the delegate for the main window to show in-app notifications
	func application(/* ... */) -> UISceneConfiguration { }
 
    // ... OneSignal observers
	func onPushSubscriptionDidChange(state: OSPushSubscriptionChangedState) { }
	func onClick(event: OSNotificationClickEvent) { }
	func onWillDisplay(event: OSNotificationWillDisplayEvent) { }
 
}
// ... scene delegate definitions

Privacy Manifest File

Since 2024, Apple requires all apps to include a privacy manifest file (opens in a new tab).

The most common use case entry in the privacy manifest file would be the access of UserDefaults. In addition to that, all third-parties SDK must include their own privacy manifest entries.

SwiftyLaunch takes care of that for you, by automatically creating a PrivacyInfo.xcprivacy file in the App/Resources/ folder and by making sure that all SDKs that require a privacy manifest entry, include it.

Developer View

The developer view is only shown on development builds of the app, and comes with a bunch of handy buttons and toggles to test out various features of the app. It is here to streamline the development process and make it easier to test features.

You can remove or add buttons to the developer view by modifying the DeveloperSettingsView.swift file.

Module File Contents

Let's go through every file that is contained in the App module:

Resources

Contains the main app assets, the launch screen storyboard, and the privacy manifest file.

Sources

App.swift

The main entry point of the app. Here we initialize all the providers, attach them to the environment, and set up the app structure. See App Initialization in App.swift for more information.

View / ContentView.swift

Main View of the App, includes the root Tab View to switch between different views.

Settings / SettingsView /

Contains the root settings view and other settings-related views that are shown when the user taps on the settings button in the tab bar. Read more about the App Settings Screen.

Developer / DeveloperSettingsView.swift

The developer view that is only shown on development builds of the app. Contains a set of buttons and toggles to test features during development. Read more about the Developer View.

OneTimeViews / OnboardingView.swift

The onboarding view that is shown to the user when they first open the app. Read more about the Onboarding Screen.

OneTimeViews / WhatsNewView.swift

The "What's New" view that is shown to the user after he updates the app and includes new features, bug fixes and more. Read more about the What's New Screen.