Skip to main content
adicionou 22 caracteres ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
func searchBuscape(query: String) {
    guard
        let escapedSearch = query.stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet()),
        url = NSURL(string:  "http://sandbox.buscape.com.br/service/findProductList/554163674d2f57624d676f3d/BR/?categoryId=77&keyword=\(escapedSearch)&format=json")
    else { return }
    NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: { (data, response, error) -> Void in
        guard
            let httpURLResponse = response as? NSHTTPURLResponse where httpURLResponse.statusCode == 200,
            let data = data where error == nil
        else { return }
        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            var error: NSError?
            let json = JSON(data: data, options: .AllowFragments, error: &error)
            if let error = error {
                print(error.localizedDescription)
            }

            print("===json start")
            print(json)
            print("===json end")

            print(json["totalresultsreturned"])  // 16
            print(json["product"][0]["product"]["pricemin"])  // 819.90
            print(json["product"][0]["product"]["pricemax"])  // 1199.00

            // pra voce extrair um array de dicionários do json object você precisa acessar arrayObject property da segunte forma
            if let products = json["product"].arrayObject as? [[String:AnyObject]] {
                for product in products {
                    print("productStart=======")
                    print(product)
                    print("productEnd=======")
                }
                let pricesArrayMin = products.map{$0["product"]?["pricemin"]??.doubleValue ?? 0}.sort()
                print("pricesMinStart=======")
                print(pricesArrayMin)
                print(pricesArrayMin.count)    // 16
                print(pricesArrayMin.first!)   // 539.1    menor(produto precomais minimobarato)
                print(pricesArrayMin.last!)    // 2898.99
                print("pricesMinEnd=======")
            }
        }
    }).resume()
}
func searchBuscape(query: String) {
    guard
        let escapedSearch = query.stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet()),
        url = NSURL(string:  "http://sandbox.buscape.com.br/service/findProductList/554163674d2f57624d676f3d/BR/?categoryId=77&keyword=\(escapedSearch)&format=json")
    else { return }
    NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: { (data, response, error) -> Void in
        guard
            let httpURLResponse = response as? NSHTTPURLResponse where httpURLResponse.statusCode == 200,
            let data = data where error == nil
        else { return }
        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            var error: NSError?
            let json = JSON(data: data, options: .AllowFragments, error: &error)
            if let error = error {
                print(error.localizedDescription)
            }

            print("===json start")
            print(json)
            print("===json end")

            print(json["totalresultsreturned"])  // 16
            print(json["product"][0]["product"]["pricemin"])  // 819.90
            print(json["product"][0]["product"]["pricemax"])  // 1199.00

            // pra voce extrair um array de dicionários do json object você precisa acessar arrayObject property da segunte forma
            if let products = json["product"].arrayObject as? [[String:AnyObject]] {
                for product in products {
                    print("productStart=======")
                    print(product)
                    print("productEnd=======")
                }
                let pricesArrayMin = products.map{$0["product"]?["pricemin"]??.doubleValue ?? 0}.sort()
                print("pricesMinStart=======")
                print(pricesArrayMin)
                print(pricesArrayMin.count)    // 16
                print(pricesArrayMin.first!)   // 539.1    menor preco minimo
                print(pricesArrayMin.last!)    // 2898.99
                print("pricesMinEnd=======")
            }
        }
    }).resume()
}
func searchBuscape(query: String) {
    guard
        let escapedSearch = query.stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet()),
        url = NSURL(string:  "http://sandbox.buscape.com.br/service/findProductList/554163674d2f57624d676f3d/BR/?categoryId=77&keyword=\(escapedSearch)&format=json")
    else { return }
    NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: { (data, response, error) -> Void in
        guard
            let httpURLResponse = response as? NSHTTPURLResponse where httpURLResponse.statusCode == 200,
            let data = data where error == nil
        else { return }
        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            var error: NSError?
            let json = JSON(data: data, options: .AllowFragments, error: &error)
            if let error = error {
                print(error.localizedDescription)
            }

            print("===json start")
            print(json)
            print("===json end")

            print(json["totalresultsreturned"])  // 16
            print(json["product"][0]["product"]["pricemin"])  // 819.90
            print(json["product"][0]["product"]["pricemax"])  // 1199.00

            // pra voce extrair um array de dicionários do json object você precisa acessar arrayObject property da segunte forma
            if let products = json["product"].arrayObject as? [[String:AnyObject]] {
                for product in products {
                    print("productStart=======")
                    print(product)
                    print("productEnd=======")
                }
                let pricesArrayMin = products.map{$0["product"]?["pricemin"]??.doubleValue ?? 0}.sort()
                print("pricesMinStart=======")
                print(pricesArrayMin)
                print(pricesArrayMin.count)    // 16
                print(pricesArrayMin.first!)   // 539.1    (produto mais barato)
                print(pricesArrayMin.last!)    // 2898.99
                print("pricesMinEnd=======")
            }
        }
    }).resume()
}
adicionou 1 caractere ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
func searchBuscape(query: String) {
    guard
        let escapedSearch = query.stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet()),
        url = NSURL(string:  "http://sandbox.buscape.com.br/service/findProductList/554163674d2f57624d676f3d/BR/?categoryId=77&keyword=\(escapedSearch)&format=json")
    else { return }
    NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: { (data, response, error) -> Void in
        guard
            let httpURLResponse = response as? NSHTTPURLResponse where httpURLResponse.statusCode == 200,
            let data = data where error == nil
        else { return }
        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            var error: NSError?
            let json = JSON(data: data, options: .AllowFragments, error: &error)
            if let error = error {
                print(error.localizedDescription)
            }

            print("===json start")
            print(sonjson)
            print("===json end")

            print(json["totalresultsreturned"])  // 16
            print(json["product"][0]["product"]["pricemin"])  // 819.90
            print(json["product"][0]["product"]["pricemax"])  // 1199.00

            // pra voce extrair um array de dicionários do json object você precisa acessar arrayObject property da segunte forma
            if let products = json["product"].arrayObject as? [[String:AnyObject]] {
                for product in products {
                    print("productStart=======")
                    print(product)
                    print("productEnd=======")
                }
                let pricesArrayMin = products.map{$0["product"]?["pricemin"]??.doubleValue ?? 0}.sort()
                print("pricesMinStart=======")
                print(pricesArrayMin)
                print(pricesArrayMin.count)    // 16
                print(pricesArrayMin.first!)   // 539.1    menor preco minimo
                print(pricesArrayMin.last!)    // 2898.99
                print("pricesMinEnd=======")
            }
        }
    }).resume()
}
func searchBuscape(query: String) {
    guard
        let escapedSearch = query.stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet()),
        url = NSURL(string:  "http://sandbox.buscape.com.br/service/findProductList/554163674d2f57624d676f3d/BR/?categoryId=77&keyword=\(escapedSearch)&format=json")
    else { return }
    NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: { (data, response, error) -> Void in
        guard
            let httpURLResponse = response as? NSHTTPURLResponse where httpURLResponse.statusCode == 200,
            let data = data where error == nil
        else { return }
        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            var error: NSError?
            let json = JSON(data: data, options: .AllowFragments, error: &error)
            if let error = error {
                print(error.localizedDescription)
            }

            print("===json start")
            print(son)
            print("===json end")

            print(json["totalresultsreturned"])  // 16
            print(json["product"][0]["product"]["pricemin"])  // 819.90
            print(json["product"][0]["product"]["pricemax"])  // 1199.00

            // pra voce extrair um array de dicionários do json object você precisa acessar arrayObject property da segunte forma
            if let products = json["product"].arrayObject as? [[String:AnyObject]] {
                for product in products {
                    print("productStart=======")
                    print(product)
                    print("productEnd=======")
                }
                let pricesArrayMin = products.map{$0["product"]?["pricemin"]??.doubleValue ?? 0}.sort()
                print("pricesMinStart=======")
                print(pricesArrayMin)
                print(pricesArrayMin.count)    // 16
                print(pricesArrayMin.first!)   // 539.1    menor preco minimo
                print(pricesArrayMin.last!)    // 2898.99
                print("pricesMinEnd=======")
            }
        }
    }).resume()
}
func searchBuscape(query: String) {
    guard
        let escapedSearch = query.stringByAddingPercentEncodingWithAllowedCharacters(.URLQueryAllowedCharacterSet()),
        url = NSURL(string:  "http://sandbox.buscape.com.br/service/findProductList/554163674d2f57624d676f3d/BR/?categoryId=77&keyword=\(escapedSearch)&format=json")
    else { return }
    NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: { (data, response, error) -> Void in
        guard
            let httpURLResponse = response as? NSHTTPURLResponse where httpURLResponse.statusCode == 200,
            let data = data where error == nil
        else { return }
        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            var error: NSError?
            let json = JSON(data: data, options: .AllowFragments, error: &error)
            if let error = error {
                print(error.localizedDescription)
            }

            print("===json start")
            print(json)
            print("===json end")

            print(json["totalresultsreturned"])  // 16
            print(json["product"][0]["product"]["pricemin"])  // 819.90
            print(json["product"][0]["product"]["pricemax"])  // 1199.00

            // pra voce extrair um array de dicionários do json object você precisa acessar arrayObject property da segunte forma
            if let products = json["product"].arrayObject as? [[String:AnyObject]] {
                for product in products {
                    print("productStart=======")
                    print(product)
                    print("productEnd=======")
                }
                let pricesArrayMin = products.map{$0["product"]?["pricemin"]??.doubleValue ?? 0}.sort()
                print("pricesMinStart=======")
                print(pricesArrayMin)
                print(pricesArrayMin.count)    // 16
                print(pricesArrayMin.first!)   // 539.1    menor preco minimo
                print(pricesArrayMin.last!)    // 2898.99
                print("pricesMinEnd=======")
            }
        }
    }).resume()
}
removeu 55 caracteres do conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17

Voce não precisa de nenhuma framework para fazer isso. Você pode usar NSURLSession dataTaskWithURL e criar um método para baixar os dados de forma assíncrona da seguinte forma:

Voce não precisa de nenhuma framework para fazer isso. Você pode usar NSURLSession dataTaskWithURL e criar um método para baixar os dados de forma assíncrona da seguinte forma:

Você pode usar NSURLSession dataTaskWithURL e criar um método para baixar os dados de forma assíncrona da seguinte forma:

adicionou 1 caractere ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando
adicionou 928 caracteres ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando
adicionou 338 caracteres ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando
Reversão para edição 5
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando
adicionou 195 caracteres ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando
adicionou 248 caracteres ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando
adicionou 92 caracteres ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando
adicionou 1109 caracteres ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando
adicionou 1109 caracteres ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando
adicionou 66 caracteres ao conteúdo
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando
Fonte Link
Leo Dabus
  • 1,1mil
  • 10
  • 17
Carregando