use CocoaPods 0.36.0 in CocoaTouchFramework with S

2019-08-31 14:14发布

问题:

I would like to use CocoaPods in my CocoaTouchFramework, which has Swift classes.

My Podfile looks the following:

platform :ios, '7.0'
inhibit_all_warnings!

link_with 'MyFramwork'

pod "AFNetworking", "2.5.0"

But how do I achieve to include e.g. AFNetworking into my .swift class in the CocoaTouch Framework? There's no briding header so I somehow have to import it directly in my swift class...

回答1:

AFNetworking is an objective-c library. So you need to have a bridging-header and import the correct headers.

If you want to use a Swift library for networking you should look to Alamofire. It's from the same creator. Put this in your podfile:

pod 'Alamofire', '~> 1.1'

In every Swift file where you want to use it import the library with this line:

import Alamofire


回答2:

You need to import AFNetworking, just using in your Swift files:

import AFNetworking

Be careful with upper/lower case letters, as autocompletion does not work. Import every pod library you need to use, using its name (i.e., the name of the folder inside the Pods group/directory)



回答3:

If you want to use AFNetworking pod, try to add an Objective-C class by using File->New->File->Cocoa Touch Class. Xcode will ask you to add bridge header. In your bridge header you can import AFNetworking such as;

#import <AFNetworking/AFNetworking.h>

If you don't want to use bridge header you should use Alamofire pod.