Search code examples
swiftxcodeswiftuixcode11

Navigation Link suddenly not working after 1 day


Yesterday, everything worked fine for me, but when I ran the app today(with the same code!) my Navigation Link won't work. I really have no idea where the problem could be. I'm pretty new to swift so it could be something very obvious.

This is in the console when the Navigation Link is pressed:

2020-03-20 22:53:12.447955+0100 To Do App[2650:175993] [ProcessSuspension] 0x10de7c450 - ProcessAssertion::processAssertionWasInvalidated()

Code of the List Item:

import SwiftUI

struct ToDoItemView: View {
    static let taskDateFormat: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateStyle = .medium
        formatter.timeStyle = .short
        formatter.timeZone = .current
        return formatter
    }()



    @State var title:String = ""
    @State var info:String = ""
    var createdAt:Date = Date()
    @State var until:Date = Date()
    var body: some View {
        HStack{
            if info == "" || "\(until)" == ""{
                Text(title)
                        .font(.headline)
                Spacer()
                Text("\(until, formatter: Self.taskDateFormat)")
                    .font(.caption)
            }else{
                Text(title)
                    .font(.headline)
            Spacer()
            Text("\(createdAt, formatter: Self.taskDateFormat)")
                .font(.caption)




            NavigationLink(destination: ModalView(title: self.$title, info: $info, until: $until)){
                Image(systemName: "arrow.down")
                    .foregroundColor(.clear)
                }
            }

        }
        .padding(.horizontal)


    }
}

Solution

  • NavigationView is missing. Add the same.

    var body: some View {
        NavigationView {
            HStack{
                if info == "" || "\(until)" == ""{
                    Text(title)
                            .font(.headline)
                    Spacer()
                    Text("\(until, formatter: Self.taskDateFormat)")
                        .font(.caption)
                }else{
                    Text(title)
                        .font(.headline)
                Spacer()
                Text("\(createdAt, formatter: Self.taskDateFormat)")
                    .font(.caption)
    
    
    
    
                NavigationLink(destination: ModalView(title: self.$title, info: $info, until: $until)){
                    Image(systemName: "arrow.down")
                        .foregroundColor(.clear)
                    }
                }
    
            }
            .padding(.horizontal)
       }
    }