Smarter Software

Using hotspins in your IPhone Application

Posted: June 20th, 2010 | Author: César Naranjo | Filed under: Uncategorized | No Comments »

The procedure is as follows:

  • Main Thread
    • First thing is to start a new Thread, the Background Loader Thread, as soon as the application starts.
    • Load the first screen and anything else you 100% need at startup to have a functional first screen.
    • Whenever something is referenced that may or may not have been loaded check the pointer/reference using a hotspin. If its loaded, great use it as is, otherwise you wait until the pointer is set.
  • Background Loader Thread
    • Load everything you need here: Databases, images, ViewControllers, whatever…

Starting a New Background Loader Thread, start Interface


[NSThread detachNewThreadSelector: @selector(backgroundLoad) toTarget:self withObject: nil];
[window makeKeyAndVisible];

Implementing the Background Loader Thread


- (void) backgroundLoad {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
self.takePicViewController = [[TakePhotoViewController alloc] init];
self.mainInterface = [[MainInterface alloc] initWithNibName: @"MainInterface" bundle:nil];
[pool release];
}

Hotspin on pointers/references


/* Will use the TakePicture View Controller */
- (void) takepicture {
if( takePicViewController == nil) {
//hot spin until value is set
while( takePicViewController == nil ) { [NSThread sleepForTimeInterval: 0.01]; }
}
[self.navigationController presentModalViewController: takePicViewController animated: YES];
}

Other References



Leave a Reply

  • Powered by WP Hashcash