Ugliest Line of Objective-C I Have Seen So Far

Started working through the Apress book ‘Beginning iOS 5 Development‘ and have been happy with it so far but I do think I have found the *ugliest line of Objective-C I have seen:

switchViewFrame.origin.y += [UIApplication sharedApplication].statusBarFrame.size.height;

What does that do? It is setting the beginning of the y-axis(top left corner) of the view to just below the status bar, as to not be hidden by it.

*not ugly as in bad code, ugly as in not very pretty to look at.

Code Created When Using ctrl + Drag to Connect UI Elements in Xcode 4

I was curious what code is generated in Xcode 4 when you ctrl + drag from a UI element to the header of the xib’s view controller.

For outlets, Xcode will create the @property in the header file and add a @synthesize to the implementation file. It will also add an entry to the viewDidUnload method to set the value of the outlet to nil. If your implementation file does not have a viewDidUnload method one will be created. Here is the code made for a label outlet:

-ViewController.h-

@property (weak, nonatomic) IBOutlet UILabel *label;

-ViewController.m-

@synthesize label;

in the viewDidUnload method

[self setLabel:nil];
For actions, Xcode creates an entry in the header and an empty method in the implementation file. Here is the code generated for an action:

-ViewController.h-

– (IBAction)buttonPressed:(id)sender;

-ViewController.m-

– (IBAction)buttonPressed:(id)sender {

}

Keyboard Shortcuts For Moving Around in Xcode

Using Xcode on a 13″ monitor gets pretty cramped so I need to be able to hide parts of Xcode I don’t need when I’m done using them. Here are the keyboard shortcuts to show/hide the 3 view areas in Xcode:

Navigation –  Command key icon0

Debug –   Shift iconCommand key iconY

Utilities –  Option or Alt key iconCommand key icon