unable to print object ('po') in xcode6 be

2019-03-08 09:35发布

问题:

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?

回答1:

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.



回答2:

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.



回答3:

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.



回答4:

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



回答5:

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).