2009-11-11

adding frameworks to an iPhone app in Xcode

To add a framework like CoreLocation or QuartzCore to an iPhone app in Xcode, don't ctrl-click on the Frameworks group and select Add / Existing Frameworks... Instead, go to the Target, Get Info and use the plus-sign button at the lower left of the General tab, below the Linked Libraries section. That will ensure you're getting a framework from the correct path.

2009-10-31

tab bar / nav controller / table view iPhone tutorial

This is a great tutorial video by Beth Robson showing a way to create an iPhone app with a tab bar where a one of the tab views is a nav controller with a table view controller stack:

http://cdn.oreilly.com/broadcast/2009/06/Bethrobson-CombiningTabBarNavigationAndTableViewControllersInAnIP434.mov

2009-10-30

internationalizing an existing iPhone app

To make your app work in different languages you need to set the app to handle different languages, and then create the translations from the app's native language to other languages.

Here's one way to do that, which avoids keeping track of multiple .xib files and instead puts all the strings for an app in one file:
1) set all your labels and button titles from your code
2) make all the strings in your code be NSLocalizedString values
3) create a Localizable.strings file, add it to your project and make it localizable.
4) translate the Localizable.strings files

Here are the details.
1) set all your labels and button titles from your code
This straightforward coding. For each label and button in your xib files, create a corresponding UILabel or UIButton as an IBOutlet, connect the variable to the interface item, and use the UILabel's text property or the UIButton's setTitle method to set the titles.

I recommend making the titles in a xib have square brackets around them so you can know whether the label's coming from the code or the xib.

2) make all the strings in your code be NSLocalizedString values
Replace hardcoded strings with NSLocalizedString. For example, instead of

labelFriction.text = "Friction";

use

labelFriction.text = NSLocalizedString(@"Friction", @"label for the Friction slider" );

The second string, @"label for the Friction slider" in this example, gives direction to translators so they know the context of the string they're translating. If you use the same string more than once, be sure to use the same comment, too, or the genstrings tool will throw warnings.

You can Find in Project the string @" (that is, at-sign, double-quote) to find all the strings in your project. For any string that's not a file name or in an NSLog statement, make sure the string is an NSLocalizedString.

3) create a Localizable.strings file, add it to your project and make it localizable.
Create this fie with the genstrings app.

  • launch Terminal.app

  • cd to your project's folder

  • run genstrings with this command,
    genstrings ./Classes/*.m
    You should run this from the project folder (above /Classes) because where you run it is where the Localizable.strings file will be created and you want that in the project folder, not the /Classes folder.


Now that the file's there, add it to your project. In Xcode, ctl-click on your Resources folder and Add / Existing files... Select Localizable.strings and click Add. Change the Text Encoding to Unicode (UTF-16) and click Add.

Then, make Localizable.strings localizable. Bring up the Info window for Localizable.strings and click the Make File Localizable button. Then, in the General tab of the Info window click the Add Localization and enter the 2-character locale code for the language, which you can find at http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

Each new language will result in a new folder in your project.

4) translate the Localizable.strings files
Translate the Localizable.strings for each language you want to support, and put the translated copies in the appropriate folders of your project.

how to get an Xcode build to run on an iPhone

how to get an Xcode build to run on an iPhone connected to your Mac:

set the SDK to the device
Project / Set Active SDK / Device - iPhone OS 3.0 (or whatever's appropriate)

set the build to Release
Project / Set Active Build Configuration / Release

clean all targets
Build / Clean All Targets

set Code Signing Identity to your profile
click on your target, then the info button, then the Build tab
under Code Signing Identity, next to Any iPhone OS Device, pick the certificate for your platform

set the Bundle identifier in Info.plist
change com.yourcompany to whatever you used in your AppID


if you're using a Distribution profile instead of a Development profile, add a dist.plist file to your project and include it as the Code Signing Entity

  • File / New File... Entitlements, save it as dist.plist

  • clear the get-task-allow checkbox

  • click the target then the Info button, under Code Signing Entitlements enter dist.plist

2009-10-04

how to rename an Xcode iPhone project

If you want to rename an Xcode iPhone project, especially useful after copying an pasting a project, here's how:
http://dougdiego.com/2008/10/09/how-to-rename-an-iphone-xcode-project/

If you rename the [...]AppDelegate class in the [...]AppDelegate.h and .m files, you'll need one more step:

  • open the MainWindow.xib (or whatever your root .xib is) in Interface Builder, click on the App Delegate object, and in the Identity Inspector, choose the new class name in the Class Identity section.