Email syntax validation -iPhone Programming

Understanding that iPhone SDK dont support NSPredicate which is there for MAC Apps SDK i wrote an Utility Method to do a syntax validation of email.


if( (0 != [email rangeOfString:@"@"].length) &&  (0 != [email rangeOfString:@"."].length) )
		NSMutableCharacterSet *invalidCharSet = [[[[NSCharacterSet alphanumericCharacterSet] invertedSet]mutableCopy]autorelease];
		[invalidCharSet removeCharactersInString:@"_-"];

		NSRange range1 = [email rangeOfString:@"@" options:NSCaseInsensitiveSearch];

		// If username part contains any character other than "."  "_" "-"

		NSString *usernamePart = [email substringToIndex:range1.location];
		NSArray *stringsArray1 = [usernamePart componentsSeparatedByString:@"."];
		for (NSString *string in stringsArray1) {
			NSRange rangeOfInavlidChars=[string rangeOfCharacterFromSet: invalidCharSet];
			if(rangeOfInavlidChars.length !=0 || [string isEqualToString:@""])
				return NO;

		NSString *domainPart = [email substringFromIndex:range1.location+1];
		NSArray *stringsArray2 = [domainPart componentsSeparatedByString:@"."];

		for (NSString *string in stringsArray2) {
			NSRange rangeOfInavlidChars=[string rangeOfCharacterFromSet:invalidCharSet];
			if(rangeOfInavlidChars.length !=0 || [string isEqualToString:@""])
				return NO;

		return YES;
	else // no '@' or '.' present
		return NO;



I started incorporating the accelerometer events in my app.
My app is quite similar to the
SampleDrillDown (one of the example app provided by apple). I am having menus in my app, which are like
Category -> Sub category -> final item page

All the above navigations are through pushing view controllers.

I am trying to add accelerometer delegate methods to select any of the cell in tableview on tilting the device up or down, moreover tilting right will push the view controller and tilting left will pop.

  • My concern is about how to set delegate for UIAccelerometer for such an implementation? 
  • Also the method like “selectCellAtIndexPath” will simply highlight the cell, so i want to call UITableView’s delegate method  “didSelectRowAtIndexPath” explicitly. ( to push corresponding viewcontroller)

I don’t think there is much harm in doing so..
But i would like to hear from someone who implemented this in much better way…

Checkout an abstract sample code

Conditional compilation – easy way !!

I achieved this by adding a #define in .pch file for each project.

and do #import based on that definition using #ifdef

This is the pretty cool and easy way  if your are sharing single source code set across multiple target/build/project

Just make use of different .pch file for different builds.

You want to create <n>  number of .pch file for <n> targets. Assign corresponding  .pch file for each target’s info