首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:正在导入Alamofire

错误:正在导入Alamofire
EN

Stack Overflow用户
提问于 2015-08-05 14:14:29
回答 3查看 1.5K关注 0票数 1

..Hi我很难导入Alamofire我已经完成了教程,但我在"import Alamofire“第2行收到错误消息。我应该构建什么阶段我的目标依赖是"Alamofire iOS (Alamofire)“,这是我唯一的选项,与教程中的"Alamofire (Alamofire)”没有"Alamofire (Alamofire)“选项。

代码语言:javascript
复制
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.
  }
}
EN

回答 3

Stack Overflow用户

发布于 2015-09-25 03:27:25

当我试图从git复制项目并将其添加到我的项目中时,我在使用Alamofire时遇到了很多麻烦。我的解决方案是使用CocoaPods的"s60“注释,所以下面是使用Podfile的步骤:

首先打开您的终端,并使用以下命令安装CocoaPoads:

代码语言:javascript
复制
sudo gem install cocoapods

安装后,使用命令cd+"name of path“转到应用程序的文件夹,例如:

代码语言:javascript
复制
cd Documents
cd AlamofireProject

当您在项目文件夹中时,使用下一条命令:

代码语言:javascript
复制
pod init

运行此命令后,应在您的目录中创建Podfile您应打开Podfile,然后指定要使用的Alamofire版本、Podfile的源以及要在应用程序中使用框架,以下是Podfile的外观

代码语言:javascript
复制
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target 'YOUR APP NAME' do
pod 'Alamofire', '~> 2.0'

end

编辑Podfile后,保存它,然后在终端中运行以下命令:

代码语言:javascript
复制
pod install

如果现在一切运行顺利,您的应用程序文件夹中应该有一个名为Pods的新文件夹和一个".xcworkspace“文件。现在,您必须在工作区文件中工作,在该文件中可以像这样顺利地引用Alamofire库:

代码语言:javascript
复制
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问候。

票数 2
EN

Stack Overflow用户

发布于 2015-08-11 02:27:58

集成Alamofire最简单的方法是使用CocoaPods

将以下内容添加到您的Podfile并运行pod更新Alamofire将自动集成到您的项目中

代码语言:javascript
复制
platform :ios, '8.0'
use_frameworks!

pod 'Alamofire', '~> 1.3.0

票数 0
EN

Stack Overflow用户

发布于 2015-10-12 13:47:59

Alamofire是用Swift编写的非常好的网络库。将Alamofire集成到项目中有两种方法:

  1. Cocoa Pod:将新的Alamofire库添加到当前项目中,请使用pod installation。下面是您必须集成到pod文件中的代码,以便全新安装Alamofire。

源'https://github.com/CocoaPods/Specs.git‘平台:ios,'8.0’use_frameworks!pod 'Alamofire','~> 2.0'

随着Alamofire 2.0最新版本的发布,请求方法发生了变化。

我在这里发布了一些示例步骤,它们对您最有帮助

下面是我的示例代码//Step:

代码语言:javascript
复制
    import Alamofire

//步骤:1

代码语言:javascript
复制
     var manager = Manager.sharedInstance

//指定我们需要的头部

代码语言:javascript
复制
    manager.session.configuration.HTTPAdditionalHeaders = [
    "Content-Type": "application/graphql",
    "Accept": "application/json" //Optional
    ]

//步骤:3然后调用Alamofire请求方法。

代码语言:javascript
复制
    Alamofire.request(.GET, url2).responseJSON { request, response,result in
    print(result.value)
    }

试试这个,或者你可以在xcode 7上查看alamofire的最新更新:

https://github.com/Alamofire/Alamofire

在Alamofire的早期版本中,请求方法中的句柄多了一个参数,现在已被删除。有关更多信息,请查看Git。我认为这会对你有更大的帮助。

  1. Mannual:从git:https://github.com/Alamofire/Alamofire下载Alamofire,然后解压下载的文件夹。

从您的项目-> 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 7Swift 2,那么您必须使用Alamofire的Cocoapod安装

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31824691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档