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!


Objective C documentation generation

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


Programmatically Exit iPhone App

To terminate your app from within your code execute the following command…

exit(0);


UIAlertView with UITextField – REJECT

A project I’m working on contains an alert that uses the addTextFieldWithValue:label: private API, this approach has been popular/recommended by a number of developers/blogs, but now that Apple have their automated checking for Private API’s any apps using this technique will be rejected….

“3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs.”

The following non-public APIs are included in your application:
addTextFieldWithValue:label:
textFieldAtIndex:

Jeff LaMarche has a great article that shows an alternative, that doesn’t use any Private API’s and therefore shouldn’t get you rejected.


XCode SCM column in Xcode project treeview

If you can’t see the column to the left of project files that shows the SVN status of a file, right-click the “Groups & files” title and select SCM

Groups & Files - SCM


__MyCompanyName__

The template that creates your .h and .m files within Xcode by default sets the company name to __MyCompanyName__

To correct perform the following…

1) Start up the program Terminal Utilities/Terminal
2) Enter the following where XXXXXXXXXXXXX is what you want to appear in place of __MyCompanyName__:
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions ‘{“ORGANISATIONNAME” = “XXXXXXXXXXXXX”;}’
3) Press enter
4) Shut down and restart Xcode.


Finding Build Errors

To quickly jump to build errors within your iPhone app, use the short cut combo of ⌘=


Previous Entries Next Entries