Troubleshooting tips part 1: NSLog, etc.

In the course of working on part four of the Expenses tutorial I kept getting the error about the store being incompatible with the store used to create the file despite the fact that I copied the code over from a working project. I of course started with the generic “Clean All” option, but that didn’t do me any good. As I have never had any formal programming classes (other than a year in Middle school where we had to make a flowchart for how to make a cheeseburger and wrote everything in BASIC, and I don’t mean Visual Basic, I mean late 1980’s BASIC) I don’t really understand how debuggers work, I can do some really basic stuff with the Xcode one now, but nothing of substance. After I was convinced that I had done everything right (after all I’m perfect, right?) I added a single NSLog to the start of the newly overridden method NSLog(@”configuring store.”);. Then I hit build and run, and was confronted by the lack of any statements in the log about configuring store. I was of course at once convinced that there must be something wrong in the system so I, again, did the default “Clean” thinking that would solve it, still no message in the log. I tried a different machine, still no log message. I then went hunting in the docs to see if the method had been deprecated, but it hadn’t been. In desperation I copied the method from the documentation and pasted it into my code, suddenly I had a log message and it all worked. I, of course, was confused and so looked back through the part of the tutorial with the method in it, to see if I miss a part of the method or something. It looked right… until I finally looked letter by letter and saw that I had mis-spelled coordinator by leaving out an ‘o’ the odds of me mis-spelling words is pretty high (I suck at spelling) so I should have looked for that kind of thing sooner, but I thought I had pulled from working code. As I have been learning to write software these kinds of things have happened less often, somewhat due to experience but mostly because I have learned ways to work with my ignorance.I use NSLog all over the place to help find where things go off the tracks. I have logged each step of a method that was giving me issues before, putting in the values of variables and counts of arrays to see if what I designed to have happen actually happens. This of course means that I have to get rid of all those NSLogs at some point, or have my customer’s console fill up with crap every time they run my app (assuming, of course that I will have more than just the one small Mac app and two small iPhone apps out one day). There are several approaches out there to making this easy, I tend to go really low tech and just #define MSLOG to be either ‘NSLog’ or ‘//’ Depending on what kind of build I am doing. I haven’t used much in the way of automated defines or used scripts in my build process as of yet, but I am now starting to learn such things. So far I have a simple script that increments the build number each time (I got the basic script from a blog whose name now escapes me and altered it to work the way I wanted). One of the other things I have started doing is keeping a notes file in each project so I can keep track of things right in the project. I am now starting to work on a way to split this notes file out of the app but in the same folder. The idea behind the notes file is that I put in more info than would normally go into a commit message, while the commit message might say something like adds feature x, the notes file will say how feature x was added so I can do it again in a different project if I want. THe notes file also gives me a place to record ideas that didn’t work so I don’t try to get a feature to work the same wrong way five different times. This is really useful for me since I tend to have multiple projects of similar idea at the same time and may go months between times I work on one of them, generally I have one that is my real project and one that is my sandbox to try ideas out. Once I get an idea to work in the sandbox I move it over to the main project using the notes file as a guide for what I need to copy and paste over and what IB connections and bindings are needed. Let me know what you all have come up with to make your coding lives easier. As I come up with other ideas, possibly based on some of your comments, I will post about them as well.

About theMIkeSwan

Entertainment Lighting Tech, OS X & iOS developer
This entry was posted in Programming and tagged . Bookmark the permalink.

Leave a Reply