Xcode is a full-featured application that makes it easy to enter, compile, debug, and execute Objective-C programs. If you want to develop iOS applications quickly on a Mac, you must learn the ways to use this powerful tool. In this article, you’ll cover the basics of Xcode 9 development tools in detail, laying a foundation for the rest of the book.
1.1 Basic Panel Introduction
Figure 1-1 shows the effect of opening an iOS 11 project with Xcode 9.
(2) Resource Manager: The left part is the resource manager, above which you can set the view to be displayed, including Class view, search view, error view, etc.
(3) Engineering panel: this part is the most important and occupies the largest area in the whole window. It usually displays general information about the current project, such as build information, version information, and team information. When you select a source code file in Explorer with the mouse, the area changes to the Code panel, where the specific source code for the file is displayed.
(4) Properties panel: Useful for Storyboard or XIB design, you can set the properties of each control. And Visual C++, Vsiual Studio.NET properties panel similar.
1.1.1 Debug toolbar
Figure 1-2 shows the debugging toolbar. Starting on the left, we’ll take a look at common toolbar items, starting with the Run run button, which opens the emulator to run our project. The stop button is. In addition, when clicking and holding for a while, you can see the pop-up menu below, which gives us more options to run.
At the far right of the toolbar are three close View Controller tools that allow you to close unwanted views, as shown in Figure 1-4.
The navigation area contains multiple navigation types. For example, after the first icon is selected, the project navigation panel is displayed, that is, the construction file of the current project is displayed, as shown in Figure 1-5.
Clicking the second icon will bring you to the symbol navigation panel interface, which will display the classes, methods, and properties contained in the current project, as shown in Figure 1-6.
Clicking the fourth icon will bring you to the problems navigation panel interface. If there are errors or warnings in the current project, they will be displayed in this panel, as shown in Figure 1-8.
Clicking the sixth icon brings you to the debug navigation panel, which is blank by default, as shown in Figure 1-10. This panel displays content only when you are debugging your project.
Open a file, locate the line number in the coding window where you want to add a breakpoint, and click the left mouse button. An icon appears in front of the line of code, as shown in Figure 1-11. To remove breakpoints, simply drag the breakpoint sideways by holding down the left mouse button and it will disappear.
The breakpoint test navigation screen is very powerful, and you can even view your application’s CPU usage, as shown in Figure 1-14.
Clicking the eighth icon brings you to the Log navigation panel interface, which displays all the information that happened during the development of the entire project, as shown in Figure 1-16.
1.1.3 Inspector panel
Click the icon in the properties window to go to the file inspector panel, which displays information about the file storage, such as the file name, file type, file storage path, and file code, as shown in Figure 1-17.
Clicking the icon in the properties window brings you to the Quick Help Panel interface, where help information is displayed when you hover over the declaration snippet section of a source file. The help information about the mouse position is displayed in the upper right corner of Figure 1-18.
From the previous part of this article, you have learned the basics of panels in Xcode 9. In this section, you’ll go through the basics of doing things in Xcode 9.
1.2.1 Change of company name
When you write code in Xcode, the header of your code will have something similar to figure 1-19.
You can enter the keyword in the search box shown in Figure 1-20, so that only files with the keyword are displayed in the browser window. For example, you only want to see book-related classes, as shown in Figure 1-21.
1.2.3 Formatting Code
For example, in the interface shown in Figure 1-22, many lines are at the top and need to be formatted.
A more disciplined approach is to select the code you want to format and then look it up in the context menu, as shown in Figure 1-23.
Xcode does not provide shortcut keys, of course, you can set yourself, you can use the shortcut keys, such as Ctrl+A (select all text), Ctrl+X (cut text), Ctrl+V (paste text). Xcode will format the pasted text.
1.2.4 Code indentation and auto-completion
Sometimes you have to indent, and sometimes you have to do the opposite. Single-line indentation is similar to other editors in that you only need to use the Tab key. If multiple lines are selected, you need to use shortcut keys. Command+] indicates indentation, and Command+[indicates reverse indentation.
One of the great things about using IDE tools is that they help you automate long type names. Xcode provides this functionality. For example, the following output log.
NSLog(@”book author: %@”,book.author);
You can type NS first and then use the shortcut key “Ctrl+.” , the following code automatically appears.
NSLog(NSString * format)
Then fill in the parameters. Keyboard shortcuts “Ctrl +.” Is automatically given the first function or type that matches the NS keyword, and NSLog is the first. If you continue with “Ctrl+.” , will appear like NSString. And so on, all types or functions that start with NS are displayed, and so on. Alternatively, you can use the “Ctrl+” shortcut key, such as ns, to display a list of all types, functions, constants, and so on that begin with NS. You can choose here. In fact, Xcode can also automatically make suggestions as you type code. Let’s say YOU want to type in NSString. When you type in NSStr.
NSString
At this point, “ING” will automatically appear. If it is as I expected, just press Tab to confirm. Maybe you want to type NSStream, so go ahead and type. Alternatively, press Esc to display a list of results, as shown in Figure 1-24.
If you are entering a method, it will complete automatically as shown in Figure 1-25.
You can use the Tab key to confirm the contents of a method, or use the shortcut key Ctrl+/ to toggle parameters in a method.
1.2.5 Search and replace within the file
During code editing, search and replace operations are often performed. If you just search, press “Command+F” directly, and the dialog box shown in Figure 1-26 will appear in the upper right corner of the code. Just type in your keywords, case insensitive, and all hit words in your code are highlighted.
You can also do more complex lookups, such as case sensitivity, regular expressions, and so on. Figure 1-27 shows the setting screen.
You can switch to the Replace screen by selecting Find & Replace as shown in Figure 1-28.
The screen shown in Figure 1-29 sets the lookup to case sensitive and then replaces it with myBook.
Alternatively, you can click the button to replace all of them, or search for one to replace one, etc. If you need to Find and replace the entire Project, click “Find” -> “Find in Project…” Command, as shown in Figure 1-30.
Figure 1-31 shows the page for searching for the keyword book.
The process of substitution is similar and will not be explained in detail here.
1.2.6 Quickly Locate a line of code
To Navigate the cursor to the Line of the selected file, use the shortcut key “Command+L” or click “Navigate” -> “Jump to Line…”. Command is executed, as shown in Figure 1-32.
The following dialog box is displayed when you use the menu or shortcut keys. Enter the line number and press Enter to display the specified line of the file, as shown in Figure 1-33.
1.2.7 Quickly Opening files
Sometimes, you need to open the header file quickly, as shown in Figure 1-34. To find out what the file viewController.h is, click on the file viewController.h.
Click File -> Open Quickly… Command, as shown in Figure 1-35.
The dialog box shown in Figure 1-36 is displayed.
Double-click on the entry in the viewController.h file to see the interface shown in Figure 1-37.
At the top of the code window is a toolbar that provides many convenient navigation functions, as shown in Figure 1-38.
It can also be used to implement TODO requirements above. There are two ways to write a custom navigation bar, of which the following is standard.
#pragma mark
Here are the Xcode compatible formats.
// TODO: xxx
// FIXME: xxx
Copy the code
Figure 1-39 shows the complete code.
The navigation bar effect shown in Figure 1-40 is displayed.
1.2.9 Using Xcode Help
If you want a quick view of the official API documentation, you can press “Option” in the source code and double click on the type (functions, variables, etc.). The “didReceiveMemoryWarning” API documentation dialog box is shown in Figure 1-41.
If you click the button identified in Figure 1-41, the complete document window is displayed, as shown in Figure 1-42.
1.2.10 Debug code
The simplest debugging method is to print the results of the program running through NSLog, and then judge whether the flow of the program running and the result value meet the expectations based on these results. For simple projects, this approach is usually sufficient. However, if you are developing a commercial project, you will need to use the specialized debugging tools provided by Xcode. All programming tools debug in the same way. The first step is to set breakpoints in your code. If you imagine that your program is executing sequentially, you might suspect that something is wrong with the code. Set a breakpoint at the beginning of the code, such as the first line of the method, or at the beginning of the loop. The program will stop when it hits a breakpoint during debugging, and then you can run the code line by line to see if it executes in the order you expect it to, or if the values of the variables are what you think they are.
Setting a breakpoint is very simple. For example, to set a breakpoint on the line represented in the box (run to), click the left circle of the line, as shown in Figure 1-43.
Then run the code, for example, Command+Enter. The code will run and stop at the breakpoint, as shown in Figure 1-45.
You can run the Shift+Command+Y Command to bring up the debugging dialog box, as shown in Figure 1-46.
Figure 1-46 Debugging dialog box
This is very similar to the interfaces of other IDE tools in other languages because they all have similar functionality. The following is a detailed description of the main commands.
1.3 Use Xcode 9 Help system
When using Xcode 9 in Mac for iOS development, it is inevitable to encounter a lot of API, class and function information query operations, at this time, you can use Xcode’s own help document system to learn and solve our problems. There are three ways to use the Xcode 9 help system.
(1) Use the “Quick Help Panel”
You can use the Quick Help Panel in this article 1.2. You only need to move the mouse pointer over a class or function in the source code to display the help information in the Quick Help Panel, as shown in Figure 1-47.
Click View Controller Catalog for iOSView Controller in the lower right corner. The detailed information is displayed on the new screen, as shown in Figure 1-48.
(2) Use the search function
In the help system shown in Figure 1-48, we can enter a keyword in the top text box to display the corresponding knowledge point information below. Figure 1-49 shows the effect after keyword NSString is entered.
(3) Use quick help in the edit area
In the code editing interface of a program file, after pressing the Option key, when the mouse cursor is moved to a class, the cursor will change to a question mark. At this time, clicking the left mouse button will pop up the quick help information in a floating style, and display the corresponding interface file and reference document.
When you click to open the document name, the help page is displayed, showing related help information.
This article is excerpted from the iOS 11 Development Guide
IOS 11 Development Guide by Guan Lei
Click on the cover to buy the paper book
Explain based on the new iOS11, demonstrating the new features of iOS11; Objective-c and Swift bilingual explanation, brand new Swift 4.0 example demonstration; Nine hours of video explanation, more than 230 typical examples and two comprehensive examples, to help readers get started development as soon as possible.
It’s a comprehensive, step-by-step guide to iOS 11 app development. It almost covers the main content required by iOS 11 application development, which is suitable for iOS development beginners and iOS programmers to learn, and can also be used as a teaching book for relevant training schools and colleges.
Stretch recommended
Click on key words to read more books: Python | | machine learning Kotlin Java | | | | mobile development robots contests | Web front-end | book list
If you reply “follow” in the background of “Asynchronous books”, you can get 2000 online video courses for free. Recommend friends to pay attention to according to the prompts to get a gift book link, free of charge asynchronous books. Come and join us! Scan the QR code above and reply “Follow” to participate in the event!
Read the original