Objective-C

From Shiftyjelly

Jump to: navigation, search

Contents

Basics

iPhone Basics - Phil's path to iPhone coding enlightenment.
iPhone Cheat Sheet - Phil's lazy cheat sheat

Links

NSDateTimeFormats:
http://unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns

Apple iPhone Dev Center
http://developer.apple.com/iphone/

Date Picker Control
http://iphonedevelopment.blogspot.com/2009/01/better-generic-date-picker.html

Graphing Library
http://code.google.com/p/core-plot/

Threading

Good article on how to thread your UI: [1]

The basics of it are spawn a new thread:

[NSThread detachNewThreadSelector:@selector(_loadWebImagesOnThreadForRadar:) toTarget:self withObject:radarRequested];

Do work in the thread, and post notifications back to your class (Note the auto release pool, you need to create on of these for the thread, and release it at the end):

-(void)_loadWebImagesOnThreadForRadar:(id)param{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	SingleRadarInfo *radarRequested = param;

	...do stuff
	
	[[NSNotificationCenter defaultCenter] postNotificationName:@"RadarImagesLoaded" object:[radarImages autorelease]];
	[pool release];
}

Finally you handle the notification back in your main class, and if you need to update UI components, you use the following:

-(void)_loadingProgressUpdate:(NSNotification *) notification{
	NSString *value = [notification object];
	progressBar.progress = [value floatValue];
	[progressBar performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:NULL waitUntilDone:YES];
}

Finding Memory Leaks

Run 'Build And Analyze' from the project menu in Xcode

The other way is to use Apple's built in leaks too. Just go to your project, and run it using leaks. Run the app as you would normally, and it will show you anything it thinks to be leaking.

Listening for app events

//listen for when the app is about to be backgrounded
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_enterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];

//listen for when the app comes back into the foreground
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_enterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
Personal tools
Namespaces
Variants
Actions
Reference
Navigation
Toolbox