I had already started to read the book before, and liked it a lot. I think I completed the first app it teaches, RandomNumber. So I decided to read the specs and create it without looking in the book. I actually managed to. As I suspected, I had to browse the documentation a lot (especially for the random functions), but in the end, my little app did build.
Let me just say that I'm not fully satisfied with the documentation facilities built in Xcode. I will collect my thoughts on it as I gain more experience (and probably realize that lots of things that I didn't think were there are in fact there), and do a separate post on the subject later. All that I know is that, as a beginner, I could use a bit more hand-holding.
So anyway, here's how my version of the app differred from Aaron's.
Mine displayed the random number in a text field, not as a label. More importantly, I complicated things a bit, as I already applied the MVC concept to this simple little thingy.
While in Aaron's version (note that it is the first-ever app he has his readers build), the random number generation is done in the controller, my version actually has a model class, and the random number is one of its properties. Random number generation (as well as "seeding," or initialization) is performed in the model, all the controller does is call these methods, and update the text field with the randomNumber property of the model class.
I guess this is overkill, but then at least it's MVC. And the model preserves state, too.
Due to my lack of experience, I had no idea how the model object should be created. I decided to have only one instance throughout the life cycle of the app, and I had the controller (which is serialized in the nib, if I'm not mistaken) allocate and initialize it as soon as it awakes up from the nib.
I was a bit surprised when I found out (from sample code) that there's no need to call [super awakeFromNib] when implementing that method, if I'm subclassing NSObject, but then I confirmed that to be the case in the documentation.
I guess I could also serialize my model object in the nib file? Um, maybe not. This doesn't seem to be recommended. So I'll leave it at that.
Sunday, November 18, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment