Swift expression evaluator (LLDB): error while loading Swift module - ios

I have a target with mixed Swift and Objective-C code. I do the following:
I put a breakpoint on a line in a Swift file part of this target.
I run this target.
I type po $someVariableName in the debugger once it hits the breakpoint.
The debugger now shows a host of errors, ending with:
error: failed to import bridging header '/path/to/Bridging-Header.h'
Couldn't initialize Swift expression evaluator due to previous errors.
The output starts with:
Error while loading Swift module:
TARGET_NAME: /path/to/Bridging-Header.h:18:9: note: in file included from /path/to/Bridging-Header.h:18:
In between are a host of nullability annotation warnings and errors about unknown type names. Some errors come from bridging headers in the Carthage builds directory:
error: /path/to/project/Carthage/Build/iOS/Some.framework/Headers/Some-Swift.h
It seems as if whatever is executing after my po statement, lacks a few header imports or executes things in the wrong order. Any clue as to what could be wrong here?
I am using Xcode 11.4 (11E146)

Related

XCode : Cannot print object in console when debuging

Without any reason, Xcode show an error when i whan ton print using the debuger console :
(lldb) po self
warning: Swift error in scratch context: error: failed to load module 'XXX'
.
Shared Swift state for XXX.app has developed fatal errors and is being discarded.
REPL definitions and persistent names/types will be lost.
error: expression failed to parse:
unknown error
It's an iOS project with cocoapods. I'm on an M1 pro chip.
Any idea ?
I would start with simply print(self) instruction and check what appears in the console.
I like also debug(self) function (prints the whole object hierarchy).
If you want to print thread, you can use Thread.callStackSymbols.forEach { print($0) }
Have you tried set a breakpoint and then browse the Variable List (left side of the Debug Area)?

Swift compiling error [duplicate]

This question already has answers here:
'filenames are used to distinguish private declarations of the same name' error
(8 answers)
Closed 4 years ago.
my team and I are having problems for compile a Objective C project in Xcode 9.4. Anyone have an idea of what's happening??
<unknown>:0: error: filename "Message+CoreDataClass.swift" used twice: '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Message+CoreDataClass.swift' and '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Message+CoreDataClass.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "Message+CoreDataProperties.swift" used twice: '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Message+CoreDataProperties.swift' and '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Message+CoreDataProperties.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "Model+CoreDataModel.swift" used twice: '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Model+CoreDataModel.swift' and '/Users/josepmmirabent/houtel-ios-2016/Houtel2/DerivedData/Jumbotours/Build/Intermediates.noindex/Jumbotours.build/Debug-iphonesimulator/Jumbotours.build/DerivedSources/CoreDataGenerated/Model/Model+CoreDataModel.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
Thanks!
Go into your project settings > select your main app target > Build phases > Compile Sources and remove the duplicate entries in that list referring to the files listed in your compile errors. It looks like some files are listed for compilation twice which would cause this issue.
This is usually an issue in the xcode project file, I have had this issue occur due to manually resolving git conflicts in the project file.
If that does not solve your issue make sure you do not have files with the same name in the project.

Swift unit-testing: Debug info from this module will be unavailable in the debugger

I have Objective-C project and I decided to write unit test in Swift.
Everything runs normally however I cannot see param values during debugging.
When I set cursor on value I see its name and not value:
when I try to print it out in lldb I get following error:
(lldb) po expectedEncryptedStr
warning: Swift error in module AppLibTests.
Debug info from this module will be unavailable in the debugger.
error: in auto-import:
failed to get module 'AppLibTests' from AST context:
I use Version 8.2.1 (8C1002)
Any ideas?
[EDIT]
When I enter with braking point to Objective-C code - everything works as expected

Using an Obj-C sub-project in a Swift application

