unable to print object ('po') in xcode6 beta 6 osx swift project: (Error in auto-import: failed to get module '__ObjC' from AST context)

MacosSwiftXcode6

Macos Problem Overview


An attempt to print object (po command) in xcode 6 beta 6 OSX Swift project results in this error message:

(lldb) po managedObject
error: Error in auto-import:
failed to get module '__ObjC' from AST context

In this case the object in question is an instance of NSManagedObject.

Any advice on how to help auto-import in getting __ObjC module into LLVM Abstract Syntax Tree context?

Macos Solutions


Solution 1 - Macos

As of Xcode 6.1 if you attempt the po command twice it will work on the second attempt. The first po command will always fail for each new debugging session but subsequent calls work.

Solution 2 - Macos

Have same issue in xcode 7.3.1:

error: Error in auto-import:
failed to get module 'Touch' from AST context:
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/libxml/tree.h"
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/libxml/tree.h:17:10: error: 'libxml/xmlversion.h' file not found
#include <libxml/xmlversion.h>
         ^
could not build Objective-C module 'LibXML2'

But you can use fr v managedObject instead of po managedObject.

Solution 3 - Macos

I'd recommend double-checking that you have the

> -D DEBUG

flag set under 'Other Swift Flags' for the scheme that you're using to debug. I experienced similar issues when I'd accidentally deleted it.

Solution 4 - Macos

A clean of my project and deleting DerivedData worked for me.

Solution 5 - Macos

I discussed a similar error message with an Apple engineer at WWDC2017. It seems like this issue can have many causes, and I am aware that mine is slightly different than the one described above.

My team spent weeks trying to figure this out, and it ended up being a bug on Apple's compiler, which we could never have figured out by ourselves. Also, it has a VERY easy workaround.

So, this is just me posting the fix here, in order to maximize the probability that someone else does a search for this confusing error message, and finds this answer.

So, here it is. In our case, we had an Objective-C project using a mix of Swift and Objective-C frameworks. This fix might apply in slightly different contexts, just try it.

There happens to be a bug with the way the compiling flags get aggregated from the frameworks and the project, and the "pure Objective-C" project "activates" it.

Solution: add one single, empty Swift file ("Whatever.swift", or whatever) in your Objective-C project, making it not-pure-objective-c any more (new->file->Swift file, don't create the bridging header. The file will only contain the import of Foundation).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMaxim VolginView Question on Stackoverflow
Solution 1 - MacosRobert WagstaffView Answer on Stackoverflow
Solution 2 - MacosAlexander DanilovView Answer on Stackoverflow
Solution 3 - MacosgemmakbarlowView Answer on Stackoverflow
Solution 4 - MacosNicoView Answer on Stackoverflow
Solution 5 - MacosfredericouimetView Answer on Stackoverflow