Saturday, November 27, 2010

Don't Object to Objective C

As it turns out I don't care enough about writing a Twitter application as I originally thought. According to my research in order to get the authentication to work the best method is called xAuth. Using the xAuth method I would have to send an e-mail to Twitter's API e-mail address in order to get a key for my application. Being that it was just a learning application I decided that viewing the tweet string in the debugger was sufficient.


I just finished chapter 3, and we make one small enhancement to the InstaTwit application from the previous chapter. I added a text view, which was a new component for me, and learned about how to interact with the on-screen keyboard. There's no way to automatically tie functionality to the Done button on the keyboard. You can choose from various words for the button, but you actually have to tie it to an IBAction to get it to do anything.

While the chapter was light on coding it was full of detail on how Objective C was handling everything I was doing. Of the most interest to me was the way that memory management and garbage collection was done. Objective C uses something called reference counting. Certain things like calling retain, and alloc will increase the reference count by one, and other things like release will decrease the reference count by one. When the reference count reaches zero it will be cleaned up. Methods are also called in a different way than in most languages. They are called inside of brackets rather than with a period or arrow operator.

After a chapter of getting more in depth in Objective C we are ready for a chapter getting more in to depth about iOS. The next chapter will show me how to implement applications with more than one view. This should set me up nicely to make my own multiple view apps.

Friday, November 26, 2010

A Virgin to Subversion

It's been a fun last couple of days. First, I ran in the Gobble Jog 10k on Thanksgiving morning. The weather for the run was nice and cool, and I managed to meet my goal of under an hour with a time of 58 minutes. Being that it was my first 10k I was pleased with how I did.

After that I was headed out of town for Thanksgiving with my fiance's family. There was a lot of great food and even better people. Then it was back to Atlanta for Thanksgiving with my family. All in all a great couple of days filled with awesome food, and excellent company.

So I finally had a little bit of time to get some work in, but not quite enough to get OAuth working in my Twitter app that I made for chapter 2 of Head First iPhone Development. However, before I attempt to get my project to work, I want to be able to undo anything and revert back to the project's original state if I mess everything up. I could make a copy of the project as a backup, but there's a better and more sophisticated method.

Source control. It's a repository of your code that essentially is a snapshot of your project the last time that you committed it. That way as long as I commit my project before I attempt to implement OAuth I will be able to revert back to the original state of the project with the push of a button.

There are many different source control systems you can work with. I opted to go with Subversion because it has nice integration right in to Xcode. I am using a local repository on my laptop because I am only saving learning projects at this point. Once I am working on more important projects I will likely use an external repository incase anything happens to my laptop.

Once you create a Subversion repository you can add it to Xcode very easily. From that point you can import your project, and then check it out to start working on a controlled version of it. Once you save some changes to a file you will see an 'M' next to it in the project window indicating that it has been modified. You can commit the file to save the changes to Subversion, or you can revert the changes to get the file back to it's original state.

The best use of a source control system is to do checkins daily, and even more often if you just implemented a large piece of logic. It is good practice to only check in code that compiles. That way no matter what you do to the code you can always rollback to a stable version that builds. Now that I have Subversion in place I will begin trying to implement OAuth so that my InstaTwit application can send the tweets to Twitter.

Wednesday, November 24, 2010

A Little Hiccup

I have just completed chapter 2 of the book, and the material was introducing you to a new control called a picker. It's the spinning wheel thing that you sometimes see in an iPhone application. It also took you in to a bit more depth regarding buttons than the first chapter did.


So, the cool thing about pickers is that they don't store their own information. The information is stored using data sources and delegates, and the picker only knows how to ask about the data. When you scroll the picker it has to ask the for the items to display next. This is a very smart approach as performance would probably be severely hampered if a control was storing over 100 items in it especially considering that strings are the simplest things that you can display with a picker.

Now, about the above application. The purpose of the application was to make a Twitter app that could easily send a tweet with what you are doing, and how you are feeling. It seems silly from an actual user standpoint, but it has merit as a learning device. I got everything working just fine, but then when I went to hit the "Tweet it!" button:

