Over the weekend I was working on some additions to my Craft Pricing Pro app. The main addition that is being added is the ability to share the information from the app in the form of a PDF. This will allow the user to print out lists of their projects and the relevant information along with a single sheet views of an individual project.
This was working until I went into an individual project view and returned. Once it returned, it would no longer generate a list of the projects, but instead a sheet of the last project viewed. I beat my head for hours attempting to fix this. I thought it was an issue with SwiftUI, then I thought it was an issue with the ShareLink command. I spent hours trying different things. I moved code into different functions. I made new functions thinking that might have been the problem. I was writing and rewriting various parts of my app over and over again then removing the changes when each new solution would fail.
Then, I began to notice the error messages that sometimes would show up saying that it couldn’t find a certain file. I also noticed that when I’d create a new PDF that filename would show up as the name of the PDF. It took a while, but eventually I made enough connections to figure out the solution to my problem. All the PDFs I was creating had the same file name. SwiftUI wouldn’t create a new file because the data didn’t change, so it would simply use the existing file and that would be the previous view.
So, I simply had to give each type of PDF that I was generating a different filename and the problem was solved. So hours of effort and searching for a solution was solved by simply changing one line of code in order to change a filename. Everything else was working just fine. It was both frustration, and oddly satisfying to finally solve the issue.
So, yeah. Sometimes the simplest solution will be the one that saves the day.