Learn to use Xcode 4 snippets
January 17th, 2012

One of my favorite features of the new Xcode 4 is code snippets. Code snippets let you use (and re-use) common classes and objects by simply typing a shortcut. For example if you type dealloc, Xcode 4 automatically generates the deallocation method for you:
- (void)dealloc {
<#deallocations#>
[super dealloc];
}
To add your code snippets to Xcode:
- Find the code you want and highlight it.
- Drag the selected code to the the Snippet Library
- Name your snippet (this is just the name you see in the Snippet Library)
- Choose a shortcut for your snippet which is used to invoke it (a good practice is to use shortcuts that show what the snippet does, like dealloc is used for invoking the deallocation method).
- Choose language and platform (so Xcode knows when to offer this snippet).
- If you like a bubble to appear as part of your snippets (like the #deallocations# in the example), just type <#text in the bubble#> in your snippet.
How to: Fix the “Base SDK missing” issue in Xcode
November 17th, 2010
Sometimes after upgrading your Xcode and iPhone SDK installation you may see the alert “Base SDK missing” when you try to compile and build an old project (that was written with a previous version of Xcode and an older version of iPhone SDK). That issue is as easy to fix as performing some clicks. Let’s see how:
- Open old project. On the upper side of the Xcode window you should see the message of the missing SDK as shown in the image below.

- Click the info button (blue icon with the “i”).

- Navigate to the “General” tab.
- Under the “Base SDK for all configurations” choose the latest version of iOS (now its 4.1. Choose iOS Simulator if you want to run the program on your Mac, or iOS Device if you have a developer device and you want to build the project and run it straight to the device).

- Click “build and run” and your project should now compile as usual.
iPhone programming: How to force your app to run in landscape mode
February 12th, 2010
As you may have mentioned, lot of iPhone apps (especially games) run by default in landscape mode! You can easily force the app you develop to run in landscape mode! Let’s see how:
- In Xcode find the file [YourAppName]-Info.plist and open it up.
- Right click on the table and select “Add Row”. Select “Initial interface orientation” and set the value to Landscape (left or right).
- Right click again and add Status bar is initially hidden.This is optional, it has nothing to do with view orientation, but it will hide the status bar.

- Open [YourAppName]ViewController.m file and uncomment the following:
// Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); - Change the code you just uncommented to look like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); }Parameter
interfaceOrientation == UIInterfaceOrientationLandscapeRightstarts the app with the Home button at the right side. interfaceOrientation == UIInterfaceOrientationLandscapeLeftstarts the app with the Home button at the left side. Set the same landscape orientation that you’ve set in Info.plist file.





