Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Playground para a questão
//: Playground - noun: a place where people can play
import UIKit
import Foundation
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
let url = NSURL(string: "")!
var imagens = [String]()
var links = [String]()
func get() {
NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: {
(data, response, error) -> Void in
// error
if error != nil {
// resposta vazia
guard let data = data else { return }
// parse do JSON
do {
let json = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) as! [[String: AnyObject]]
for objeto in json {
// preenche os arrays com os dados do JSON
} catch {
print("erro no parse do JSON: \(error)")
// teste dos arrays
imagens.count //quantidade de itens dentro de imagens
imagens[0] //mostra o objeto 0 de imagens
links.count //quantidade de itens dentro de links
links[1] //mostra o objeto 1 de imagens
// chama o metodo de teste
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment