UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Day 50: Milestone: Projects 10-12

Forums > 100 Days of Swift

Took a while to figure out how to have the DetailViewController show the selected image. The solution was quite simple, and took me a couple of hours and many 'print()' to figure out.

All I had to do was to add URL....

class Image: NSObject, NSCoding {
    var name: String
    var url: URL

    init(name: String, url: URL){
        self.name = name
        self.url = url

    required init?(coder decoder: NSCoder){
        name = decoder.decodeObject(forKey: "name") as? String ?? ""
        url = decoder.decodeObject(forKey: "image") as? URL ?? URL(fileReferenceLiteralResourceName: "")

    func encode(with coder: NSCoder) {
        coder.encode(name, forKey: "name")
        coder.encode(url, forKey: "url")
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let dvc = storyboard?.instantiateViewController(identifier: "ImageView") as? DetailViewController {
            dvc.selectedImageURL = images[indexPath.row].url
            dvc.selectedImageName = images[indexPath.row].name
            navigationController?.pushViewController(dvc, animated: true)


TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.