Xcode use tutorials in detail is the content of this article, Xcode is a powerful IDE development environment, as you write a Windows program need VS2005 as much as you need to Xcode write Mac program to provide the environment. Therefore, if you want to become a Mac program developer, the flexibility to use the Xcode tool is the first step you have to take.
1 When we write the program often in the head of the source file to add a copyright statement and the company name , and so on, and Xcode in the creation of the file has helped us do most of the work, we may need to modify the company name, because Xcode to not know our company name, It can't predict everything, so we need to tell it by setting it ourselves. So how do we do that? Because there are no placeholders for company names in Xcode, we must set them by using the terminal command.
Before using this command, let's look at the default file header comments that Xcode provides for us:
//UNTITLED.M
//filesorganize////
Created by Yan Li on 8/29/09.
Copyright 2009 __mycompanyname__. All rights reserved.
Execute the following command in terminal (the hotkey to open terminal is Command+shift+u):
Copy Code code as follows:
yan-lis-macbook-pro:~ yanli$ Defaults write Com.apple.Xcode pbxcustomtemplatemacrodefinitions ' {' OrganizationName ' = ' Liyanzhong ";} '
Note that the above command is on the same line as the terminal command line, not two lines, because the command is too long. Note that the command does not emit any prompts when it executes, even if you have written the wrong parameter name in the command, there will be no prompts, so if you execute the command and find that the effect you are looking for does not appear, please check to see if you have any spelling errors, then restart Xcode and recreate the file after you execute the command. This is the time to create a file header annotation, as seen below:
* * * UNTITLED.H * Untitled * *
Created by
Yan Li on 8/29/09.
* Copyright 2009 Liyanzhong. All rights reserved.
*
*/
2 Tips for using editors
A how do you close the browser window on the Xcode interface?
Click on the rightmost editor icon on the Xcode toolbar to turn on or off the browser that finds the project file in Xcode. Shortcut keys are command+shift+e.
If you have every icon on your window that I'm talking about, then you need to manually place the icon on the toolbar. How to put it?
Activate Xcode tool, enter View->customize Toolbar ... You'll find a lot of tools on the right that don't appear on the toolbar, so you can drag the tools you want to use at any time to the toolbar.
b How do I indent the code first line?
The first method: Select the code that needs to be indented, hold down the control key, click the cursor, pop the menu, and then select Re-indent Selection.
The second method: Select the code that needs to be adjusted and press command+[(left move code) or command+] (right Move code).
c) Powerful application of the code completion function
Writing code in Xcode, the Xcode editor often gives hints that if the code hints given are consistent with our requirements, we can press the TAB key to select the indicated code.
If the prompt code does not meet our requirements, we can press the ESC key to display the entire list of prompts to find what we need. There is a small box at the far left of the list member, if the inside is F then the corresponding Member is a function, if it is M is the method, if it is a # it is the #define command; if it is E, it is an enumeration;
If we do not want to display a list of prompts and choose between list members, we can use the shortcut key control+. Loops between options, or you can use shift+control+. Reverse loops between options. We can query the API (interface method) provided by a class by using the Code AutoComplete feature. The method is to implement this query in a method invocation expression by writing the class:
[nsdictionary+ space, and then press ESC, the list of methods provided in Nsdictionary appears. Note: [Nsdictonary must be followed by a space, prompting that the compiler class name is already written. The next step is to enter the message (that is, the method name in the Class).
The shortcut key that jumps the cursor from a placeholder to the next placeholder is: Control +/
D When you modify the code for a project, take a snapshot first.
File->make Snapshot Take a snapshot of the project; File->snapshots recover from the snapshot. The corresponding shortcut key: Control+command+s; Recovery does not have a shortcut key, the advantage is that the current code modification rotten, you can restore to the most state. This shows that this function is only helpful when we modify the code, and cannot really replace our manual modification of the code.
e) Find the use of replacement features:
Edit->find->find in Projects ... The following dialog box appears:
Enter the character you want to look for in the Find field; Enter the character to replace the found character in the Replace column; we chose to find it in the project. If we do not select ignore case, the substitution occurs only in the main () function.
This method modifies the code with a lot of drawbacks--if I just want to modify the car characters within a function, but this modification will change all the car characters outside the function that I don't want to modify, and the second is that it can't modify the class name and filename; So the following method is needed to make up for its first deficiency.
F This method can solve the first flaw in the code modified above, you can control the modification of the code within a function, but it still cannot modify the class and file name. Before using this method, you must use the cursor to select a local variable character or function parameter that needs to be modified, note that it must be a character, and if you select a class-name character, the menu item "Edit All in Scope" will not appear.
Edit->edit all in Scope, and then when you enter, all occurrences of the character are replaced with the characters entered.
g) Here is a way to modify the class name and file name.
The method can change the class name and filename, first select a class name that needs to be modified, such as engine, insert the cursor into the character, select Edit->refactor ... Open the following dialog box:
You can also repair the car if you need it.
Press the preview button, the interface as seen below, Xcode automatically give us the analysis report, what files will be modified, each file will be modified and other information. As you can see from the figure below, the class name and the name of the class are all modified.
h) shortcut keys commonly used in cocoa text fields:
Using the shortcut keys below, we can move the cursor in a small range. Don't let the hand not leave the keyboard.
CONTROL+F: Moves the cursor to the right on the same line
CONTROL+B: Moves the cursor to the left on the same line
CONTROL+P: Move the cursor to the previous line
Control+n: Move the cursor to the following line
Control+a: Moves the cursor to the beginning of the line
Control+n: Moves the cursor to the line end of the bank
Control+t: Swap the characters on both sides of the cursor
Control+d: Deletes the character to the right of the cursor
Control+k: Deletes the code behind the cursor at the row cursor to allow you to rewrite the line-end code
Control + L: Places the cursor insertion point in the middle of the window.
How do I search for a file in Xcode?
How do you open a header file imported by #import in a source file?
Select the header file (you can not include. h), and then pass File->open Quickly ... Open the file that is selected.
When no text is selected, select Open Quickly ... Opens a simple query window to find the files in the project. Shortcut keys Command+shift+d
If you are currently looking at an. m file, and you suddenly want to see the. h file corresponding to the file, we can use the COMMAND + option+ up ARROW key combination to open the supporting file.
j) Use of bookmarks in Xcode
If you want to mark a part of your code so that you can find it later and conveniently, then we'll use a bookmark.
Select a piece of text or place the insertion point in the source file, and then select Edit->add to Bookmarks (shortcut command + D) and enter the book signature when prompted.
k) the navigation bar of the Code Editor
The navigation bar is the top of the editing window in this article.
There is a function menu on the navigation bar, and we can add items to the function menu via the #pragma mark command. #pragma指令将objective-C passes information or instructions outside of the regular code to the compiler and the code device. Usually, #pragma是被忽略, if your compiler does not recognize it, it will ignore it and will not apply for a warning.
In addition to adding items via #pragma mark to the function menu;
Text that starts with the following key characters in a comment is added to the function menu:
Copy Code code as follows:
MARK:
Todo:
Fixme:
!!!:
???:
(L) obtain Xcode documentation and reference materials through research Assistants (Assistant).
It can be opened by Help->show Research Assistant. Once the research assistant's floating window is open, the contents of the floating window will change as you change the contents of the Xcode interaction.
As shown in the following illustration: In the TIRE.M file, when the cursor is on the NSString class, study the information displayed by the Assistant floating window:
When you switch to file Tire.h, the Research assistant's floating window displays information about NSObject:
M) Document management program
We can access Apple's official API documentation by holding down the option key and double-clicking on a symbol to view. If we hold down the option key and double-click the NSString symbol, the NSString information is opened in the Document browser window, as shown in the following figure:
Hold down the CONTROL key and click the document area to open the Pop menu, select any menu item, and open the document in another window.
M) How do I debug a program?
(a) There are two methods: one is the violent debugging, the other is debugging with the debugger.
What is violent debugging?
Violent debugging is to add the NSLog () language to your program, and to export the program control flow and some important data to the terminal.
Debugger Debugging:
A debugger is a program between the application and the operating system you write, and you can control your program, such as stopping, executing, stepping, and so on.
The debugger used by Xcode is GDB.
Xcode in addition to GDB, there is a miniature debugger, it is a floating window, through which we can skip the GDB debugger to do some simple debugging work.
Xcode has a debugging window that provides a large amount of overview information.
Xcode provides a debug console that allows you to send debugging commands directly to the debugger.
(b) How do I debug with the debugger?
(1) The compiler's debug configuration must be used to compile the program so that the compiled program contains debugging information (the information the debugger uses)
(2) When debugging, you need to have the program run in debugger mode.
There are two ways to run a program in Xcode: Run->run (shortcut: Command + R) without the debugger running the program;
Run->go (Debug) or Run->debug (shortcut key: command+y), run the program using the debugger.
(3) How do I set a breakpoint on the operation of a breakpoint?
Click on the side column (gutter) to set a blue breakpoint, disable the breakpoint on the second click, and drag the breakpoint out of the Edge column if you want to delete the breakpoint.
Debug shortcut keys:
Continue : option + COMMAND + P step to : SHIFT + COMMAND + I step over
: SHIFT + COMMAND + O Step out :
Open the Debug window of the Xcode (click on a box with an aerosol on the Debug control bar) as shown below:
With this window, you can perform various debugging commands and observe changes in the value of the variable.
The following is the GDB Command Debug window, where you can enter the debug command for GDB to debug the program:
You can view the function call stack by debugging one of the controls on the control bar (the one on the right side of the black box control), as shown in the figure above.
[Note] Side column (the column in which the breakpoint is located) a narrower column is the focus column.
Summary: Xcode Use the detailed introduction of the tutorial, I hope this article is helpful to you, we probably learned xcode this powerful tool, to study it in depth, we still have a lot of road to go, but we have a good start.