Learning how to use Xcode  was particularly challenging, especially because it can only run on a Mac OS.  Since I am not yet working on a Mac of my own I had to share someone else’s through the learning process.  The multiple panels seem to be a bit confusing if you’re not used to that environment. However, there are lots of resources online that will help you adjust and learn some of the other components necessary for developing for Mac and iOS.  A great and resource I found was at Cocoa Dev Central.  Here you can find concise tutorials for Cocoa, Objective-C and even basic C for Cocoa.  They also have tutorials for specific coding styles.  This site is great!  Another Gem is a PDF that I found at CocoaLab.  It focuses on using Xcode to program for Mac but the skills can easily be transfered to iOS, just bring in your mobile efficiency considerations.  A common book that I have seen come up a lot on blogs, and even on the desks of some of my colleagues is Apress’s Beginning iPhone Development: Exploring the iPhone SDK.  It averages $26.30 CDN on Amazon.ca.

I also had the pleasure of attending a presentation by Matt Rixx the creator of the Trainyard app for iPhone and he explained that his transfer from AS3 to Objective-C and Cocoa was made much easier by using Cocos2D for iPhone

The learning project that I worked on with a few other students, just to get an understanding of the interface, was to make a datepicker.
In our .h file, we declare myLabel and myPicker so that the interface builder knows to listen for them. We create the UILabel and UIDatePicker and give them their instance names declared earlier.  We also tell the datePicker to listen for the actions of the setDate function.
Here is what our code in the .h file looks like:

//
//  DateViewController.h
//  Date
//
//  Created by Florence Kwok on 11-03-15.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface DateViewController : UIViewController {
	IBOutlet UILabel *myLabel;
	IBOutlet UIDatePicker *myPicker;
}
@property (nonatomic, retain) IBOutlet UILabel *myLabel;
@property (nonatomic, retain) IBOutlet UIDatePicker *myPicker;
- (IBAction)setDate: (id)sender;
@end

In our .m file, we synthesize myLabel to myPicker.  In the setDate function we assign myPicker.date to myDate2, then make the date (myDate2.description) appear in the myLabel text field.  When a date is selected from the datePicker it is assigned to myDate2 and subsequently inserted into myLabel and can be viewed and used for submission later.
Here is the code for our .m file:

//  DateViewController.m
//  Date
//
//  Created by Florence Kwok on 11-03-15.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "DateViewController.h"

@implementation DateViewController
@synthesize myLabel, myPicker;

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

	NSLog(@"Hi from IMM");
}
- (IBAction)setDate: (id)sender{

	//myLabel.text= myDate;

	NSDate *myDate2 = myPicker.date;

	myLabel.text= myDate2.description;

	NSString *myDate = myDate2.description;
	NSLog(@"Date Picked = %@", myDate);
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

	// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}
- (void)dealloc {
    [super dealloc];
}
@end

As you can see, the syntax has a similar feel to many of the OOP Ecma scripting languages we may be used to, and it is definitely helpful is you understand a script like  ActionScript 3, but it can sometime take up to 10x the amount of lines to make the same thing in Objective-C that you might be used to in AS3.  However, it is much more efficient with memory management and has better garbage collection.

About these ads