我想在框架的viewcontroller中使用Alamofire发出一些网络请求。
// Call
let myURLString = "https://jsonplaceholder.typicode.com/todos/1"
Alamofire.request(myURLString)
.responseJSON { response in
// do stuff with the JSON or error
}
但是,它正在返回
No such module 'Alamofire'
答案 0 :(得分:2)
首先,您应该创建CocoaTouch框架的目标。
然后您应该将CocoaTouch框架添加到主项目的PodFile:
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'MainApp' do
use_frameworks!
end
target 'CocoaTouchFramework' do
use_frameworks!
end
pod 'Alamofire'
或者您可以为框架设置特定的容器:
platform :ios, '9.0'
use_frameworks!
#Your custom framework's pods
def customframework_pods
pod 'Alamofire'
end
target 'MainApp' do
pod 'MyAwesomePod', '~>1.0'
customframework_pods
end
target 'CocoaTouchFramework' do
customframework_pods
end
我找到了另一个答案:
来源: Youval Vaknin's Medium Article
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!
workspace 'YourWorkSpaceName'
xcodeproj 'Project/ProjectName.xcodeproj'
xcodeproj 'CustomFramework/Framework.xcodeproj'
def project_pods
pod 'Alamofire'
end
def framework_pods
pod 'Alamofire'
end
target 'ProjectName' do
xcodeproj 'Project/ProjectName.xcodeproj'
project_pods
end
target 'ProjectName' do
xcodeproj 'Project/ProjectName.xcodeproj'
project_pods
end
target 'Framework' do
xcodeproj 'CustomFramework/Framework.xcodeproj'
framework_pods
end
target 'Framework' do
xcodeproj 'CustomFramework/Framework.xcodeproj'
framework_pods
end
我希望它能起作用
享受