Jul 11

When refactoring existing code, be careful to ensure that your Interface Builder outlets are still correct. For example, if I have a simple controller class with the following attributes:

XcodeScreenSnapz004

They are defined as IBOutlet’s and are, therefore, connected in Interface Builder to UI elements.

Interface BuilderScreenSnapz001

Now, let’s say we wish to change the name of “switcher” to “switchElement”. Obviously, the worst thing we could do is make the change manually, even without the Interface Builder connections we’d have to manually update both the .H and the .M files. So, we should make use of Xcode’s refactoring mechanism.

Right click on the attribute in question (“switcher”), and select Refactor

XcodeScreenSnapz005

This will bring up a new Dialog with the “rename” option already selected. Type in the new name, it will identify what files will be changed. You’ll notice that the .H, .M and the nib file are selected for changing.

Once you apply the change, you’ll need to revert the nib in Interface Builder to the version on file. However, Xcode doesn’t handle everything for you, there is one more step that you have to take care of. If you open up the connections part of the UI, you’ll see that it did, in fact, update your connection. But, the old outlet name still appears as another entry and the new name has a warning. The warning is that the class doesn’t have an outlet with the new name.

After banging my head for awhile trying to figure out why they wouldn’t take the final step during a refactor I realized I needed to do one more thing. Save the .M and .H files. Now, everything is in sync and working properly.

Tagged with:
Jul 08

You’ll notice that Xcode has built in Autocomplete (as most IDEs do). As you start typing, the IDE does its best to anticipate what you are trying to do and puts suggested code in for you. See below:

XcodeScreenSnapz003

In the above screenshot my cursor is after the ‘t’ in ’string’. All text to the right is suggested.

One cool feature of Xcode is using CTRL+/ you can immediately jump the the first parameter. The parameter is highlighted to allow for immediately typing and replacing. This saves a bit of time, as I was originally hitting RETURN mousing over and replacing the parameter. This saves a couple key strokes.

Tagged with:
Jul 05

Amazingly, Xcode comes built with a Unit Test suite and an Application Test suite. However, it took a bit of trying to fully understand how to set it up. The key element is adding a new Build Target.

XcodeScreenSnapz001

Set the new target as “Unit Test Bundle” and you’re done. Now, you can add new class files using the “Objective-C test case class” as the template and write Unit Tests. Now, make sure you set the only build target of this new class as the Unit Test target you created previously (that’s very important).

Now, when you want to run your unit tests, simple switch your build target and hit the build button.

XcodeScreenSnapz002

Tagged with:
Jul 04

There are a few steps that one must go through in order to setup their machine for iPhone development. First, you need to install XCode (and related tools), next sign-up for an Apple Developer Connection account, and last download and install the iPhone SDK.

Installing XCode

This is fairly straight forward. If you’ve recently purchased a new Mac, you’ll have a DVD with called the Tools Disk. Simply put this in the drive and run the installer. This will install XCode and many other developer tools. I’ll go over the tools in later posts as I learn about them. But some highlights are:

  • XCode – the primary IDE for Mac development. This is where we’ll be spending much of our time editing source code.
  • Instruments – a tool for gathering profiling information about your running application.
  • Interface Builder – this little guy is the graphical UI tool for setting up your interface and connecting it to source code.

If you don’t have the proper DVD, you can download the Tools DMG from the Apple Developer Connection Site.

One interesting note, is all Applications for development go into /Developer/Applications, not /Applications/Developer as I would have expected. I must admit this caused me a bit of confusion for awhile.

More information can be found at: http://developer.apple.com/documentation/Xcode/Conceptual/XcodeCoexistence/Contents/Resources/en.lproj/Basics/Basics.html

Sign Up for Apple Developer Connection

You can sign up for a free ADC account. This will give you access to a number of SDKs, including the iPhone SDK. It also gives access to a substantial amount of documentation (including the beginning iPhone development doc referenced below). Go to developer.apple.com and sign up. Later, we’ll need to sign up for the iPhone Developer Program (which is not free) in order to actually get our application to the iPhone device (rather than just the simulator), but that’s for later when we have something worth showing off.

Download and Install the iPhone SDK

Once you have your ADC account, sign in and go to http://developer.apple.com/iphone/program/sdk/. Here you can get the SDK (over 2 GB of SDK goodness). Once the download is complete, install it, and we are ready to begin.

Additional Info

I’ve decided to go through iPhone Development Guide for my first “Hello World” app. You can find it here: http://developer.apple.com/iphone/library/documentation/Xcode/Conceptual/iphone_development/000-Introduction/introduction.html

Tagged with:
preload preload preload