use CocoaPods 0.36.0 in CocoaTouchFramework with Swift

巧了我就是萌 提交于 2019-12-12 06:35:25

问题


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.



来源:https://stackoverflow.com/questions/29140393/use-cocoapods-0-36-0-in-cocoatouchframework-with-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!