📜 ⬆️ ⬇️

We learn Xcode independently to put a program name instead of NewApplication


All Cocoa developers know about this unpleasant trifle: when creating a new Cocoa Application project in Interface Builder, you need to manually edit the program menu and change NewApplication to the name of the program. For some reason, the Xcode developers did not automate this process is not clear, because This is a matter of two minutes. You have to do it for them.

So let's get started. Go to /Developer/Library/Xcode/Project Templates/Application/Cocoa Application . Here we see files that are automatically copied to the folder with the new project. Because the annoying word NewApplication we change in Interface Builder, we need the MainMenu.xib file in the English.lproj folder. Open it in a text editor and see that NewApplication is there (in the amount of 6 pieces). We need to replace all occurrences of NewApplication with «PROJECTNAME» (including quotes «» ). Save, close.

Xcode when creating a project replaces all found «PROJECTNAME» with the name of the project. But in order for him to know in which files it needs to be done, he needs to indicate this. To do this, right-click on the CocoaApp.xcodeproj file and select "Show Package Contents". Open the TemplateInfo.plist file in a text editor and see the following:

  {
	 FilesToRename = {
		 "CocoaApp_Prefix.pch" = "" PROJECTNAME "_Prefix.pch";
	 };
	 FilesToMacroExpand = (
		 "PROJECTNAME" _Prefix.pch ",
		 "Info.plist",
		 "English.lproj / InfoPlist.strings",
		 "main.m",
	 );
	 Description = "This project builds a Cocoa-based application written in Objective-C.";
 } 

As you can probably guess, we need to add the path to MainMenu.xib to the MainMenu.xib :
')
  "English.lproj / MainMenu.xib", 

Save, close.

Voilà! Now you don’t need to manually change NewApplication to the name of your program each time you create a new project. I hope this hint was useful for you. Successes! :)

Source: https://habr.com/ru/post/56623/


All Articles