This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Alamofire | |
func makeGetCallWithAlamofire() { | |
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1" | |
Alamofire.request(todoEndpoint) | |
.responseJSON { response in | |
// check for errors | |
guard response.result.error == nil else { | |
// got an error in getting the data, need to handle it | |
print("error calling GET on /todos/1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func makeGetCall() { | |
// Set up the URL request | |
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1" | |
guard let url = URL(string: todoEndpoint) else { | |
print("Error: cannot create URL") | |
return | |
} | |
let urlRequest = URLRequest(url: url) | |
// set up the session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Alamofire | |
enum BackendError: Error { | |
case objectSerialization(reason: String) | |
} | |
extension Todo { | |
class func endpointForID(_ id: Int) -> String { | |
return "https://jsonplaceholder.typicode.com/todos/\(id)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func alamofireGet() { | |
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1" | |
Alamofire.request(todoEndpoint) | |
.responseJSON { response in | |
// check for errors | |
guard response.result.error == nil else { | |
// got an error in getting the data, need to handle it | |
print("error calling GET on /todos/1") | |
print(response.result.error!) | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Adding a header to a single request | |
func doRequestWithHeaders1() { | |
let headers: HTTPHeaders = [ | |
"X-Mashape-Key": MY_API_KEY, | |
"Accept": "application/json" | |
] | |
Alamofire.request("https://mashape-community-urban-dictionary.p.mashape.com/define?term=smh", headers: headers) | |
.responseJSON { response in | |
debugPrint(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func makeGetCall() { | |
// Set up the URL request | |
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1" | |
guard let url = URL(string: todoEndpoint) else { | |
print("Error: cannot create URL") | |
return | |
} | |
let urlRequest = URLRequest(url: url) | |
// set up the session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func doGetWithBasicAuthCredential() -> Void { | |
let username = "myUsername" | |
let password = "myPassword" | |
let credential = NSURLCredential(user: username, password: password, persistence: NSURLCredentialPersistence.ForSession) | |
Alamofire.request(.GET, "https://httpbin.org/basic-auth/\(username)/\(password)") | |
.authenticate(usingCredential: credential) | |
.responseString { _, _, result in | |
if let receivedString = result.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func doMashape() -> Void { | |
let manager = Alamofire.Manager.sharedInstance | |
let headers = ["X-Mashape-Key": "MY_API_KEY", "Accept": "application/json"] | |
manager.request(.GET, "https://mashape-community-urban-dictionary.p.mashape.com/define?term=hipster", headers: headers) | |
.responseString { _, _, result in | |
if let receivedString = result.value { | |
print(receivedString) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DetailViewController.swift | |
// objcInterop | |
// | |
// Created by Christina Moulton on 2015-07-02. | |
// Copyright (c) 2015 Teak Mobile Inc. All rights reserved. | |
// | |
import UIKit | |
import DZNEmptyDataSet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ScrollDemoViewController: UITableViewController { | |
var objects = [AnyObject]() | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
} | |
override func viewDidLoad() { |
NewerOlder