Search code examples
swiftmacosmacos-mojave

Swift 2.2 app no longer works on macOS 10.14 Mojave


I make a plug-in to ą third-party app. Part of the plug-in is written in Swift. The plug-in is stuck at Xcode 7.3.1/Swift 2.2 because of this issue.

The plug-in no longer works on Mojave.

We have the following observations:

  • The issue is limited to Mojave, everything works as expected on older macOS versions.
  • If the third-party app asks to "load this bundle" of the plug-in, it just gets nil.
  • The plug-in's init method is not called at all.
  • If I completely remove Swift 2.2 from the plug-in's code base (making in unusable), its bundle is correctly loaded.

Any ideas what might be causing this issue and how to fix it?

PS: Pursuing users to install a newer version of Python/PyObjC is not feasible nor expecting Apple to bundle a newer version of Python/PyObjC with macOS (so the plug-in code base cannot be upgraded to a newer Swift version). Migrate the code from Swift to Objective-C is planned but it will not happen instantly (it's a matter of a few months).


Solution

  • I have managed to get the plug-in running on Mojave.

    The nil was returned by a call to NSBundle's principalClass. Based on my understanding of the official documentation, there are two ways how the principalClass is determined.

    • The principal class name is specified manually in the info.plist file. As the plug-in did not have it specified here, this step should not apply.
    • The principal class is the first one listed on the ld command line when linking. As the exactly same plug-in binary was used on both High Siera and Mojave, "the first one listed on the ld command line" was the same so the returned principal class should be the same on both versions.

    Somehow, the principalClass call returned different value on High Sierra and Mojave. Personally, I do not see any reason why it should behave differently, as the documentation has not changed and the logic sounds to be dependent solely on what happened while compiling the plug-in not how the world context while running it.

    However, after I have added NSPrincipalClass item into the info.plist file, the plug-in loads successfuly on Mojave.