Här är koden
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
// Sample function for one section, use a similar function per section
void PrintPathInfo() {
NSLog(@ "Uppgift 1B Sektion 1: ");
NSLog(@);
NSString *path = @"~";
path = [path stringByExpandingTildeInPath]; //Omvandlar relativa sökvägen tilde till absolut sökväg.
NSLog(@"My home folder is at %@", path);
NSArray *pathComponents = [path pathComponents]; //Plockar ut komponenterna som ingår i sökvägen och lägger dom i en array.
for(NSString *path in pathComponents){ //Plockar ut varje del i arrayen.686989<ol>
NSLog([path description]);
}
}
void PrintProcessInfo() {
NSLog(@ "Uppgift 1B Sektion 2: ");
NSLog(@);
NSString *processName = [[NSProcessInfo processInfo] processName];
NSString *processId = [NSString stringWithFormat:@"%d",[[NSProcessInfo processInfo] processIdentifier]];
NSLog(@"Process name: %@ Process id: %@", processName, processId);
}
void PrintBookmarkInfo() {
NSLog(@ "Uppgift 1B Sektion 3: ");
NSLog(@);
NSDictionary *URLdictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSURL URLWithString: @"http://www.stanford.edu"], @Stanford University, //URLWithString är en klassmetod, inte instansmetod.
[NSURL URLWithString: @"http://www.apple.com"], @Apple,
[NSURL URLWithString: @"http:/cs193p.stanford.edu"], @CS193P,
[NSURL URLWithString: @"http://itunes.stanford.edu"], @Stanford on iTunes U,
[NSURL URLWithString: @"http://stanfordshop.com"], @"stanfordshop.com",
nil];
for (id key in URLdictionary) {
if ([key hasPrefix:@Stanford])
NSLog(@"Key: %@ URL: %@", key, [URLdictionary objectForKey:key]);
}
}
void PrintIntrospectionInfo() {
NSURL *anURLobject =[NSURL URLWithString: @"http://www.stanford.edu"];
NSDictionary *URLdictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSURL URLWithString: @"http://www.stanford.edu"], @Stanford University, //URLWithString är en klassmetod, inte instansmetod.
[NSURL URLWithString: @"http://www.apple.com"], @Apple,
[NSURL URLWithString: @"http:/cs193p.stanford.edu"], @CS193P,
[NSURL URLWithString: @"http://itunes.stanford.edu"], @Stanford on iTunes U,
[NSURL URLWithString: @"http://stanfordshop.com"], @"stanfordshop.com",
nil];
NSString *aString = @Hejsan;
NSMutableArray *array = [NSMutableArray array];
[array addObject:anURLobject];
[array addObject:URLdictionary];
[array addObject:aString];
//NSLog ([URLdictionary description]);
for (id test in array) {
NSLog(@"Class name: %@", [test className]); //Klassnamn
if ([test isMemberOfClass:[NSString class]])
NSLog(@"Is member of NSString: YES");
else
NSLog(@"Is member, of NSString: NO");
if ([test isKindOfClass:[NSString class]]) //Är det denna sortens klass?
NSLog(@"Is Kind of NSString: YES");
else
NSLog(@"Is Kind of NSString: NO");
if ([test respondsToSelector: @selector (lowercaseString)]) {
NSLog(@"Responds to lowercaseString: YES");
NSString *lowCase = [test lowercaseString];
NSLog(@"lowercaseString is: %@", lowCase);
}
else
NSLog(@"Responds to lowercaseString: NO");
NSLog(@"***************************************************");
}
}
void PrintPolygonInfo() {
NSMutableArray *shapes = [[NSMutableArray alloc] init];
PolygonShape *shape4 = [[PolygonShape alloc] initWithNumberOfSides:8 minimumNumberOfSides:2 maximumNumberOfSides:10];
NSLog(@"Shape4's retain count = %d", [shape4 retainCount]); // retain count = 1
[shapes addObject:shape4];
NSLog(@"%@",shape4);
NSLog(@"Shape4's retain count = %d", [shape4 retainCount]); // retain count = 2
[shape4 release];
NSLog(@"Shape4's retain count = %d", [shape4 retainCount]);
//[shape4 release];
}
int main (int argc, const char * argv[]) {
//#import "PylogonShape.h"
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
PrintPathInfo(); // Section 1
NSLog(@);
NSLog(@);
PrintProcessInfo(); // Section 2
NSLog(@);
NSLog(@);
PrintBookmarkInfo(); // Section 3
NSLog(@);
NSLog(@);
PrintIntrospectionInfo(); // Section 4
NSLog(@);
NSLog(@);
PrintPolygonInfo(); // Section 6
NSLog(@);
NSLog(@);
[pool release];
return 0;
}