It seems every time I need to add some functionality to my app, I end up refactoring other code in the app so the new functionality can use it. This is a GOOD thing. Especially when one is not yet an expert in iPhone app development.
It takes a fair amount of experimenting to learn how to write for the iPhone. This experimentation yields pretty messy code, but code nonetheless. In an ideal world I would throw away this experimental code and rewrite it once I learned the “right way”. However, I fear no app would ever get finished that way.
Instead, go ahead and use the experimental code, realizing that it isn’t perfect. Fix and clean it when you either need to reuse it somewhere else (and refactor mercilessly), or when you find that your code doesn’t really work as well as you thought, e.g. it won’t rotate worth a darn.
Now if I can just get the testers to install it!
Enabling rotation has been a pain, and I’m not sure it is really all that necessary for my app, but it has certainly forced me to clean up my code. It seems like every single thing I had done “wrong” in the code broke when I turned on rotation. It has forced me to really clean up my view controllers and memory management. In the end, I might even turn off rotation. But enabling it will have been good for the app in the long run.
Today’s tip: Enable rotation in your app! It’s the good kind of pain!
And today’s learning is regarding Objective-C and accessors, from Scott Stevenson at theocacao.com:
When using properties with the dot syntax, prefix the name with self to use the accessor:
value = studio;
studio = value;
self.studio = value;
value = self.studio
Even if you have garbage collection enabled, you should still use the accessor methods in most cases because Key-Value Observing, and Cocoa Bindings depend on these methods being called to synchronize changes across objects.
A subtle point, but an important one. Especially when dealing with pesky object retention problems!
9:30 - I know that everyone is waiting with baited breath! Well, I have to say, “not yet”. I was all ready to enable rotation (2nd try), when I realized I needed to do my scroll view memory usage optimization first. Unfortunately, that exposed some previously hidden memory management issues, which forced me to learn some new tools and finally figure out Objective-C memory management. Now I seem to have that solved, so I can check it in and get on to rotation. Except, wait, I did get the app to crash last night, so better look at that first…
10:00 - Ah, the debugger’s nightmare. Console log was gone, crash log no help, and can’t reproduce it. Oh, well, sure I’ll see it again later. Time to check-in!
10:10 - Are the “blog” gods as powerful as the “demo” gods? Just as soon as I wrote the last paragraph, I crashed the app! Let’s see why I won’t be able to debug this one…
10:30 - Again, no console log, crash log no help. Gotta see if I can reproduce it while plugged in… YES!
12:44 - Got a bunch of stuff fixed. I want to write it is ready for check-in, but I know now that I wrote that, something will crash…
14:09 - Cleaned up and ready to check-in!