📦 SwiftyLaunch Modules
🔗 SharedKit
App-wide Constants

App-Wide Constants

SharedKit (SwiftyLaunch Module) - App-Wide Constants

SwiftyLaunch defines a dedicated Constants object to organize important infromation that is reused throughout the application. Things like Notification Center names, App Version, etc.

Definition

Constants is a struct that contains nested structs for each category of constants. For example, UserDefaults. The values in it are also defined as static properties, in order to be accessed without the need to instantiate the Constants object.

Constants.swift
public struct Constants {
    public struct AppData {
       public static let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
    }
}

Usage

From the What't new View:

import SwiftUI
import SharedKit
 
struct WhatsNewView: View {
	// ...
	var body: some View {
		ScrollView {
            // ...
            VStack(alignment: .leading) {
                Text("Version \(Constants.AppData.appVersion)")
                // ...
                Text("What's new")
                // ...
            }
            // ...
		}
        // ...
	}
}

Different Categories

UserDefaults

The UserDefaults struct contains all the keys used to store data in the UserDefaults.

General

The General struct contains general constants that are used throughout the app.

InAppNotifications

Contains in-app notifications related constants, such as the duration that the in-app notifications are displayed or the max amount that can be shown at once

Notifications

Contains notification names that are used to send notifications to the NotificationCenter. Basically a simple way to send information between different parts of the app.

InAppPurchases

Contains InAppPurchaseKit related constants. Currently only used to store the entitlement identifier of the premium version of the app.

AppData

Contains general app data, like the name, version, developer website, privacy policy URL and more.