Why additional #import in bridging header failed in swift?
Asked Answered
A

5

8

Before I added a new dependency to my test project via CocoaPods, I have already added a C header file ('wahoo.h') and exposed it to the swift code via a bridging header file "wahoo-Bridging-Header.h". The test app could be compiled and run without any problem.

Then I added a new dependency 'STHTTPRequest' to my project. You can see the list of file here:

enter image description here

If I added this line:

#include <STHTTPRequest/STHTTPRequest.h>

It will fail to compile with this error message:

enter image description here

I have tried a few alternatives but they all failed:

#include "STHTTPRequest.h"

#import "STHTTPRequest.h"

Apparently I cannot have more than one bridging header file in a project. How can I fix this import problem?

EDIT I can get around the problem if I copy the header file from Pods into SO1 and add #include "SO1/STHTTPRequest.h" to the bridging header. It is not an ideal solution.

How can I automate the copying of header files? Or alternatively how can make header files in Pods accessible to SO1?

Antiseptic answered 9/9, 2014 at 8:10 Comment(7)
Does it work if you #include "STHTTPRequest/STHTTPRequest.h"?Grekin
The STHTTPRequest.h is in another project in the same workspace, have you tried the path where the file is in the project navigator? <Pods/Pods/STHTTPRequest/STHTTPRequest.h>Fulltime
@Grekin That would not work, since file paths are in <>Fulltime
@ViktorLexington: well that's what I see in my swift project - I am using several pods - but it looks like they are interchangeable, because I've just tried replacing "" with <> and it compiles in both casesGrekin
@ViktorLexington Sorry it did not workAntiseptic
@AnthonyKong What's the relative path (from the directory containing your project) of your bridging header in finder ? And what did you set in the build settings at Objective-C Bridging Header ?Cusco
Have the exact same issue, did you resolve it by any chance?Couchant
A
1

This works:

#include <STHTTPRequest.h>
Antiseptic answered 10/9, 2014 at 9:15 Comment(1)
Add ${PODS_ROOT} as recursive and then it will start workingParental
R
7

You need to tell Xcode where to look for the header files you’re listing in the bridging header. Find the Search Paths section, and change the project-level setting for Header Search Paths, adding a recursive entry for the Pods directory. It should be Pods/** now.

In the Bridging Header include with:

#include <STHTTPRequest/STHTTPRequest.h>

or because of recursive search path:

#include <STHTTPRequest.h>
Roseboro answered 12/2, 2015 at 0:13 Comment(0)
D
3

You should add the following header search path: "${PODS_ROOT}/Headers/STHTTPRequest"

Discontinuous answered 10/9, 2014 at 8:43 Comment(0)
M
2

I added "Pods/Headers/Public" as a recursive entry in the build settings for my project under "Search Paths/User Header Search Paths".

I then can use is standard import format: - #import "AFNetworking/AFNetworking.h"

Mallee answered 18/12, 2014 at 13:29 Comment(0)
A
1

This works:

#include <STHTTPRequest.h>
Antiseptic answered 10/9, 2014 at 9:15 Comment(1)
Add ${PODS_ROOT} as recursive and then it will start workingParental
F
0

If your pod library in Objective c in that case you need to import class like this -

@import STHTTPRequest;

Frolic answered 11/7, 2017 at 12:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.