Bridge issue when using AFNetworking with Pods in Swift Project

I ran into a problem when I initialize AFHTTPSessionManager in my quick class. I added AFNetworking using containers in my project. It shows the use of undeclared errors. But when I click CMD + Click on AFHTTPSessionManager, it will bring me to the desired class.

This is my bridging header class

I added a bridge header and an imported AFNetworking.h class. I tried to fix this problem by adding a title to the header in various ways. 1- I created my own header class by creating a new header file 2- I created the object class c test in the swift project and added the bridge title when it asks to add the title header in the project.

This is how I set build settings

This is how I used AFNetworking in my Swift class

The Bridging header also did not work with the self created by the test class when I tried to initialize it in my swift class.

Can someone help me deal with this issue?

+6
source share
3 answers

I know the pain ... I encountered the same problems that tried to get AFN to work on the playground. I did not succeed in this endeavor. But it really worked in the project, and I learned something along the way.

First, I configure the bridge title in my project build settings (as you did) and import the AFN as follows:

#import <AFNetworking/AFNetworking.h> 

Secondly, I set the Pods Project build setting "Defines the module" to "Yes."

1o2KXZD.png

Then I did a simple build (Product -> Build or Option + B) to make sure it was done. Then I launched the simulator.

+6
source

I managed to get it to work this link.

Then, in the bridge header file, I imported the AFNetworking framework, as in any framework. I also imported BButton.h, which is a third-party library that is not a pod infrastructure, but something that I placed directly in my project

 #import "BButton.h" #import <AFNetworking/AFNetworking.h> 

Then in the Swift file calling the AFNetworking code, I had to import AFNetworking, but not BButton

 import UIKit import AFNetworking class RootViewController: UIViewController { @IBOutlet weak var emailButton: BButton! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. // Set the icon for the email signup button self.emailButton!.setTitle(NSLocalizedString("", comment: ""), forState: UIControlState.Normal) self.emailButton!.setType(BButtonType.Primary) self.emailButton!.addAwesomeIcon(FAIcon.FAEnvelope, beforeTitle: true) let manager = AFHTTPRequestOperationManager() manager.GET( "http://headers.jsontest.com", parameters: nil, success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in println("JSON: " + responseObject.description) }, failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in println("Error: " + error.localizedDescription) } ) } } 

Hope that helps

0
source

In addition to everything you have done, add "use_frameworks!". Add to your subfile so it looks like this:

 target 'appName' do use_frameworks! pod 'AFNetworking' end 

run the pod install command again

0
source

Source: https://habr.com/ru/post/976657/


All Articles