NSLog – debugging tool

Came across this useful blog that shows you can override the description method of an object and when you display object using NSLog it will show the extra info you’ve included!

iPhone Configuration Utility

Link to the iPhone Configuration Utility

Validate email address on the iPhone

Here is some simple code that allows you to validate email addresses that have been entered by a user on an iPhone. It does use NSPredicate, which is only available on OS 3.0 and above;

	NSString *email = [newEmailAddress.text lowercaseString];
	NSString *emailRegEx =
    @"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
    @"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
    @"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
    @"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
    @"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
    @"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
    @"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
	
	NSPredicate *regExPredicate =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
	BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:email];
	if(!myStringMatchesRegEx){
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Correct Email" message:@"Please enter a valid email address" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
		[alert show];
		[alert release];
	}

The code is based on this article which describes this in a lot more detail.

switch case compile error

If you are using a switch case similar to the one below:

	switch (row) {
		case 0:
			int i;
			i = row + 10;
			NSLog(@"%d",i);
			break;
		default:
			break;
	}

You’ll get a compile error, “Expected expression before ‘int’”. If you need to declare a variable enclose the code in curly braces and the error goes away….

	switch (row) {
		case 0:
		{
			int i;
			i = row + 10;
			NSLog(@"%d",i);
			break;
		}
		default:
			break;
	}

Note that the error only occurs if the variable declaration is the first statement in the code block.

Great tool for iPhone Mockups

Used OmniGraffle to produce mockups for my latest iPhone project, its pretty easy yo use and there are a number of good stencils that allow for most of the UI Kit controls and even the iPad!

Mac OS free XML Editor

Found a really useful XML editor that runs on the Mac, XML Spear

Objective C documentation generation

Found a useful tool Doxygen that will scan through your source code and generate documentation in an HTML format.