When developing an iOS application you might get into a situation when you need to change the UIApplication
base class. It is often a requirement when using various MDM SDKs, like the Mobile Iron AppConnect SDK. There are two ways to do that in a Swift application, both with some advantages and disadvantages.
Declarative method with Info.plist
The first method to change the UIApplication base class is using Info.plist
. It is quite simple, you just need to add a new key NSPrincipalClass
with a string value representing the name of the desired class, like AppConnectUIApplication
when using the Mobile Iron AppConnect SDK.
<key>NSPrincipalClass</key>
<string>AppConnectUIApplication</string>
No actual code changes are required.
Code method with main.swift
The second method is a bit more complicated but more flexible at the same time. First you need to remove @UIApplicationMain
from your AppDelegate
class definition. Then you add a main.swift
to the root of your project that looks like this
import AppConnect
import UIKit
UIApplicationMain(
CommandLine.argc,
CommandLine.unsafeArgv,
ACUIApplicationClassName,
NSStringFromClass(AppDelegate.self)
)
The third parameter in the UIApplicationMain
call is the name of the desired class, ACUIApplicationClassName
in this example.