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
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.
from on .
Tutorial
iCodeBlogClass.m:
@implementation iCodeBlogClass @synthesize name; -init { return self; } @end
iCodeBlogGetsClassy.h:
#import "iCodeBlogClass.h"
iCodeBlogGetsClassy.h:
iCodeBlogClass *myNewObject = [[iCodeBlogClass alloc] init]; NSLog(@"%@", myNewObject);
iCodeBlogClass.h:
#import <Foundation/Foundation.h> @interface iCodeBlogClass : NSObject { NSString *name; } @property (nonatomic, retain) NSString *name; @end
iCodeBlogClass.m:
@synthesize name;
iCodeBlogGetsClassy.m:
iCodeBlogClass *myNewObject = [[iCodeBlogClass alloc] init]; [myNewObject setName:@"Collin"]; NSLog(@"%@", [myNewObject name]);
iCodeBlogClass.m:
-initWithName:(NSString *)inputName { self.name = inputName; return self; }
iCodeBlogGetsClassy.m:
iCodeBlogClass *myNewObject = [[iCodeBlogClass alloc] initWithName:@"Collin"];
iCodeBlogGetsClassy.m:
iCodeBlogClass *person1 = [[iCodeBlogClass alloc] initWithName:@"Collin"];
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"];
iCodeBlogGetsClassy.m:
NSMutableArray *myArray = [[NSMutableArray alloc] init];
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];
iCodeBlogGetsClassy.m:
for(iCodeBlogClass *myObject in myArray) { NSLog(@"%@", myObject); }
iCodeBlogGetsClassy.m:
-(NSString *)description { return [NSString stringWithFormat:@"The name of the object is %@", self.name]; }