Tuesday, May 01, 2007

Wahoo! Finals are over! :: Book & QuietLog

Finals are finally done with, all my big projects are over with, all my homework is turned in I can refocus all my energy again!!! :D Don't' get me wrong I like learning in detail about algorithms and some finite math, but after a few months of doing big projects it gets tiring very fast. Most importantly im gonna get back on track on writing here regularly. Advanced Cocoa Book I don't usually give my thumbs up to something that I haven't completely gone through yet, but i've gotten about halfway through Aaron Hillegass and Mark Dalrymple's Advanced Mac OS X Programming and already I love the book. It's the first Mac Developer book I've personally read that doesn't treat you like a complete newbie to Macintosh Development and instead shows in great detail how Mac OS X works and will even show you some nice unix tools you didn't know existed that can actually be of great help to you. The book covers various topics such as Multi-threading, Interprocess Communication, Networking, Performance Tuning, kqueues, Bonjour, Authentication, Keychain, GCC, GDB, memory management, etc. Really this book is a fantastic book that I would really recommend to all Mac developers out there. It starts you right off showing you in detail how you can work with gcc then goes into libraries, gdb, memory and more. Thank you Aaron and Mark for putting together such a great book! QuietLog I also wanted to share something with you that I posted in my personal blog a while ago and recently I've learned it's value as I begin to really use it in my serious projects. And I found it on Borkwares quickies site. To be honest I'm not sure how I came across Borkwares quickies site but I'm glad I found it, if you haven't been there take a minute and open up another tab and go there after you see this. One problem I have with NSLog is that it can provide you with a ton of information when you just want to print simple statements. Printf can be useful, but it can't handle Objective-C objects. So that's what QuietLog is for...

void QuietLog (NSString *format, ...) { // get a reference to the arguments on the stack that follow // the format paramter va_list argList; va_start (argList, format); // NSString luckily provides us with this handy method which // will do all the work for us, including %@ NSString *string; string = [[NSString alloc] initWithFormat: format arguments: argList]; va_end (argList); // send it to standard out. printf ("%s\n", [string UTF8String]); [string release]; } // QuietLog
It's a nice method that can handle objective-c objects and print them out in a simple manner, you won't notice any difference except the all the preceeding junk you didn't care about. To implement this in a way you can use throughout all your project you just need to do it like so... QuietLog.h
#import < Cocoa/Cocoa.h > extern void QuietLog (NSString *format, ...);
QuietLog.m
#import "QuietLog.h" void QuietLog (NSString *format, ...) { // get a reference to the arguments on the stack that follow // the format paramter va_list argList; va_start (argList, format); // NSString luckily provides us with this handy method which // will do all the work for us, including %@ NSString *string; string = [[NSString alloc] initWithFormat: format arguments: argList]; va_end (argList); // send it to standard out. printf ("%s\n", [string UTF8String]); [string release]; }
And then import the QuietLog.h anywhere you actually need it and now you have a nice utility to use in your projects. If your curious about the va_* stuff you can find more info here http://www.delorie.com/gnu/docs/glibc/libc_675.html, the va_list is a type that's part of the GNU C Library for obtaining info about the arguments used in calling the method. I could go on more about this but you can read the GNU page if you want to know more about it. Thats it for now. I have some free time now that I have roughly a month free from school and can work on my new pet project RedFlag (hopefully to be a great and elegant Del.icio.us client) and post some more great stuff I've discovered. See you soon! :D

No comments:

 
...