Detailed description of Apple development tools Xcode and Interface Builder

Source: Internet
Author: User

Apple development toolsXcodeAndInterface BuilderIs the content to be introduced in this article. It introduces the usage and operation methods of the two development tools in detail. Let's take a look at the details.

What is Xcode?

Xcode is developed by Apple and runs only the IDE on Mac OS X. If you really want to know about development on Mac OS X, you should understand it. Of course, Mac OS x implements POSIX, which also supports the traditional UNIX programming environment. Java development tools such as Eclipse also support Mac OS X. However, you can also experience this on Linux or Windows. Xcode is not mysterious. Apple does not have its own compiler, Although Gcc on Mac is a version modified by Apple). When creating a project, xcode will still generate and execute a line of Gcc and ld commands. So if you have enough UNIX experience and know where to find the desired Framework), you can compile a complete Cocoa application on the command line.

In fact, Xcode provides a lot of functions that allow you to benefit from creating projects, designing, modifying code, compiling, and other processes. I am afraid it is difficult to find a reason for not using it. In fact, since Mac OS 10.4 introduced the concept of Universal Binary, Xcode has almost become the only choice for most Mac developers. You don't have to worry that Xcode is free of charge. As long as you have a Mac, Xcode is included in the random installation disk, the upgrade is free. However, if you are using an OS earlier than Mac OS 10.5, you cannot run Xcode 3.0 or later ).

What is Interface Builder?

Interface BuilderIB) is an application used to design and test the user Interface GUI on Mac OS X. To generate a GUI, IB is not necessary. In fact, all user interface elements in Mac OS X can be directly generated using code; however, IB allows developers to easily and quickly develop a GUI that complies with Mac OS X human-interface guidelines. Generally, you only need to drag the drag-n-drop operation to build the GUI.

IB uses Nib files to store GUI resources and is applicable to both Cocoa and Carbon programs. When necessary, the Nib file can be quickly loaded into the memory.

ByeWindows Program

The best way to learn and understand Xcode is to make a simple example. Otherwise, you will always only know Xcode and do not know how to use it. In this example, I also put two in many external connections on the internet). readers who have no problem with English can directly look at those examples.

Let's take a look at how to use Xcode to compile a simple Cocoa program to ensure real-time performance. The following example uses Xcode 3.0. The reason for using the Cocoa program as an example is that I want to use a coherent example to introduce Xcode and Interface Builder. At the same time, the Cocoa program can represent the features of Mac OS X programming ).

First, install Xcode. In the Leopard installation DVD, select "optionalinstils-> Xcode Tools-> XcodeTools. mpkg" in the pop-up window, and complete the installation according to the installation wizard. After the installation is complete, Xcode. app can be found under \ Developer \ Applications. Double-click the icon to run Xcode.

Next we need to create a New Project, click "File-> New Project..." In Xcode's menu, or use the shortcut key Shift + Cmd + N. In this case, an Assistant window is displayed, where you need to select the Project you want to create. Select "Application-> Cocoa Application" and click "Next ". Then you need to name the project and specify the path. Here we call the project ByeWindows. Click "OK" and you will see the main Xcode window.

Figure 1.1 select a Project type

Let's take a look at the "Groups & Files" column on the left, and notice that the ByeWindows blue icon representing the entire Project has been selected. At this time, all the Files in the Project are displayed, including source files and Binary files to be generated. Note that the executable file of ByeWindows. app is displayed in red, which means the file has not been generated yet, but the Project has a Reference for it.

If the selected Group on the left is changed, the file list on the right is also updated accordingly. Now we create two New files in the Classes group: Right-click to select Classes, Add-> New File... select Objective-C Class, name the File "AppController", and click OK. At this time, two new files will be added to the Class group. By default,. H files will be opened in a new window. Can you use the shortcut key ?? Swap to the. m file. You can also double-click a file in the Groups & Files column to open it in a new window. Editing code in a new window is sometimes very convenient, but the "All-in-One" window mode may be more favored.

If you like "All-in-One", you just need to select main on the left. m file, and then click the Editor button on the Toolbar. If you cannot see this button, you need to first click the menu item "View-> Customize Toolbar... to add the button), so that the window on the right is changed to Editor. If you select the option on the left, the content of the Editor on the right will be updated accordingly. Note:XcodeUnlike VS, which supports tabs, you can click the small triangle on the left to select the files recently opened in the Editor. Click the small triangle on the right, you can select the Symbols, such as the function name, in the currently edited file ).

Figure 1.2 Editor

Next we will write some code:

 
 
  1. AppController.h:   
  2. @interface AppController : NSObject {  
  3.     IBOutlet NSButton *button;  
  4. }  
  5. - (IBAction)saySomething:(id)sender;  
  6. @end  
  7. AppController.m:   
  8. #import "AppController.h"  
  9. @implementation AppController  
  10. - (void)awakeFromNib {  
  11.     NSLog(@"Wake up!");  
  12. }  
  13. - (IBAction)saySomething:(id)sender {  
  14.     NSLog(@"Hello Mac, Goodbye PC.");  
  15. }  
  16. @end 

Here we have defined a class, but it has not yet generated its Instance. Double-click Resources-> MainMenu. nib,Interface Builder willAuto Start. From the Library drag a NSObject blue cube) to the Window where the Title is MainMenu. nib. Then select Identity tap (? 6), change its Class to the class we just defined in AppController ).

Then, any Button of the Drag Button in the Library can be used) to the Title Window ). Then, while holding down the Control, the Drag button goes to AppController and connects its Action to SaySomething :. Save and returnXcode.

Figure 1.3 drag an Object

Figure 1.4 specify the Class of the Object

Figure 1.5 press and hold Control and drag the button to the App Controller

Next we will compile the project. Click the "Build" icon on the toolbar or use the shortcut key? B. The compilation should be successful. Note that "Build succeeded" and "Succeeded" are displayed on both the left and right sides of the main window ". Click the latter and you will see the "Build Result" window. If there is any Error or Warning, it will be displayed here. Run the program, click the Go icon, or use the shortcut key? R. Then you will see that you areInterface BuilderWindow with a Button. Click the small Gdb icon at the top of the Rditor window. You can see Wake Up! . Click the Button in the window to view the Log message "Hello Mac, Goodbye PC.

Here, I will explain the working principle of this program. First, AppController is instantiated through the Nib file. AwakeFromNib Method is automatically called after the program runs, so the first Log message is available. In addition, we established the link between the Button and saySomething: In IB, and every time the Button is pressed, it will send a message to its Target (AppController). Here is saySomething :), so every time we press the Button, there will be a new Log message.

Next, we will try debugging. First, we need to set a Breakpoint. InXcodeIt is the simplest in it. On the left of the Editor window, there is a column showing the row number. Click the number 5... oh, a Breakpoint is born. To change the position of a Breakpoint, we only need to drag it up and down with the mouse; how to remove it? Just drag it out with your mouse and let it go.

If you click on the blue Breakpoint, it turns gray, meaning it is Disable. Well, now make sure there is a blue Breakpoint in row 5th. Then we click the menu item "Run-> Debug", and the program will stop at the Breakpoint we set. Place the mouse over different variables to view the value of the variable. At the same time, note that there is an additional row of tools above the Editor for debugging. Click the icon "Gdb" on the rightmost side to view the Console window again. Keep the Console window on one side, and then click Step Over on the left. "Hello World" is displayed on the Console again. Then, click "continue" on the left ), since we have no other Breakpoint, the program should be terminated normally.

Related Article

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.