Combining .Net and iPhone Development (Part 2 Adding another string to the bow)

Often when you read blogs or articles on improving .NET development skills you’ll find a recurring theme : learn another language or learn a new technology. For the C# .Net developers that usually means looking at languages like VB, Ruby, Java, PHP, Pytho. In terms of technologies it involves looking at one of the myriad of .Net technologies like MVC, Silverlight, Entity Framework, WPF, AJAX, jQuery,Windows Mobile etc… etc…

So the main reason this is a recurring theme, is because as a developer by learning new language you are taking yourself outside your comfort zone and exposing yourself to a new syntax, techniques, tools and frameworks. Whilst this can be daunting at times or may even seem slightly pointless (ie. If you are a great VB.NET developer in a great  VB.NET job why would waste your time changing), you need to consider the potential benefits in applying yourself to a new language.

Now iPhone development is not the most logical move for .Net developers. Historically, there is a fair bit of tension and antagonism between the Apple and the Microsoft camps. Suggesting there is a logical reason to  combine the development skillsets of the two big competitors may not seem that sensible. However, from a .Net developers perspective I feel there is a significant case to add the iPhone SDK to your skillset including:

  • The massive growth in iPhone usage is now starting to see a change in job prospects for iPhone developers. For Australian developers just type “iPhone” in a developer job role in www.seekit.com.au and notice the number of roles appearing for the iPhone.
  • Adding another language to your toolkit makes you more flexible – a downturn in one specific toolset market may not impact another market as seriously.
  • Having iPhone SDK experience or projects on your CV is significant (the above two reasons are pretty good reasons for this).
  • iPhone usage is massive – if you sersiously think you want to develop and publish apps, the appstore provides you the perfect avenue
  • The syntax whilst different is not that hard to learn particularly with some good references.
  • Additional devices (including iPad) are based on the same fundamental development environment.

Next Part 3 – Ok I want to do some iPhone Development what do I need?

Dom

Review: Free iPhone Development Videos – Stanford Uni

http://itunes.stanford.edu/

I started going through these free videos around 3-4 weeks ago. While I am only half way through I am so so impressed, Excellent presentation, Very knowledgeable  lecturers and the lectures move at a great pace. OK, they are really big, but well worth it.

They don’t expect any Objective C background, but a programming background is needed.

Dom

iPhone Project 1

Background

  • This is the first iPhone app I wrote last year
  • There is not a lot of code!!!
  • Best way to do this is just copy the code in XCode as needed and follow the simple instructions below about creating the UI in Interface Builder

Requirements

  • Provide effective light from the iPhone in Darkness
  • On/Off Switch
  • No Fade Out/Dim
Specification
  • See screen below.

  • Label is White when torch is on (Yes this is a very simple torch!)
  • Label is black when torch is off
  • On Application start torch is off
  • Off/On button toggles the light
Test
  • None required at this stage (OK so my objective C needs to get improved before I start building unit tests first). I promise it will happen …. yeah yeah.

Code (Please Note was built with XCODE 3.0.1)

  • iPhone_TorchViewController.h

//  iPhone_TorchViewController.h
//  iPhone Torch
//
//  Created by Dom Millar on 31/08/09.
//  Copyright DOMSCODE 2009. All rights reserved.
//
#import
@interface iPhone_TorchViewController : UIViewController {
IBOutlet UILabel *torchlabel;
}
@property (retain,nonatomic) UILabel *torchlabel;
-(IBAction)buttonPressed:(id)sender;
@end
  • iPhone_TorchViewController.m (Important Bits)

#import “iPhone_TorchViewController.h”

@implementation iPhone_TorchViewController
@synthesize torchlabel;
-(IBAction)buttonPressed:(id)sender
{
NSString *buttonTitle = [sender titleForState:UIControlStateNormal];
if([buttonTitle compare:@”On”] == NSOrderedSame)
{
[torchlabel setBackgroundColor:[UIColor whiteColor]];
}
else
{
[torchlabel setBackgroundColor:[UIColor blackColor]];
}
}

– (void)dealloc {
[torchlabel release];
[super dealloc];
}
Ok so now to hook up to the UI build the code in XCode then open the XIB File. Add the UI elements to the main view like in the above screenshot (1 label with background black, 2 buttons). Then hooking up the outlets and action is easy. Two steps in fact:
1. Option click on the File Owner and drag from the label item to the actual big label on the view.
2. Click on each of the buttons and bring up the button connections. Click on the Touch Up Inside connection and drag that to the File Owner – selecting the button pressed action. Make sure you do this for both buttons.


Issues
  • Should make it a bit more funky (FlashLight – Version 2)
  • Using the title of the buttons to determine which one pressed is a bit dodgy – will see if we can improve this

Summary

Ok so this was an extremely simple applIcation and no test driven development (Curse you Dom) but was achieved in just over an hour and considering this is my first iPhone app – I am pretty happy. In terms of the process, it was all fairly basic but as we consider this series of Projects you’ll see things get more complex.

Dom