I'm simply fetching data from youtube API and show it on tableView. It was working fine just before Swift 3 upgrade but now it gives me an error.
I'm able to print JSON successfully but cannot have the title, description and the imageView displayed.
When I click on the videoTableView, I get an error on the lines starting with "videoObj".
The error message:
this class is not key value coding-compliant for the key snippet.'
let videoObj = Video()
videoObj.videoId = Video.value(forKeyPath: "snippet.resourceId.videoId") as! String
videoObj.videoTitle = Video.value(forKeyPath: "snippet.title") as! String
videoObj.videoDescription = Video.value(forKeyPath: "snippet.description") as! String
videoObj.videoThumbnailUrl = Video.value(forKeyPath: "snippet.thumbnails.maxres.url") as! String
arrayOfVideos.append(videoObj)
if self.delegate != nil {
self.delegate!.dataReady()
}
I've looked at similar questions and some of them suggested to check the storyboard for missing connections or class name but couldn't replicate them on my own project.
Some also suggested to clean the project, delete the app from simulator and device and get rid of the derived data but none of them seems to be the solution for me.
Before the Swift 3 upgrade, the lines were as follows;
let videoObj = Video()
videoObj.videoId = video.valueForKeyPath("snippet.resourceId.videoId") as! String
Where you have Video
, put (video as NSDictionary)
.
So for example:
videoObj.videoId = (video as NSDictionary).value(forKeyPath: "snippet.resourceId.videoId") as! String
...and so on.