Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spaces in Xcode project names, what's the best practice?

Tags:

xcode

macos

cocoa

I'm creating a new Xcode project and the name will have a space on it, like "Foo Bar". I am inclined to name it "Foo Bar" because that's the actual name of the app as it appears on the top menu, the file system ("Foo Bar.app"), command-tab, etc. But then, I end up with odd looking folders and targets, like "Foo BarTest".

What's the best practice here?

like image 899
pupeno Avatar asked Mar 07 '15 10:03

pupeno


2 Answers

I use one word camelCase names like "FooBar" for developing: file names, paths, etc. To me, it makes sense to make my life a little easier when the occasional shell script needs to be written or something, as there's no need to worry about internal spaces. For sure, the 'make' utility chokes horribly on spaces…

But really, it's because I don't see the downside: the name of my FooBar.app is going to be localized anyhow, in English as well as whatever other languages, so the app in Finder looks like "Foo Bar", and in the About Menu, etc.

So it's FooBar to me in all my coding, and Foo Bar everywhere to the user.


How to localize the name of your app:

Start with a newly created Xcode Cocoa application, named "FooBar". Initially, everything is "FooBar", everywhere: the Xcode variables ${PRODUCT_NAME} and ${EXECUTABLE_NAME}, and the name of your built app in the Finder.

Now we want to only change the name as it appears in the Finder.
Properly, this is no more or less than localization.

In the app's Info.plist file, add the key "CFBundleDisplayName", and make its value identical to the value for the already existing key "CFBundleName".

The initial value of CFBundleName is "${PRODUCT_NAME}", an Xcode variable, and you can just copy & paste that. Alternatively you can "hard code" each of those keys to some literal string, but if you do that, then you must also update the "Product Name" value in the "Build Settings" pane for the application.

Then, you need to do the actual localization.

If it does not exist already (it probably does), create and add to the project an "InfoPlist.strings" localization file, id est (assuming English to be the "main" language) the file which resides in and is copied to the app's Resources folder in a sub-folder named "en.lproj".

In this file, add the same two keys that appear in the Info.plist file, in this format, giving them the value that you want your app to appear as in the Finder:

/* Localized versions of Info.plist keys */
CFBundleName        = "Foo & Bar";
CFBundleDisplayName = "Foo & Bar";

That's it! The app is now "FooBar.app" as far as UNIX is concerned, but it appears to the user as "Foo & Bar" in the Finder.

like image 120
zeppenwolf Avatar answered Oct 01 '22 03:10

zeppenwolf


I stopped using spaces in my Xcode project names.

There are circumstances(*) where you have to import your module into your unit test module, so in Swift you end up writing

import Foo Bar

in your Foo BarTest module, which is something the Swift compiler doesn't like.

(*) this is at least necessary when you use core data and you want to use your core data model and classes in your unit tests.

like image 27
Gerd Castan Avatar answered Oct 01 '22 03:10

Gerd Castan