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!
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!
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.
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.
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!
Found a useful tool Doxygen that will scan through your source code and generate documentation in an HTML format.
If you have IE 8 installed and your ASP.Net project won’t stop on the breakpoints you’ve set they you probably need to read this article
You basically need to add an entry to your registry to stop process growth for tabs.
I’ve copied the steps required below
1) Open RegEdit
2) Browse to HKEY_LOCALMACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main
3) Add a dword under this key called TabProcGrowth
4) Set TabProcGrowth to 0
UPDATE: unfortunately this only works for new projects!
Recently needed to change the way svn dealt with pbxuser files, found the following article that shows you how to tell svn to ignore certain files, but before I could do anything I had to be able to see the “hidden” svn folder where this article came in handy!
I’ve copied the crucial snippets here so that I don’t lose them….
From Terminal run the following command…
defaults write com.apple.Finder AppleShowAllFiles YES
Then you need to get Finder to relaunch, hold down the option key and click the Finder icon in the Dock, then select Relaunch
Now when you look at folders any hidden ones are visible, including the important .svn
Step 1. Open the subversion configuration file
~/.subversion/config
NOTE: If the “.subversion” directory doesn’t exist yet then run this command which fails but will create the necessary files to get you started:
svn status
Step 2. Enable “global-ignores” and add new things to ignore
Find the line that contains the text “global-ignores” and append the following text:
build *~.nib *.so *.pbxuser *.mode* *.perspective*
Step 3. Enable “auto-properties”
Located and uncomment (e.g. remove the leading “#” character) the line that looks like this:
# enable-auto-props = yes
Step 4. Add additional properties
Then go to the end of the file, in the [auto-props] section, and append these lines:
*.mode* = svn:mime-type=text/X-xcode
*.pbxuser = svn:mime-type=text/X-xcode
*.perspective* = svn:mime-type=text/X-xcode
*.pbxproj = svn:mime-type=text/X-xcode