Demo Swift Alamofire
Swift Objective-C Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Demo Swift Alamofire
README.md
README.png

README.md

Demo Swift Alamofire

Alamofire

This demonstration shows:

This README describes how to create the project, if you want to try doing it yourself.

To learn more about Swift and Alamofire, see the official documentation for Alamofire

How to create the project

  1. Launch Xcode and create a new project. We call ours "Demo Swift Alamofire".

  2. Create a simple way to print some text to the screen, such as a text view with an IBOutlet named "demoTextView".

  3. Add Alamofire to the project.

    • To add Alamofire as a dependency, we prefer using Carthage.

    • If you prefer, you can add it by using a dynamic framework or using Cocoapods.

    • Need help with Carthage? See our repo demo_swift_carthage.

Add Alamofire

  1. Edit ViewController.swift.

  2. Add Alamofire networking code:

    import UIKit
    import Alamofire
    
    class ViewController: UIViewController {
    
      @IBOutlet weak var demoTextView: UITextView!
    
      override func viewDidLoad() {
        super.viewDidLoad()
        Alamofire.request("https://httpbin.org/get")
          .validate()
          .responseString { response in
             self.demoTextView.text = response.result.value
           }
         }
      }
      …
    }
    
  3. Verify Alamofire works by runing the app. The screen shows the response result value string, which looks something like this.

    {
      "args": {},
      "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip;q=1.0, compress;q=0.5",
        "Accept-Language": "en-US;q=1.0",
        "Host": "httpbin.org",
        "User-Agent": "MyApp/com.example.MyApp …"
      },
      "origin": "207.237.149.238",
      "url": "https://httpbin.org/get"
    }
    

Tracking

  • Package: demo_swift_alamofire
  • Version: 2.0.0
  • Created: 2016-05-30
  • Updated: 2016-10-10
  • License: BSD, GPL, MIT
  • Contact: Joel Parker Henderson (joel@joelparkerhenderson.com)