Objective C 2.0: An Intro – Part 2

June 29th, 2009 Posted by: - posted under:Tutorials

Introduction

Hello everyone, welcome to my fourth screeencast. This is the second in my series introducing readers to Objective C. Let’s dive in.

Skill Level Beginner

Source Code

Available Here

Screencast

I film myself coding out the entire sample project for each post. I personally think going through the Screencast is the best way to learn. But feel free to look through the slides and text if that suites you better.

iCodeBlog Tutorial: Objective C 2.0 An Intro Part 2 from Collin Ruffenach on Vimeo.

Tutorial

objectivec20anintropt2001

objectivec20anintropt2002

objectivec20anintropt2003

objectivec20anintropt2004

objectivec20anintropt2005

objectivec20anintropt2006

objectivec20anintropt2007

objectivec20anintropt2008

objectivec20anintropt2009

objectivec20anintropt2010

objectivec20anintropt2011

objectivec20anintropt2012

iCodeBlogClass.m:

@implementation iCodeBlogClass

@synthesize name;

-init
{
	return self;
}

@end

objectivec20anintropt2013

objectivec20anintropt2014

objectivec20anintropt2015

iCodeBlogGetsClassy.h:

#import "iCodeBlogClass.h"

objectivec20anintropt2016

objectivec20anintropt2013

objectivec20anintropt2014

objectivec20anintropt2015

iCodeBlogGetsClassy.h:

iCodeBlogClass *myNewObject = [[iCodeBlogClass alloc] init];
NSLog(@"%@", myNewObject);

objectivec20anintropt2017

objectivec20anintropt2018

objectivec20anintropt2019

objectivec20anintropt2020

objectivec20anintropt2021

objectivec20anintropt2020

objectivec20anintropt2023

objectivec20anintropt2024

iCodeBlogClass.h:

#import <Foundation/Foundation.h>

@interface iCodeBlogClass : NSObject
{
	NSString *name;
}

@property (nonatomic, retain) NSString *name;

@end

objectivec20anintropt2025

iCodeBlogClass.m:

@synthesize name;

objectivec20anintropt2026

objectivec20anintropt2027

iCodeBlogGetsClassy.m:

iCodeBlogClass *myNewObject = [[iCodeBlogClass alloc] init];
[myNewObject setName:@"Collin"];

NSLog(@"%@", [myNewObject name]);

objectivec20anintropt2028

objectivec20anintropt2029

objectivec20anintropt2030

iCodeBlogClass.m:

-initWithName:(NSString *)inputName
{
     self.name = inputName;
     return self;
}

objectivec20anintropt2031

objectivec20anintropt2032

iCodeBlogGetsClassy.m:

iCodeBlogClass *myNewObject = [[iCodeBlogClass alloc] initWithName:@"Collin"];

objectivec20anintropt2033

objectivec20anintropt2034

objectivec20anintropt2035

objectivec20anintropt2036

objectivec20anintropt2037

objectivec20anintropt2038

objectivec20anintropt2039

iCodeBlogGetsClassy.m:

iCodeBlogClass *person1 = [[iCodeBlogClass alloc] initWithName:@"Collin"];

objectivec20anintropt2040

iCodeBlogGetsClassy.m:

	iCodeBlogClass *person1 = [[iCodeBlogClass alloc] initWithName:@"Collin"];
	iCodeBlogClass *person2 = [[iCodeBlogClass alloc] initWithName:@"Martin"];
	iCodeBlogClass *person3 = [[iCodeBlogClass alloc] initWithName:@"vtsib"];
	iCodeBlogClass *person4 = [[iCodeBlogClass alloc] initWithName:@"AppStoreMod"];
	iCodeBlogClass *person5 = [[iCodeBlogClass alloc] initWithName:@"Matt"];
	iCodeBlogClass *person6 = [[iCodeBlogClass alloc] initWithName:@"Brendan"];
	iCodeBlogClass *person7 = [[iCodeBlogClass alloc] initWithName:@"Geoff"];
	iCodeBlogClass *person8 = [[iCodeBlogClass alloc] initWithName:@"RobotGrrl"];
	iCodeBlogClass *person9 = [[iCodeBlogClass alloc] initWithName:@"brandon"];
	iCodeBlogClass *person10 = [[iCodeBlogClass alloc] initWithName:@"Aaron"];
	iCodeBlogClass *person11 = [[iCodeBlogClass alloc] initWithName:@"Brian"];
	iCodeBlogClass *person12 = [[iCodeBlogClass alloc] initWithName:@"Fernando"];
	iCodeBlogClass *person13 = [[iCodeBlogClass alloc] initWithName:@"Chad"];

objectivec20anintropt2041

iCodeBlogGetsClassy.m:

NSMutableArray *myArray = [[NSMutableArray alloc] init];

objectivec20anintropt2042

iCodeBlogGetsClassy.m:

	[myArray addObject:person1];
	[myArray addObject:person2];
	[myArray addObject:person3];
	[myArray addObject:person4];
	[myArray addObject:person5];
	[myArray addObject:person6];
	[myArray addObject:person7];
	[myArray addObject:person8];
	[myArray addObject:person9];
	[myArray addObject:person10];
	[myArray addObject:person11];
	[myArray addObject:person12];
	[myArray addObject:person13];

objectivec20anintropt2043

objectivec20anintropt2044

objectivec20anintropt2045

iCodeBlogGetsClassy.m:

	for(iCodeBlogClass *myObject in myArray)
	{
		NSLog(@"%@", myObject);
	}

objectivec20anintropt2046

objectivec20anintropt2047

objectivec20anintropt2048

iCodeBlogGetsClassy.m:

-(NSString *)description
{
	return [NSString stringWithFormat:@"The name of the object is %@", self.name];
}
objectivec20anintropt2049