Launch screen comes up--this is controlled by the platform. Appears even before the first line of the entry point of the application. "Launch screens in XCode" covers options as of June 2021:
Apparently 4/5/6 are still somewhat "under development" according to that blog.
Launch screen images are also apparently cached by iOS. Undocumented hack (not tested on iOS 14+) that might work to delete the cache:
```
public extension UIApplication {
func clearLaunchScreenCache() {
do {
try FileManager.default.removeItem(atPath: NSHomeDirectory()+"/Library/SplashBoard")
} catch {
print("Failed to delete launch screen cache: \(error)")
}
}
}
```
Entry point
CFBundleExecutable
); by default this comes from the EXECUTABLE_NAME
environment variablemain
, written by the developer int main(int argc, char* argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
@main
as the class to pass in as the fourth argument.
main.swift
(name is important, it gets special dispensation from the compiler to have top-level statements/expressions), and do the same as above: import UIKit
UIApplicationMain(
CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(AppDelegate.self)
)
@main
a type and give it a static main()
function: @main
struct Program {
static func main() -> Void {
UIApplicationMain(
CommandLine.argc, CommandLine.unsafeArgv, nil,
NSStringFromClass(AppDelegate.self)
)
}
}
UIApplicationMain
(assuming the app supports scenes (Info.plist contains an "Application Scene Manifest" dictionary and the code has classes and protocols whose names begin with UIScene
) and the app has a main storyboard):
UIApplication.shared
application(_:didFinishLaunchingWithOptions:).
Info.plist
)UIStoryboard(name:bundle:).instantiateInitialViewController()
)window
property; assigns the initial view controller to the window instance's rootViewController
property. This view controller is now the app's root view controller.scene(_:willConnectTo:options:)
makeKeyAndVisible
to make the window visible. This causes the window to turn to the root view controller and tell it to obtain its main view (from a nib or nib inside a storyboard, typically) and then call its viewDidLoad
method.Enter the event loop
Create new Xcode project ("TrulyEmpty").
Application Scene Manifest
-> Scene Configuration
-> Application Session Role
-> Item 0 (Default Configuration)
) and delete it; delete the entire thing (the key/value pair), not just the value stored thereSceneDelegate.swift
: edit scene(_:willConnectTo:options:)
to look like: func scene(_ scene: UIScene,
willConnectTo session: UISceneSession
options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.backgroundColor = .white
window.rootViewController = ViewController()
self.window = window
window.makeKeyAndVisible()
}
}
TODO: Create an app where there's a main storyboard but sometimes is ignored at launch time (step 4 above), such as displaying a login screen.
TODO: How does the splash screen storyboard play into this?
Last modified 27 November 2024