You can see that I was getting an error of "Basic authentication is not supported". Apparently sometime between when this book was published, and when I actually did this exercise Twitter upgraded from basic authentication to OAuth authentication. I checked the website for the book for a fix, but I could not find anything. 

Glancing forward it appears that we are modifying the InstaTwit application in chapter 3 to better understand the Objective C that we are using so I would like the application to actually be able to tweet to Twitter, and not just the command line. I am hoping that my next blog post will have detailed information on how to get InstaTwit converted from basic authentication to OAuth authentication. It's probably a better learning exercise than immediately moving on with the book.

Tuesday, November 23, 2010

It Starts...

So today I got quite a lot of packages in the mail. First, I got a new book. Head First iPhone Development has been an interesting read so far. It reads very much like the other Head First title that I read, which is a good thing, as it makes learning a new IDE (Xcode) and a new language (Objective-C) that much easier.


I also got in the mail a MacBook Pro, and a case to store it in. Let's just say that a Mac is not intuitive to pick right up for a Windows user like myself, but after some strenuous Googling of things like "how do I right click on a Mac" and "how do I take a screen shot on a Mac" I am much more at home on this computer. After messing around for a little bit I registered as an Apple developer (free until I want to debug on an actual iPhone) and installed Xcode and the iOS SDK. I finally had everything ready to go to start learning how to build apps.

The first chapter of the book is exactly the same as the C# book in terms of how they introduce you to a book. I was building an app right out of the gate. The whole purpose of the chapter is to get you creating a functional, albeit simple, iPhone app. It very lightly goes in to detail about how you accomplish this, but for the most part it's just taking you on a brief walkthrough of the various tools (Xcode, Interface Builder, and iPhone Simulator) so that you are familiar with them in the following chapters.

The app that I had to build was a large button with a text label on top of it, and when you press the button the text changes to some predetermined text that I hardcoded in to the event handler function.


Now, I wish the experience of the first chapter was as easy as I just made it sound, but I inadvertently introduced an error in to my program. It took me a little while, and a lot of Googling, but I ended up unlinking my view to the file owner. While I was frustrated at the time in hindsight it's better to make mistakes like that when you are learning because you end up learning more about what you are working on. Chapter 2 looks to delve in to the world of Twitter, so I hope to annoy some of you with my application's tweets. You can follow me at: http://twitter.com/myrx84.

Friday, November 19, 2010

The Next Iteration of Me

So I am just about done reading through this book "Head First C#", and I have to say I was very pleased with the style of the book. It uses pictures to deliver the point more thoroughly than purely words can accomplish. It also makes use of repetition to make sure that key points are driven home. Now, this book, like many programming books, is very remedial at the beginning. There are probably a few chapters that you can skim through because they cover topics that most software developers would know, but they are still worth skimming as there are still C# nuances in the simplest of things.

I was so pleased with the style of writing and how it lent itself to learning that I decided to order another Head First book. Head First iPhone Development should be arriving in a couple of days. There are a couple of things that you need to know before diving in to iPhone development, and the first of those things is that you need to have a Mac to run the SDK. There are ways to get your PC to boot Mac, and do it on there, but even with that method there are a lot of drawbacks. I had been wanting a personal laptop for a while now, and while I occasionally enjoy making fun of Apple, I can see the personal advantages of learning another operating system, and set of IDEs. With that being said I have ordered a MacBook Pro. It should arrive fairly closely in relation to the Head First book so I should be able to get started with both around the same time.

I do not want to limit my mobile development to one platform, and since I have an HTC Incredible for a phone I will be picking up Head First Android Development when it is released in March. Understanding how both operating systems work, and how to develop applications for both platforms will be much more valuable to me than only learning one.

What you can expect to see in the future is a sort of chronicling of my journey through learning how to develop on the iPhone. There may also be remarks related to running as that is one of my favorite things to do, and where I think a lot about programming, and things that I want to learn.

It's time to pick up a book and learn something new and exciting!