Umair Aamir Umair Aamir - 9 days ago 5
Objective-C Question

Bridging issue while using AFNetworking with Pods in a Swift Project

I am facing problem when I initialise AFHTTPSessionManager in my swift class. I have added AFNetworking using pods in my project. It shows error use of undeclared type. But when I press CMD + Click on AFHTTPSessionManager it takes me to the right class.

This is my bridging header class

I have added bridging header and imported AFNetworking.h class in it. I have try to fix this issue by added bridging header in many ways.
1- I have created bridging header class myself by creating new header file
2- I have created objective c test class in swift project and added bridging header when it asks to add bridging header in project.

This is how I set build settings

This is how I used AFNetworking in my Swift class

Bridging header also didn't work with myself created test class when I tried to initialise it in my swift class.

Can anyone help me sorting out this issue?

Answer

I know the pain... I ran into the same issues trying to get AFN working in a Playground. I was not successful in that endeavor. But it did work in the project and I learned a few things along the way.

First, I configure the bridging header in my Project's build settings (as you have done) and import AFN like this:

#import <AFNetworking/AFNetworking.h>

Second, I set the Pods Project build setting "Defines Module" to Yes.

Then I executed a plain build (Product -> Build or Option+B) to see if it took. Then I launched the Simulator.