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!
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….
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
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.
To have a label recognise line breaks in the text that you enter in the Interface Builder, set the number of lines to 0, and when you want a new line press both the Option key and the Return key
After creating a new version of your data model, and adding the relevant code to handle lightweight migration, to actually get your code to run ensure that you do a clean all targets otherwise you get merge model errors!
Now that I’ve started to do some OpenGL I needed to determine where in my 3D world a user had touched. In order to do this you can use a function called gluUnProject, which isn’t part of the standard framework. I’ve converted the code (so have many others) and posted it here in case it might help someone else.
I used the following article to then use this methods.
I’ve copied the code below so that I have a reference to it as well.
You also need to ensure the following steps are followed…
Make your controller implement UITextViewDelegate
setup your textfield’s (s) delegate to be your controller
in the controller @interface add an int verticalOffset
in the controller @implementation add the functions below
#pragma mark "-- text editing support --"
// Animate the entire view up or down, to prevent the keyboard from covering the text field.
- (void)moveView:(int)offset {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
// Make changes to the view's frame inside the animation block. They will be animated instead
// of taking place immediately.
CGRect rect = self.view.frame;
rect.origin.y -= offset;
rect.size.height += offset;
self.view.frame = rect;
[UIView commitAnimations];
}
- (BOOL)textFieldShouldReturn:(UITextField *) sender {
[sender resignFirstResponder];
if (verticalOffset!=0) {
[self moveView: -verticalOffset];
verticalOffset = 0;
}
return TRUE;
}
- (void)textFieldDidBeginEditing:(UITextField *)theTextField {
int wantedOffset = theTextField.frame.origin.y-200;
if ( wantedOffset < 0 ) {
wantedOffset = 0;
}
if ( wantedOffset != verticalOffset ) {
[self moveView: wantedOffset - verticalOffset];
verticalOffset = wantedOffset;
}
}