I have a custom class, located in a Swift Package, I am using as the super class to my AppDelegate
When I run the following code, testVar
will be empty when printed to the console.
import UIKit
import CustomSwiftPackage
@main
class AppDelegate: CustomSwiftPackageDelegate {
let testVar = "test"
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print(testVar)
return true
}
}
Note: If I change let testVar = "test"
to lazy var testVar = "test"
, it works as the variable is initialized at runtime.
When I run the follow code now, the testVar
will be printed to the console with "test"
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
let testVar = "test"
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print(testVar)
return true
}
}
If I try to make a new class that that does the same exact thing as CustomSwiftPackageDelegate
and place it in the same package as my AppDelegate
, the testVar
will print "test"
to the console.
What is going on here? Does Apple allocate memory slightly different for Swift Packages?