Cocoa Quickies

Well since I am working a lot with cocoa lately, I came across two things that you may like. Let’s start…

1) Have you every tried to print out or display the percentage ‘%’ sign with Cocoa? ;) I haven’t and it was quite tricky, although after 20 minutes (hehe) I found a way to do it… so here we go:

NSLog(@"Here is my percentage sing %%");

2) I wanted to implement a method that will go through all my files in my home directory. I couldn’t believe how easy that was. I have done it in C before and it was really really hard! Thanks God, cocoa does it with a few lines:

NSString *path = [NSString stringWithFormat:@”%@/”,NSHomeDirectory()]; 
NSFileManager *manager = [NSFileManager defaultManager];
NSDirectoryEnumerator *dirEnum = [manager enumeratorAtPath:path];
NSString *file;
 
while (file = [dirEnum nextObject]){
NSLog(@”%@”,file );
}

BTW… NSThread rocks!!!

Thursday, February 18, 2010   ()