Hi all,
I've been struggling trying to get my top shelf extension to work with a remote resource. The example app shows how to set it up with a static peice of content. Here's a snippet of what I am trying to do.
var topShelfItems: [TVContentItem] {
return sectionedTopShelfItems
}
var items: [TVContentItem] = []
private var sectionedTopShelfItems: [TVContentItem] {
let jsonUrl = ServiceProvider.ShowcaseURL
let session = NSURLSession.sharedSession()
let shotsUrl = NSURL(string: jsonUrl)
let task = session.dataTaskWithURL(shotsUrl!) {
(data, response, error) -> Void in
do {
let jsonData = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers ) as! NSDictionary
self.items = self.mapDataToContentItem( jsonData )
} catch _ {
/
print("Failed to get JSNO data for top shelf!")
}
}
task.resume()
return self.items;
}
Since no logs seem to be output from the console, I can't see what is going on. I think it has to do with the URL request itself being an async call. so when the app gets the JSON from the server it returns an empty list first before it's able to finish processing the data of the URL request. I know it's making the call to get the JSON, I can see the request being made on the server end. Is it possible to get this work using an async call? What am I missing?
--Thanks,
Michael