Posts

Showing posts with the label iphonedev

Singleton implementation in iOS on Objective-C

Just read this very helpful article on implementing a singleton in iOS. Below is a simple snippet that is thread safe, and is indeed, faster than @synchorize when is executed. +(MyClass *)singleton { static dispatch_once_t pred; static MyClass *shared = nil; dispatch_once(&pred, ^{ shared = [[MyClass alloc] init]; }); return shared; } dispatch_once() function is indeed mentioned in Mac Developer Library that is useful in implementing singletons or global data. Hope you found this helpful.

Creating PVR file using texturetool for iPhone dev

To create a 2 bits per pixel of PVR file as a mipmap, then issue this command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool -e PVRTC --bits-per-pixel-2 -f PVR -o Brick_2.pvr test.png To create a 4 bit, just use  --bits-per-pixel-4 instead of --bits-per-pixel-2. Brick_2.pvr is the output of the file, then test.png is your file that is height and width of your image file are equivalent in numbers of pixels.  If not a mipmap file, then just remove the -m like, /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool -e PVRTC --bits-per-pixel-2 -f PVR -o Brick_2.pvr test.png  Hope this helps.