..Hi我很难导入Alamofire我已经完成了教程,但我在"import Alamofire“第2行收到错误消息。我应该构建什么阶段我的目标依赖是"Alamofire iOS (Alamofire)“,这是我唯一的选项,与教程中的"Alamofire (Alamofire)”没有"Alamofire (Alamofire)“选项。
import UIKit
import Alamofire
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Alamofire.request(.GET, "http://ec2-54-169-246-41.ap-southeast-1.compute.amazonaws.com:3000", parameters: nil)
.response { request, response, data, error in
println(request)
println(response)
println(error)
}
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}发布于 2015-09-25 03:27:25
当我试图从git复制项目并将其添加到我的项目中时,我在使用Alamofire时遇到了很多麻烦。我的解决方案是使用CocoaPods的"s60“注释,所以下面是使用Podfile的步骤:
首先打开您的终端,并使用以下命令安装CocoaPoads:
sudo gem install cocoapods安装后,使用命令cd+"name of path“转到应用程序的文件夹,例如:
cd Documents
cd AlamofireProject当您在项目文件夹中时,使用下一条命令:
pod init运行此命令后,应在您的目录中创建Podfile您应打开Podfile,然后指定要使用的Alamofire版本、Podfile的源以及要在应用程序中使用框架,以下是Podfile的外观
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target 'YOUR APP NAME' do
pod 'Alamofire', '~> 2.0'
end编辑Podfile后,保存它,然后在终端中运行以下命令:
pod install如果现在一切运行顺利,您的应用程序文件夹中应该有一个名为Pods的新文件夹和一个".xcworkspace“文件。现在,您必须在工作区文件中工作,在该文件中可以像这样顺利地引用Alamofire库:
import Alamofire
Alamofire.request(.GET, "https://omgvamp-hearthstone-v1.p.mashape.com/cards",parameters:["X-Mashape-Key:":"ibxqtnAb9BmshWhdS6Z4zttkVtQop1j0yGSjsn6tn5x2Y4BBF0"])
.responseJSON { _, _, result in
switch result {
case .Success(let data):
let json = JSON(data)
debugPrint(data)
self.Photos = self.ParseHS(json)
self.performSegueWithIdentifier("ToCollection", sender: self)
case .Failure(_, let error):
print("Request failed with error: \(error)")
}
}这是我在我的一个应用程序中使用的Alamofire请求的示例函数。如果你有任何问题,请给我留言。XD问候。
发布于 2015-08-11 02:27:58
集成Alamofire最简单的方法是使用CocoaPods
将以下内容添加到您的Podfile并运行pod更新Alamofire将自动集成到您的项目中
platform :ios, '8.0'
use_frameworks!
pod 'Alamofire', '~> 1.3.0‘
发布于 2015-10-12 13:47:59
Alamofire是用Swift编写的非常好的网络库。将Alamofire集成到项目中有两种方法:
Alamofire库添加到当前项目中,请使用pod installation。下面是您必须集成到pod文件中的代码,以便全新安装Alamofire。源'https://github.com/CocoaPods/Specs.git‘平台:ios,'8.0’use_frameworks!pod 'Alamofire','~> 2.0'
随着Alamofire 2.0最新版本的发布,请求方法发生了变化。
我在这里发布了一些示例步骤,它们对您最有帮助
下面是我的示例代码//Step:
import Alamofire//步骤:1
var manager = Manager.sharedInstance//指定我们需要的头部
manager.session.configuration.HTTPAdditionalHeaders = [
"Content-Type": "application/graphql",
"Accept": "application/json" //Optional
]//步骤:3然后调用Alamofire请求方法。
Alamofire.request(.GET, url2).responseJSON { request, response,result in
print(result.value)
}试试这个,或者你可以在xcode 7上查看alamofire的最新更新:
https://github.com/Alamofire/Alamofire
在Alamofire的早期版本中,请求方法中的句柄多了一个参数,现在已被删除。有关更多信息,请查看Git。我认为这会对你有更大的帮助。
从您的项目-> click on add files to "project" ->中,导航到extracted folder -> find Alamofire.xcodeproj ->,选择Alamofire.xcodeproj文件->,请确保选中了Copy items if needed。
现在是时候将Alamofire添加到嵌入式二进制文件中了。为此,单击项目名称,然后导航到General tab ->,选择Embedded Binaries ->,单击'+‘-> now add Alamofire.xcodeproj。
最后,在.swift文件中使用import Alamofire,只要你想使用Alamofire。
但我个人的观点是,如果您使用的是Xcode 7和Swift 2,那么您必须使用Alamofire的Cocoapod安装
https://stackoverflow.com/questions/31824691
复制相似问题