Tuesday, July 30, 2013

Lessons learned

So last night I was working on getting a singleton1 created to store the player data so that I don't have to track it through all the different view controllers in OttoJotts (there are quite a few). I had done it with the dictionary already and that was working beautifully, so I thought this would be a piece of cake. I created the new class (using NSObject as the base), pretty much copied and pasted the code, made the requisite changes, and compiled. And I got this cryptic message:
The unusual error
I was a little surprised. I had declared that PlayerAccountData was a singleton. I mean, hadn't I just copied and pasted the code? Hadn't I made the changes that I needed to make? I went back and checked - yes, everything looked correct and all the changes had been made. What the heck was going on here? Why would this not compile? Obviously I'd done something wrong. Oh wait - this was the Xcode 5 developer preview; could that mean something? I searched online to see what I could learn and was stumped. Nothing seemed to work. And no one else seemed to have seen this. What on earth was going on?
Then I noticed that things seemed "not quite right" in the file. And here's what I mean by "not quite right":
Comparison of the new and old code
The original code had coloring for the SYNTHESIZE_SINGLETON_FOR_CLASS macro which the new code didn't. Now what the hell did that mean? Why didn't it recognize it as regular code? I tried adding the #import for the SynthesizeSingleton.h - no luck. I tried removing it - no luck. So back to the web! And nothing. And I had a sad face.
Something made me open the right-hand side bar for the file - and that's when I noticed something interesting. There was a check box under the section called "Target Membership". It was unchecked for the new file. But right there was my app logo next to the check box. And when I clicked it? The syntax coloring changed for SYNTHESIZE_SINGLETON_FOR_CLASS! Well, how 'bout them apples?
So what was the lesson learned or, in my case, re-learned? Really check to see what's happening with the error messages you get from Xcode. Sometimes they seem cryptic but actually contain the exact information you need to fix the error. But I think in this particular case it means that sometimes the differences between what you expect and what you get may be slightly hidden from you. I didn't even think about the right-hand properties sidebar for my .m file - and it didn't dawn on me that when I added the file to the project that it wouldn't be appropriately associated. But the next time I add a class, I'm going to be double-checking to make sure that the target membership is set correctly. And maybe this saves you a little time in the end too.
Happy coding.

1. The SynthesizeSingleton macro I'm using is from the incredibly awesome Matt Gallagher of CocoaWithLove.com. The singleton code is located here.

Sunday, July 28, 2013

OttoJotts REBORN!

Once, a long time ago in a land far, far away, there lived a wanna-be game developer who decided oh-so-frivolously that he would write a game based on a game from his youth. One that he had played with his very erudite mother and worked wonders to both improve his vocabulary and his spelling. He thought that he could write the basic game in a few weeks and then the multiplayer version in a few months and be done by the end of summer. But alas - our wanna-be game developer had a case of the hubris.
He was able to complete the core game mechanics in a week or so and then spent far, far too many days working on getting the user interface to work. For, you see, our developer wasn't "graphically inclined" (read: his artwork suxors). So he spent many a day trying to get some basic things looking good enough to play. And then - amazingly - the single player version was complete! And there was much rejoicing!
As he began to work on the two player version, however, he stumbled and stuttered and fell flat on his face, for his game required a "back-end" (read: database and middleware to talk between the device and the database). And he despaired because again, alack, his database skills were "lackluster" at best and his middleware skills were, perhaps, rated "mediocre". He worked diligently, though, trying to connect all of the pieces. And finally, he got some of the information he wanted to get from the device to the database and back again! And there was more rejoicing!
But then came the actual "two player" work. And there was much gnashing of teeth and grunting of exertion and swearing of curses. And the developer grew weary and tired and despaired of ever completing his opus. He feared that perhaps he would always just be a "wanna-be" game developer.
And then the Great Fruit From Which A Bite Has Been Taken decided that the manner in which he getting information from and to the database was WrongTM. And it was deprecated (read: removed). And the developer was despondent. Not only would he have to actually finish the work to allow two player games to work but he would also have to change all of the code that worked to do that work. And he despaired. And exerted. And cursed. And gave up.
One day, he found that his current hosting provider was deprecating the product he had grown to love these past 10 years and would require that he move to one that was far more limited or one that was WAY more complicated. He decided to move his website and his databases and his code to a new provider who offered a product more in line with his old product. And it was good.
Then, while distracted with another as-yet-fruitless pursuit, he decided to open up the old code and see whether it was possible to make the needed changes for the new database host and make sure he followed the rules of the Great Fruit From Which A Bite Has Been Taken. After looking at the code and the middleware he decided that it wouldn't be that bad after all. And he poked and prodded the middleware, making a tweak here and a revision there until - it worked! And there was astonishment!
And our poor, despondent wanna-be game developer is no longer so despondent (although he is much poorer). He had Purpose. He had Intent. He had - a real opportunity to actually get back to finishing the damn thing.
So now, to you, my gentle reader who has so patiently put up with this long and purposeless fable, I make claim to the Twitterverse, the Facebookverse, and general Internetverse that OttoJotts is REBORN! And it WILL. BE. DONE! (By Halloween.) (No seriously, I mean this.) (Stop laughing.) (Dicks.)