i have loop meant make 10 different calls youtube's api using alamofire, each different videoid function. call however, doesn't seem made because i'm not getting results success nor failure options in alamofire switch.
can point out whats wrong?
func getrecom(completion: (result:string)->()) { let array = defaults.arrayforkey("recomquery") in 0..<10 { let videourl = "https://www.googleapis.com/youtube/v3/videos?part=contentdetails%2c+snippet&id=\(array![i])&maxresults=10&key=\(apikey)" alamofire.request(.get, videourl).validate().responsejson { response in switch response.result { case .success: print("success") //this not being called if let value = response.result.value { let json = json(value) let videotitle = json["items"][0]["snippet"]["title"].stringvalue print("title network \(videotitle)") let thumbpath = string(json["items"][0]["snippet"]["thumbnails"]["default"]["url"]) print(i) let image = uiimage(data: nsdata(contentsofurl: nsurl(string: thumbpath)!)!)! let newimage: nsdata = uiimagepngrepresentation(image)! self.recomtitles.append(videotitle) self.recomthumbs.append(newimage) } case .failure(let error): print("failure") //this not being called print(error) completion(result: "done") } } } print("saving array: \(defaults.arrayforkey("recomtitles"))") defaults.setobject(recomthumbs, forkey: "recomthumbs") defaults.setobject(recomtitles, forkey: "recomtitles") completion(result: "done") }
thanks in advance!
if run in playground, chances program ends before print called, because call async method. if that's case, call xcpexecutionshouldcontinueindefinitely() @ beginning.
Comments
Post a Comment