11
Alamofire + UITableView NSCoders México

Alamofire + UITableView

Embed Size (px)

Citation preview

Page 1: Alamofire + UITableView

Alamofire + UITableView

NSCoders México

Page 2: Alamofire + UITableView

NSCoders México

Agenda¿Que es alamofire?

¿Para que sirve?¿Como se usa?

¿Cómo proceso la respuesta?¿Cómo lo integro a un componente

(UITableview)?DEMO

Acerca de mi

Page 3: Alamofire + UITableView

An HTTP networking library for iOS and OS X

this product develop for Alamofire Software Foundation.

Page 4: Alamofire + UITableView

¿Para que sirve?❖ Chainable Request / Response methods

❖ URL / JSON / plist Parameter Encoding

❖ Upload File / Data / Stream / MultipartFormData

❖ Download using Request or Resume data

❖ Authentication with NSURLCredential

❖ HTTP Response Validation

❖ TLS Certificate and Public Key Pinning

❖ Progress Closure & NSProgress

❖ cURL Debug Output

❖ Comprehensive Unit Test Coverage

Page 5: Alamofire + UITableView

¿Como se usa?❖ Agregando como POD

❖ source 'https://github.com/CocoaPods/Specs.git'

❖ platform :ios, '9.0'

❖ use_frameworks!

❖ pod 'Alamofire', '~> 3.3'

❖ Agregando de forma manual

❖ git submodule add https://github.com/Alamofire/Alamofire.git

❖ Abrir el proyecto compilando y generando el .Framework

Page 6: Alamofire + UITableView

¿Como se usa?

//Importando la librería en la clase que se utilizara import Alamofire

Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"]) .responseJSON { response in print(response.request) // original URL request print(response.response) // URL response print(response.data) // server data print(response.result) // result of response serialization

if let JSON = response.result.value { print("JSON: \(JSON)") } }

Page 7: Alamofire + UITableView

¿Cómo proceso la respuesta?Existen varias formas de procesar la respuesta que nos devuelve alamofire veamos un ejemplo: {

songs: [{ title: "1904", artist: "The Tallest Man on Earth", year: "2012", web_url: "http://www.songnotes.cc/songs/78-the-tallest-man-on-earth-1904", img_url: "http://fireflygrove.com/songnotes/images/artists/TheTallestManOnEarth.jpg" }, { title: "#40", artist: "Dave Matthews", year: "1999", web_url: "http://www.songnotes.cc/songs/119-dave-matthews-40", img_url: "http://fireflygrove.com/songnotes/images/artists/DaveMatthews.jpg" }, { title: "40oz to Freedom", artist: "Sublime", year: "1996", web_url: "http://www.songnotes.cc/songs/45-sublime-40oz-to-freedom", img_url: "http://fireflygrove.com/songnotes/images/artists/Sublime.png" }, { title: "#41", artist: "Dave Matthews", year: "1996", web_url: "http://www.songnotes.cc/songs/46-dave-matthews-band-41", img_url: "http://fireflygrove.com/songnotes/images/artists/DaveMatthews.jpg" }] }

Page 8: Alamofire + UITableView

¿Cómo proceso la respuesta?

//Validamos que la respuesta contenga un NSArray con todos los elementos de lista de canciones if let JSON = response.result.value{

self.arraySongs = JSON[“songs"] as! NSArray }

//Obtenemos un elemento del array y lo casteamos para imprimir su valor

let dataCell = arraySongs[indexPath.row] cell.textLabel?.text = dataCell["artist"] as? String

Page 9: Alamofire + UITableView

¿Cómo lo integro en un UITableView?

❖ Declaramos una colección para alimentar el UITableview

❖ poblamos la colección para llenar el tableView

❖ recargamos el tableview para poblarlo con el contenido de la colección

Page 10: Alamofire + UITableView

DEMO

❖ https://github.com/ingscjoshua/sampleJSONTableView

Page 11: Alamofire + UITableView

Acerca de mi

❖ Josué Hernández Ramírez

❖ Twitter: @josh004_

❖ mail: [email protected]