Objective-C learning path using Xcode (3)

Source: Internet
Author: User

Objective-CLearning pathXcode3) This article will introduce you. Use Xcode 2 as the Objective-C learning path. Continue to the previous section. This article will introduce you in several sections. If you are interested, please keep an eye on it.XcodeThere are many functions. The following describes common functions and helpObjective-CDevelopers can improve coding and debugging efficiency.

Quick file opening

Sometimes we want to quickly open the header file, such:

What is Cocoa. h here. You can select Cocoa. h, for example. Then:

A dialog box is displayed:

Double-click the Cocoa. h entry and you will see:

In addition, there is a more convenient operation, for the header file, that is, hold down the command key and double-click the type function, variable, etc.) Name. This type of header file is displayed in the source code window.

Use bookmarks

I used Eclipse in the past and often used TODO.TagFunction. For example, if you need to do other things when writing code, or remind yourself of the functions to be implemented later, write a TODO annotation. This can be found in the Eclipse view, this code can be found and modified later.

Does Xcode provide functions? I now think that the bookmarks function can do similar things.

For example, I wrote a code:

This method is empty, printInfomation. It is not required for the time being. However, you need to write it down so that you can find and supplement it later. So let the cursor inside the method. Right-click and Add to Bookmarks:

Then, a dialog box is displayed, in which the TAG content is filled, such:

In this way, you can find this entry on the project's bookmarks node:

Click this entry to return to the location where you just added the bookmarks.

Custom navigation bar

In the code window, there is a toolbar. Provides many convenient navigation functions. For example:

It can also be used to meet the above TODO requirements. There are two ways to write custom navigation bars. Where:

 
 
  1. #pragma mark 

Is a standard writing method. And:

 
 
  1. // TODO: xxx  
  2. // FIXME: xxx 

Is an Xcode-compatible format.

Complete code:

The navigation bar effect is as follows:

Use Xcode help

If you want to quickly view the official API documentation, you can press the option key in the source code and double-click the function type and variable. For example, the following is the NSString API documentation dialog box:

If you click the button marked above, the complete document window will pop up:

Debug code

The simplest debugging method is to print out the results of the program running through NSLog, and then determine whether the process and result value of the program running meet expectations based on the results. This method may be enough for simple problems.

However, if a commercial project is developed, it is often complex enough and requires the help of specialized debugging tools provided by Xcode. The debugging logic of all programming tools is the same. First, you need to set breakpoints in the code. Imagine that the execution of the program is sequential, and you may suspect that the code in a certain place not only causes a bug), then at the beginning of this code, for example, set a breakpoint in the first line of a method or the beginning of a loop. The program will be aborted when it is executed to a breakpoint during debugging. Next, you can execute a line of code to determine whether the execution sequence is as expected, or whether the value of the variable is the same as you think.

It is easy to set a breakpoint. For example, to set a breakpoint for a row in the red box, click the red circle on the left side of the row:

After you click it, a breakpoint flag will appear:

Then, run the Code, for example, use the shortcut key: command + enter. The code is run and stops at the breakpoint:

You can call up the debugging dialog box through shift + command + y:

This is similar to the interfaces of IDE tools in other languages, because they all have similar functions. You can use:

Continue to execute the program

Step over, step into, and step out are used for single-step debugging, which respectively indicate:

Step over: the next statement in the current method is executed.

Step into: if the current statement is a method call, the first line inside the method is called in one step.

Step out: The method where the current statement is located. The first line outside the method is displayed.

Through debugging tools, you can perform comprehensive and meticulous debugging on the application.

Summary:Objective-CLearning pathXcode3) I hope this article will help you! Please join the following two sections.

Objective-C learning path using Xcode 1)

Objective-C learning path using Xcode 2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.