SE-0383: Deprecate `@UIApplicationMain` and `@NSApplicationMain`

I'm certainly not aware of any such cases. I can expound upon the logic for the migration path, then perhaps you can catch any inconsistencies there:

Consider a Swift module that has adopted @UIApplicationMain or @NSApplicationMain. This must be done outside of a main.swift file, so we only have to consider library-style code. Further, the type declaration these attributes are attached to must:

  • Be a class
  • Be unique wrt further declarations annotated with any of the entrypoint attributes, including @main.
  • Conform to the corresponding application delegate protocol (which also requires it be a subclass of NSObject)

What does this all get us? It means existing code has to look something like this:

@UIApplicationMain
class MyDelegate: NSObject, UIApplicationDelegate { }

What can you change here? The base class could certainly be different (I often refine NSResponder instead myself), you can mark the class @objc, or final, or give it access control modifiers, or make it an actor instead.

All of these do not affect inheritance of the entrypoint. Notably, you cannot

  • Remove the application delegate protocol conformance
  • Change the class to a value type instead

Are there backwards deployment problems? Also no since the main entrypoint is emitted into client code - just like the synthetic entrypoints created for the framework-specific attributes.

Again, perhaps I'm missing something, but I would expect a counterexample here to be pretty gnarly. For example, one could go out of their way to declare a static func main() {} in their app delegate that, upon migration, would get automatically called instead of the main provided by an application delegate conformance:

@main // was @UIApplicationMain
actor AppDelegate: NSObject, NSApplicationDelegate {
  static func main() {
    fatalError("oops")
  }
}

They'd need to change the name of this function in addition to adopting the @main attribute to avoid the code exploding. This example would crash on launch, and a less contrived example wouldn't call UIApplicationMain or NSApplicationMain to set anything up, so I think the authors of such an implementation would catch it pretty quickly.

3 Likes