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.

Objective C documentation generation

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

SVN, pbxuser and Xcode

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….

Show hidden files

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

SVN Ignore files

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

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 ⌘=

Xcode tip – use alt key for selecting code

If you have a code that is in a vertical section and you would like to select it, for copy/cut/paste/delete functions hold down the alt key while dragging your cursor over the code. The screen shot below shows me selecting //’s so that I can uncomment the code
Using alt key to select square not lines

The selection you make can also be used in pasting and will paste vertical down from your cursor point.

svn cleanup

I recently had a problem where I couldn’t check in files from my project because I was getting an error stating that the folder was locked. I tried to run a cleanup on the folder but that failed due to the “build” folder not being under source control. Quick and dirty solution to this is move the build folder to a different directory, run the cleanup again, then move the folder back. All worked after that.



In order to move the cursor automatically to the next data entry field when the user presses Next on the keyboard you need to resignFirstResponder from the current field and assign it to the next field using becomeFirstResponder

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	if (textField == field1TextField) {
		[textField resignFirstResponder];
		[field2TextField becomeFirstResponder];
	} 
	else if (textField == field2TextField) {
		[textField resignFirstResponder];
		[field3TextField becomeFirstResponder];
	}
	else if (textField == field3TextField) {
		[textField resignFirstResponder];
	}
	return YES;
}


You need to set the Return Key types accordingly within the interface builder. Your ViewController must also implement UITextFieldDelegate and the textfields delegate assignment must be set via IB to the File’s Owner

See what I do

Create Objective-C classes from Core Data model

Once you’ve created your data model within Xcode, you may need to generate the classes so that you can use and reference them in your main project. To do this open the data model, select File/New File… from the Xcode menu system, this will display the following screen…


New File screen with Managed Object Class selected

New File screen with Managed Object Class selected




Choose your location and then select the entities you want created.