I skipped first chapter, because it is just brief about iPhone programming (cocoa framework), and there are not much stuff to think. I can finish first assignment just followed given guide. Anyone can do it ;-)

Actually i already study about objective-c a few months back. but i cannot study with concentration, so i almost forgot everything. This class  reminds me, and i can remember what i studied ago.  And, i can use some unfamiliar class like NSEnumerator, NSURL, NSProcessInfo, so on. 

Here is assgnment 1-B.  Because these are my private, there is no comment ;-)

void PrintPathInfo()


NSString *path = @"~";

path = [path stringByExpandingTildeInPath];

NSLog(@"My home folder is %@", path);

NSArray *pathCompArray = [path pathComponents];

NSEnumerator *foreachEnum = [pathCompArray objectEnumerator];

NSString* item;

while (item = [foreachEnum nextObject])


NSLog(@"%@\n", item);



void PrintProcessInfo()


NSString *processName = [[NSProcessInfo processInfo] processName];

int processId = [[NSProcessInfo processInfo] processIdentifier];

NSString* outputStr = [NSString stringWithFormat: @"Process Name : %@, Process ID : '%d'",

  processName, processId];



void PrintBookmarkInfo()


NSArray *keyArray = [NSArray arrayWithObjects: @"Stanford University"



@"Stanford on iTunes U",

@"Stanford Mall", nil];

NSArray *strValueArray = [NSArray arrayWithObjects: @"http://www.stanford.edu",




  @"stanfordshop.com", nil];

NSMutableDictionary *bookMark = [NSMutableDictionary dictionaryWithCapacity: 5];

// c-style iteration

for (int nIdx = 0; nIdx < [keyArray count]; nIdx++)


[bookMark setValue: [NSURL URLWithString: [strValueArray objectAtIndex: nIdx]] forKey: [keyArray objectAtIndex: nIdx]]; 


NSEnumerator *keyEnum = [bookMark keyEnumerator];

NSString* key;

// Iteration with enumerator

while (key = [keyEnum nextObject])


NSURL *url = [bookMark objectForKey: key];

NSLog(@"Key : '%@' URL : '%@'\n", key, [url relativeString]);



void PrintIntrospectionInfo()


NSMutableArray *anyObjArray = [NSMutableArray arrayWithCapacity: 5];

NSString *string = [NSString stringWithFormat: @"Hello, Mac!!!!"];

NSURL *url = [NSURL URLWithString: @"http://www.apple.com"];

NSProcessInfo *processInfo = [NSProcessInfo processInfo];

NSDictionary *dic = [NSDictionary dictionary];

[anyObjArray addObject: string];

[anyObjArray addObject: url];

[anyObjArray addObject: processInfo];

[anyObjArray addObject: dic];

NSEnumerator *objEnum = [anyObjArray objectEnumerator];

NSObject *obj;

while (obj = [objEnum nextObject])


NSLog(@"Class Name : %@\n", [obj className]);

NSLog(@"Is member of NSString : %@", [obj isMemberOfClass: [NSString class]] ? @"YES" : @"NO");

NSLog(@"Is kind of NSString : %@", [obj isKindOfClass: [NSString class]] ? @"YES" : @"NO");

SEL sel = @selector(lowercaseString);

if ([obj respondsToSelector: sel] == YES)


NSLog(@"lowercaseString is '%@'", [obj performSelector: sel]);




NSLog(@"Responds to lowercaseString : NO");




[anyObjArray removeAllObjects];

[anyObjArray release];


Posted by yunseong