# Using Alamofire with Swift 2.0

Language: en
Canonical: [Using Alamofire with Swift 2.0](<https://allluckly.cn/en/journal/2015-11-09-using-alamofire-with-swift-2-0/>)
中文：[中文 HTML](<https://allluckly.cn/swift/Alamofire>)
English: [English HTML](<https://allluckly.cn/en/journal/2015-11-09-using-alamofire-with-swift-2-0/>)
Published: 2015-11-09T00:00:00+08:00
Modified: 2026-10-23T10:44:59+08:00
Author: [Bison](<https://allluckly.cn/about/>)

Shows how to import Alamofire manually, configure project dependencies and make network requests in a Swift 2.0 environment. Screenshots identify the project-linking settings, preserving an early framework integration and usage workflow.

Originally credited to Bison. Content is retained as published.

English translation of the [Chinese original](<https://allluckly.cn/swift/Alamofire>), translated on 2026-10-23. The article body uses automated translation; app descriptions, historical reading notes and video subtitles receive separate editorial checks. Original publication dates, attribution, code and version notes are retained.

**Before you read** This technical note dates from 2015–2017. The examples have not been rerun as part of this archive update. Targets Swift 2.0 and the Alamofire APIs available at the time.

This article uses Alamofire APIs from the Swift 2.0 era. It remains useful for examining how requests, parameters and response handling are organised. When adding the library to a new project, check the system, Swift and installation requirements for the specific release in the official repository, and use examples for that release. The old syntax in this article has not been migrated or recompiled.

- [Alamofire official repository and documentation](<https://github.com/Alamofire/Alamofire>)

Reading notes added on 2026-10-23

> "iOS technical sharing, iOS development, iOS development tips, iOS development blog" Bison

## Part 1: configure the project

Here I only describe adding third-party frameworks manually.`Pods` can look it up on Baidu. If you do not understand `Pods` can click the link. [Link](<https://allluckly.cn/en/journal/2015-05-20-installing-and-using-cocoapods-for-ios-development/>) First, create a project as shown below.

![1](<https://allluckly.cn/images/blog/Alamofire/1.png>)

Then put all extracted `Alamofire` files into the project folder you created, as shown below.

![2](<https://allluckly.cn/images/blog/Alamofire/2.png>)

This is the crucial moment: concentrate and pay attention!

![3](<https://allluckly.cn/images/blog/Alamofire/3.png>)

After this screen comes the most important step. Watch the red boxes carefully and do not choose the wrong option!

![4](<https://allluckly.cn/images/blog/Alamofire/4.jpg>)

Next, add the `Alamofire` static library to the project, as shown below.

![5](<https://allluckly.cn/images/blog/Alamofire/5.png>)

Then import the `Alamofire` header and run the project. If there are no errors, the imported files and project configuration are correct.

#### PS

A small tip from Bison: many third-party frameworks can be imported in a similar way, such as `HanekeSwift`.

## Part two: Bison shows you how to use `Alamofire`.

```css
import UIKit

import Alamofire

class ViewController: UIViewController {

    let BaiduURL = "http://apis.haoservice.com/lifeservice/cook/query?"

override func viewDidLoad() {
    super.viewDidLoad()
    //网络请求
    self .reloadData()
}

func reloadData(){


    let parameters = [
    "menu": "土豆",
    "pn":  1,
    "rn": "10",
    "key": "2ba215a3f83b4b898d0f6fdca4e16c7c",
    ]


    Alamofire.request(.POST, BaiduURL, parameters:parameters ).responseJSON {response in

    //            debugPrint(response)
    switch response.result {
        case .Success:
            //把得到的JSON数据转为字典
            if let j = response.result.value as? NSDictionary{
                //获取字典里面的key为数组
                let Items = j.valueForKey("result")as! NSArray
            //便利数组得到每一个字典模型
            for dict in Items{

                print(dict)
            }

        }
        case .Failure(let error):

            print(error)
        }


        }

    }

}
```

That concludes this tutorial. Leave a comment if you have questions; I will answer when I have time.

Recommended reading: [An illustrated guide to implementing iOS in-app purchases](<http://www.jianshu.com/p/05a3087cd796>)

Original article: https://allluckly.cn/

Copyright © Bison. Please retain a hyperlink to the original article when reproducing it.

