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”.
#import
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;
}