func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "idTable") as! TableViewCell let URL = NSURL(String: arrayOfURL[indexPath.row]) //let URL = NSURL(string: "https://vk.com/video_ext.php?oid=-28639294&id=456244781&hash=704a23ae4dfd10f0&__ref=vk.api&api_hash=1479374300a44cd0ffe4586e5649_GI3DKNBWGE3DA") cell.videoView.loadRequest(NSURLRequest(url: URL! as URL) as URLRequest) cell.titleLabel.text = "asdas" return cell } Closed due to the fact that the essence of the issue is not clear to the participants of HamSter , Denis , user194374, Denis Bubnov , post_zeew Nov 25 '16 at 22:16
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
2 answers
correct line
let URL = NSURL(String: arrayOfURL[indexPath.row]) on:
let URL = NSURL(string: arrayOfURL[indexPath.row]) - what's the difference? - Nursultan Kenzhegaliyev
- onein the spelling of the argument name - string is written with a small letter. Swift is case sensitive - Pavel
- Please do not forget to mark the answer as correct - Pavel
- I have not checked it yet - Nursultan Kenzhegaliyev
Better to suggest you do this:
... guard let urlStr = arrayOfURL[indePath.row] as? String, let URL = NSURL(string: urlStr) else {return fatalError()} ... So you will protect yourself firstly from optional, secondly from the fact that String does not return in the array. Well, you can rearrange the code a bit in the method, so that it is even better if you mean that you will definitely have URLs for the video (and their absence is not acceptable)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "idTable") as! TableViewCell cell.titleLabel.text = "asdas" guard let urlStr = arrayOfURL[indePath.row] as? String, let URL = NSURL(string: urlStr) else {return fatalError()} cell.videoView.loadRequest(NSURLRequest(url: URL! as URL) as URLRequest) return cell }
Well, or so, if urlov may not be
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "idTable") as! TableViewCell cell.titleLabel.text = "asdas" if let urlStr = arrayOfURL[indePath.row] as? String{ let URL = NSURL(string: urlStr) cell.videoView.loadRequest(NSURLRequest(url: URL! as URL) as URLRequest) } return cell