Blog Archives

Taming Snow Leopard: CGDisplayBestModeForParameters deprecation

We used to have a cool function that would give us the best match for a given resolution, it’s deprecated so let’s work around it. Again Apple failed to provide a documented example so here is one: struct screenMode {

Tagged with: ,
Posted in Code

Taming Snow Leopard: CGDisplayBitsPerPixel deprecation

This one is tricky, since Apple does not provide you with an alternative API. There is one hidden in the header files however, replace: .. bitsPerPixel = CGDisplayBitsPerPixel(CGMainDisplayID()); .. with: — (size_t) displayBitsPerPixel:(CGDirectDisplayID) displayId { CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId); size_t

Tagged with: ,
Posted in Apple, Code

Taming Snow Leopard: stringWithCString: length depreciation

I know this one has been depreciated in 10.5 to but i never found a nice replacement until now: message = [NSString stringWithCString:(buffer + 4) length:(arg2 -5)]; becomes: message = [[[NSString alloc] initWithBytes:(buffer + 4) length:(arg2 -5) encoding:NSASCIIStringEncoding] autorelease];

Tagged with: , ,
Posted in Code

Avoiding the 30 second tcp timeout on iPhone OS

So you are writing the next great iPhone app and you pull some data from a server using TCP, but what happens in the unhappy scenario? TCP timeout takes about 30 seconds, if in the main loop, your app freezes,

Tagged with: , ,
Posted in Code

Playing a sound from Cocoa and setting the balance

The NSSound class is great for playing simple sounds, yet it lacks control over a more flexible way to play sounds. MacTrek plays sounds louder when they happen closer to the players position and balances them left or right when

Tagged with: ,
Posted in Code

Getting the version number from Info.plist in your code

If you are a lazy coder like me (or you don’t like to code version numbers all over the place) you should use the version number that Apple wants you to specify (in the Info.plist file) whenever you need to

Tagged with: , ,
Posted in Code

Feeding NSXMLParser a stream of xml

NSXMLParser is a great parser, but what if you are reading XML from, say a socket. You may not have the complete message right away, and there may be multiple root tags (or you can close and open a socket

Tagged with: , , ,
Posted in Code
Categories