Friday, February 4, 2011

Objective-C Semi-Singleton Class

Sometimes when building an iOS application, you will have a class you will want to access from anywhere. Such as, a controller with any number of child controllers (navigation, tab, etc.) and some of them need simple access back to the root controller.

Apple provides their own solution to creating a full-blown singleton class, but this can be a daunting task for a simple need. A semi-singleton is much easier to create but has two caveats:

1) semi-singletons only work if there is ever only one instance of the class
2) the singleton cannot be used to initialize itself

So, here is how to make a simple "HelloWorld" class into a semi-singleton.

In the HelloWorld.m file, create a static property to hold the singleton instance:


// put just after @implementation line
static HelloWorld* helloWorldInstance;


in the init method, assign the instance (self) to the static property:


-(id) init
{
if ((self = [super init]))
{
// assign the semi-singleton
helloWorldInstance = self;
// do other init stuff here ...
}
return self;
}


create the shared static method for accessing the semi-singleton:


+(HelloWorld*) sharedInstance {
return helloWorldInstance;
}


Lastly, be sure to dealloc the property to avoid crashes:


-(void) dealloc
{
helloWorldInstance = nil;
[super dealloc];
}


And now from any class, we can access a pointer to the instance:


#import HelloWorld.h

HelloWorld *helloWorld = [HelloWorld sharedInstance];


And there you have it. Thanks to Steffen Itterheim and his book about cocos2d programming for the original tip!

Wednesday, December 22, 2010

Apple TV: A perfect replacement for digital picture frames

I never really liked the idea of digital picture frames. At first they were overpriced and very poor picture quality. Now they are getting better with higher resolution, more options for getting photos to them (SD card slot, USB, Wifi), but there is still a problem with them. They are single purpose devices, and Grandma doesn't want to fidget with loading images.

Along comes the AppleTV (Gen 2) from Apple for $99. A black hockey puck with one HDMI cable, power cable, and very simple remote. Now here is a perfect replacement for digital picture frames. I have a MobileMe account where I keep all of my photo albums up to date. Now Grandma can flip on her AppleTV and view all the new photo albums I put onto MobileMe with no work on her part. The slideshow viewer is absolutely gorgeous, and quite configurable. Now Grandma can view the photos on her TV in a much larger format instead of a dinky digital picture frame, and I manage the albums.

Not only is the AppleTV a good slideshow viewer, but you can watch Netflix, rent movies and tv shows, use airplay to push content to the TV from another iOS device, and you know an app store is in the works... but the picture viewer alone is worth the price to purchase for Grandma.

Although MobileMe is $99 bucks a year, it's well worth it for the automated syncing of addresses, bookmarks, passwords, etc. between all your Mac devices. And of course, simple management of shared photo/video galleries for the family.

So if you plan on getting a digital picture frame for a gift, spend the dollars on an AppleTV instead. It's a much better investment.

Tuesday, November 9, 2010

PHP5 References Explained Visually

If you are having trouble wrapping your head around PHP5 References, especially how objects are now handled, have a look at this handy guide.

Wednesday, September 8, 2010

Compress/GZip CSS the easy way with Apache and PHP

So you need a way to automatically compress CSS and GZIP to the browser without any complicated work on the development end? This script is for you.


Just access the .css files from the browser as per usual.

Monday, July 19, 2010

First thoughts on Droid

So my wife got a Droid. Not because she even wanted one, but because she was tired of messaging on her ancient Motorola Razor. She was going to get a non-droid phone on the cheapo data plan, but she eventually settled on a Droid, mainly for me to tinker with.

Well, my first impressions are not so good. I've been using the iPhone for a few years, and the inconsistency on this phone just baffles me. The first thing I wanted to do was unlock the phone. I couldn't even figure that out, until I saw the sales guy slide his finger over the green button on the screen. There was absolutely no visual cue of how that worked. Then as I started browsing through the pages of icons, it really reminded me of the smartphones I tried before the iPhone was around: inconsistent and clumsy.

I'm not even going to discuss features, because to me they really don't matter as much as the user experience. Bottom line, the user experience has to be good, and Apple has nailed that down. I could go on, but I found a good article that pretty much sums it all up.

Thursday, June 10, 2010

Remove the google background image

It seems Google has decided to put a background image on its home page, without your consent. It will probably go away by tomorrow, but you can get rid of it by using the secure version of the google site (and consequently, get your search results securely.)


That will get rid of the annoying background image, at least for now.

Monday, May 10, 2010

Everything-in-a-box MAME Arcade Cabinet

This is a project started around 2004, and sat for 5 years, then I finally finished up the cabinet this past year. So what is it? MAME (Multi Arcade Machine Emulator) is an arcade emulation system. The machine can play over 6,000 old-school arcade games (Pac-Man, Donkey Kong, Centipede... yeah all of them) true to their original form, and also many retro game consoles such as Atari 2600, Nintendo, Super Nintendo, Nintendo 64, SEGA Genesis, Playstation, etc.





























This is a custom built cabinet (started with a plan found on the internet, I forget where) and custom design control panel. Wells Garner 27" monitor with VGA out, trackball/spinner, 4 8-way joys. Happ arcade controls, spinner, keyboard, trackball boards and Ultimarc Opti-PAC, ArcadeVGA, IPac 4 Interface, LED Harness, HAPP 3" trackball. The joy in the middle is 4-way, with asteroid button layout around it. Buttons on the sides for pinball simulators. It's a beast, and a blast to play. Panel disconnects with a couple latches. Everything starts up/shuts down with one button (computer, marquee, monitor, etc.)