错误:导入Alamofire [英] Error: Importing Alamofire

查看:87
本文介绍了错误:导入Alamofire的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

..我在导入Alamofire时遇到了麻烦,虽然本教程已经完成,但是在 import Alamofire第2行中出现了错误消息。我该怎么办?..在buid阶段,我的目标依赖项是 Alamofire iOS(Alamofire)和 Alamofire OSX(Alamofire)的唯一选择,而在本教程中没有 Alamofire(Alamofire)的选择。

..Hi I'm having a hard time Importing Alamofire I've finished the tutorial but I got an error message in "import Alamofire" line 2.. what should I do??..In buid phases my Target Dependencies was "Alamofire iOS (Alamofire)" that was my only option together with the "Alamofire OSX (Alamofire)" no option for "Alamofire (Alamofire)" like in the tutorial..

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.
  }
}


推荐答案

I当我尝试从git复制项目并将其添加到我的项目时,Alamofire遇到了很多麻烦。我的解决方案是使用CocoaPods的 s60注释,所以这里是使用Podfile的步骤:

I had a lot of trouble with Alamofire when I tried to copy the project from git and add it to my project. my solution was "s60" comment to use CocoaPods, so here are the steps to using a Podfile:

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

First open your terminal and install CocoaPoads with the following command:

sudo gem install cocoapods

安装后,使用命令cd +路径名转到应用程序的文件夹,例如:

After installation go to the folder of your app with the commands cd+"name of path" for example:

cd Documents
cd AlamofireProject

在项目文件夹中时,使用以下命令:

When you are inside your project folder use the next command:

pod init

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

After running this command a Podfile should be created in your directory you should open the Podfile and then specify the version of Alamofire that you want to use, the source of the Podfile and that you want to use frameworks in your app, here is how you Podfile should look

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

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

end

在编辑Podfile之后保存并运行终端中的以下命令:

After you edit your Podfile save it and then run this command in the terminal:

pod install

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

If everything runs smoothly now you should have in your app folder a new folder called Pods and a ".xcworkspace" file. Now you must work in the workspace file where you can reference the Alamofire library smoothly like this:

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问候语。

This is a sample function of an Alamofire request that I use in one of my apps. If you have any trouble leave me a comment. XD Greetings.

这篇关于错误:导入Alamofire的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