
From the WWDC 2009
#import <
#import <
void PrintPathInfo() {
// Code from path info section here
NSLog(@"Printing Path");
NSString *path = @"~";
NSString *adjusted=[path stringByExpandingTildeInPath];
NSLog(adjusted);
NSLog([NSString stringWithFormat:@"My home folder is at '%@'",adjusted]);
NSArray *pathComponents = [adjusted pathComponents];
NSLog(@"Path Components Next");
for (NSString *pc in pathComponents) {
NSLog(pc);
}
}
void PrintProcessInfo() {
// Code from path info section here
NSLog(@"Printing PrintProcessInfo");
NSString *processName = [[NSProcessInfo processInfo] processName];
int processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
NSString *answer = [NSString stringWithFormat:@"Process Name: %@ Process ID: %d", processName, processIdentifier];
NSLog(answer);
//NSLog(processName);
}
void PrintBookmarkInfo() {
NSLog(@"PrintBookmarkInfo()");
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:5];
[dict setObject: [NSURL URLWithString:@"http://www.stanford.edu"] forKey: @"Stanford University"];
[dict setObject:[NSURL URLWithString:@"http://www.apple.com"] forKey: @"Apple"];
[dict setObject: [NSURL URLWithString:@"http://cs193p.stanford.edu"] forKey:@"CS193P"] ;
[dict setObject: [NSURL URLWithString:@"http://itunes.stanford.edu"] forKey: @"Stanford on iTunes U"];
[dict setObject: [NSURL URLWithString:@"http://stanfordshop.com"] forKey:@"Stanford Mall"] ;
NSArray *keys;
keys = [dict allKeys];
for(NSString *key in keys) {
if([key hasPrefix:@"Stanford"]) {
NSURL *url = [dict objectForKey:key];
NSLog([NSString stringWithFormat:@"Key: %@ URL: %@",key,url]);
}
}
}
void PrintIntrospectionInfo() {
NSLog(@"PrintIntrospectionInfo");
NSMutableArray *arr = [NSMutableArray arrayWithCapacity:4];
[arr addObject:@"John G. Kroubalkian"];
[arr addObject:@"2John G. Kroubalkian"];
[arr addObject:@"3John G. Kroubalkian"];
[arr addObject:@"4John G. Kroubalkian"];
int count = [arr count];
for (int i = 0 ; i <>
NSObject *obj = [arr objectAtIndex:i];
//NSLog([NSString stringWithFormat:@"%@",obj]);
Class claz = [obj class];
NSString *className = [claz description];
NSLog([NSString stringWithFormat:@"Class name: %@",className]);
if([[arr objectAtIndex:i] isMemberOfClass:[NSString class]]){
NSLog(@"Is Member of NSString: YES");
}else{
NSLog(@"Is Member of NSString: NO");
}
if([[arr objectAtIndex:i] isKindOfClass:[NSString class]]){
NSLog(@"Is Kind of NSString: YES");
}else{
NSLog(@"Is Kind of NSString: NO");
}
//NSLog([NSString stringWithFormat: @"Is Member of NSString: %@",memberOfClassNsString]);
SEL sel = @selector(lowercaseString);
if ([obj respondsToSelector:sel]) {
NSLog(@"Responds to lowercaseString: YES");
NSString *res = [NSString stringWithFormat:@"lowercaseString is: %@", [obj performSelector:sel withObject:obj]];
NSLog(res);
}else{
NSLog(@"Responds to lowercaseString: NO");
}
}
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
PrintPathInfo();
PrintProcessInfo();
PrintBookmarkInfo();
PrintIntrospectionInfo();
[pool drain];
}