Assignment 1B – CS193P @ Stanford U – iPhone Dev
June 16th, 2009
Je suis en train de faire un cours sur le développement d’application pour le iPhone. Il y a présentement un cours disponible sur le site de l’Université Stanford (itunes.stanford.edu) qui est bien, Rechercher: “Stanford CS193P” sur Google. Bref, je fais également les devoirs qui vont avec le cours. Voici donc le résultat du devoir “Assignment-1B”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | #import <Foundation/Foundation.h> void PrintPathInfo() { // Section 1 NSString *aString = @"~"; aString = [aString stringByExpandingTildeInPath]; NSLog(@"My home folder is at %@", aString); //NSArray *pathComponents = aString; NSArray *pathComponents = [aString componentsSeparatedByString:@"/"]; //pathComponents = [aString stringsByAppendingPaths:(NSArray *)pathComponents]; NSLog([pathComponents description]); } void PrintProcessInfo(){ // Section 2 NSString *processName = [[NSProcessInfo processInfo] processName]; int processId = [[NSProcessInfo processInfo] processIdentifier]; NSLog(@"Process Name: '%@' Process ID: '%i'", processName, processId); } void PrintBookmarkInfo(){ // Section 3 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [dictionary setObject:[NSURL URLWithString:@"http://www.standford.edu"] forKey:@"Stanford University"]; [dictionary setObject:[NSURL URLWithString:@"http://www.apple.com"] forKey:@"Apple"]; [dictionary setObject:[NSURL URLWithString:@"http://cs193p.stanford.edu"] forKey:@"CS193P"]; [dictionary setObject:[NSURL URLWithString:@"http://itunes.stanford.edu"] forKey:@"Stanford on iTunes U"]; [dictionary setObject:[NSURL URLWithString:@"http://www.stanfordmall.com"] forKey:@"Stanford Mall"]; //NSLog([dictionary description]); for (id key in dictionary) { if([key hasPrefix:@"Stanford"]){ NSLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]); } } //NSString *key; //for(key in dictionary){ // NSLog(@"key: %@, value: %@", key, [dictionary valueForKey:key]); //} } void PrintIntrospectionInfo() { // Section 4 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [dictionary setObject:[NSURL URLWithString:@"http://www.standford.edu"] forKey:@"Stanford University"]; [dictionary setObject:[NSURL URLWithString:@"http://www.apple.com"] forKey:@"Apple"]; [dictionary setObject:[NSURL URLWithString:@"http://cs193p.stanford.edu"] forKey:@"CS193P"]; [dictionary setObject:[NSURL URLWithString:@"http://itunes.stanford.edu"] forKey:@"Stanford on iTunes U"]; [dictionary setObject:[NSURL URLWithString:@"http://www.stanfordmall.com"] forKey:@"Stanford Mall"]; NSString *stringHello = @"hello world"; NSURL *appleURL = @"http://www.apple.com"; NSMutableArray *array = [NSMutableArray array]; [array addObject:stringHello]; [array addObject:appleURL]; [array addObject:dictionary]; for (int i=0; i<3;i++) { NSLog(@"================================================="); NSLog(@"Class name: %@", [[array objectAtIndex:i] class]); if([[array objectAtIndex:i] isMemberOfClass:[NSString class]]){ NSLog(@"Is Member of NSString: YES"); }else{ NSLog(@"Is Member of NSString: NO"); } if([[array objectAtIndex:i] isKindOfClass:[NSString class]]){ NSLog(@"Is Kind of NSString: YES"); }else{ NSLog(@"Is Kind of NSString: NO"); } SEL sel = @selector(lowercaseString); if ([[array objectAtIndex:i] respondsToSelector:sel]) { NSLog(@"Responds to lowercaseString: YES"); NSString *res = [NSString stringWithFormat:@"lowercaseString is: %@", [[array objectAtIndex:i] performSelector:sel withObject:[array objectAtIndex:i]]]; NSLog(res); }else{ NSLog(@"Responds to lowercaseString: NO"); } } } int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; PrintPathInfo(); // Section 1 PrintProcessInfo(); // Section 2 PrintBookmarkInfo(); // Section 3 PrintIntrospectionInfo(); // Section 4 [pool release]; return 0; } |