My team has a few full Obj-C libraries we like te reuse in our projects. To do so, we usually set up a git submodule, and then add it to the xcode project as a sub-project (Using target dependency, link binary with library and updating the User Header Search Paths)
So far it's only been done in full Obj-C projects, and I'm now trying to use it in a Swift project but with very little success so far. I tried to add the briding-header file, referenced it in the project and filled it like so :
#import "MyLibraryHeader.h"
With the target header being in the User Header Search Paths.
It lets me build, but when using it in my Swift files:
let test = MyLib();
let secondTest = MyLib.classMethod1("some_arguments");
I get an EXC_BAD_INSTRUCTION on secondTest, and the following logs in the debugger:
(lldb) po test
error: <EXPR>:1:1: error: use of unresolved identifier 'test'
(lldb) po secondTest
error: Error in auto-import:
failed to get module 'MyProject' from AST context:
/Users/siegele/Sources/MyProject_iOS/MyProject/Classes/MyProject-Bridging-Header.h:12:9: error: 'MyLibraryHeader.h' file not found
#import "MyLibraryHeader.h"
^
failed to import bridging header '/Users/siegele/Sources/MyProject_iOS/MyProject/Classes/MyProject-Bridging-Header.h'
Found the following question with no answer : Xcode 6 crashing when using Objective-C subproject inside Swift
Any help would be appreciated.
I followed the HockeyApp tutorial that can be found here:
http://support.hockeyapp.net/kb/client-integration-ios-mac-os-x/integrate-hockeyapp-for-ios-as-a-subproject
In the end, I was on the right tracks but messed up the Header Search Paths:
Add subproject xcodeproj to the workspace
On the main project : Link binary with library, and add the subproject product library (Bonus points : add it as a target dependency too)
Update Header Search Paths (not User Header Search Paths) accordingly
Import your Library.h in the main project Bridging-Header.h file
What threw me off for a while is that the Swift Compiler setting for the Objective-C Bridging Header was not set automatically. Check the Build Settings for your target and ensure the "Objective-C Bridging Header" setting is not blank.

Unit testing a static library with RestKit

I'm attempting to follow along with the RestKit unit test guide ( https://github.com/RestKit/RestKit/wiki/Unit-Testing-with-RestKit ) except that my project is a static library instead of an app.
Here is the test I've written:
- (void)testMappingOfDate
{
id parsedJSON = [RKTestFixture parsedObjectWithContentsOfFixture:#"plan.json"];
RKMappingTest *test = [RKMappingTest testForMapping:[self planMapping] object:parsedJSON];
[test expectMappingFromKeyPath:#"plan.date" toKeyPath:#"date"];
STAssertNoThrow([test verify], nil);
}
When I attempt to run the test I receive this error on the first line of the test:
error: testMappingOfDate (api_clientTests) failed: -[NSBundle parsedObjectWithContentsOfResource:withExtension:]: unrecognized selector sent to instance 0x1765c40
It seems like its not finding the NSBundle category defined by RestKit, but my test target header search path is set to "$(BUILT_PRODUCTS_DIR)/../../Headers" and I've verified this path includes NSBundle+RKAdditions.h which contains the supposed "unrecognized selector".
Is there something I'm missing here?
You are trying to include a category within your binary that comes from a library. To get that accomplished you will need to add the following to your (Unit-Test-Target's) build settings.
Other Linker Flags: -ObjC
From Apple's QA:
Objective-C does not define linker symbols for each function (or
method, in Objective-C) - instead, linker symbols are only generated
for each class. If you extend a pre-existing class with categories,
the linker does not know to associate the object code of the core
class implementation and the category implementation. This prevents
objects created in the resulting application from responding to a
selector that is defined in the category.
Solution:
To resolve this issue, the static library should pass the -ObjC option
to the linker. This flag causes the linker to load every object file
in the library that defines an Objective-C class or category. While
this option will typically result in a larger executable (due to
additional object code loaded into the application), it will allow the
successful creation of effective Objective-C static libraries that
contain categories on existing classes.
The error means that the "unrecognized selector" issue is at runtime. The compiler and NSBundle+RKAdditions.h do not give this error they would at compile timr.
The issue is that the code that has #implementation NSBundle(RKAdditions) is not linked into your app. So you need to add this to your build

Resources