Search code examples
xcodelldbswift3xcode8swift2

Cannot debug Swift module/framework embedded in Objective-C app


Alternative titles (to aid searching)

  • Cannot debug Swift 2.3 framework linked to an Objective-C app in Xcode 8
  • error in auto-import: failed to get module 'XYZ' from AST context Xcode 8
  • Xcode 8 cannot debug Swift framework
  • warning: Swift error in module <XYZ>
  • Workaround for; Xcode Debugger cannot debug apps written in Objective-C only but that link against frameworks written in Swift only. (28312362)

I have an app written in Objective-C that links against some modules (frameworks) written in Swift 2.x.

Question

Everything (debugging etc.) works fine in , however when moving to and updating the modules to use I was unable to debug the modules.

LLDB reported these errors:

warning: Swift error in module XYZ.
Debug info from this module will be unavailable in the debugger.

error: in auto-import:
failed to get module 'ABC' from AST context

This does not happen if I link the modules to an app built in Swift 2.3.


Solution

  • tl:dr

    Add a user defined setting under "Build Settings" for your app target.

    SWIFT_VERSION = 2.3

    SWIFT_VERSION = 2.3 — Build Settings

    More Info

    I'm unsure if this is an Xcode 8 bug or if it's Apple policy (to try an force developers to Swift 3.0?). But... by default Xcode 8 installs the Swift 3.0 versions of the standard Swift runtime libraries.

    When it comes to debugging with LLDM the Swift 2.3 modules fail to load (in to the Swift 3.0 runtime).

    Forcing the app to use Swift 2.3 (or legacy Swift as Apple call it), fixes the issue.

    Swift apps have this setting exposed by Xcode but you have to manually add it for an Objective-C app.

    Further Advice

    Port your Swift 2.3 code to Swift 3.0 as soon as possible, Apple won't support 2.x for very long.