Xcode4_入门经典教程.pdf

上传人:tbuqq 文档编号:4741633 上传时间:2019-12-05 格式:PDF 页数:14 大小:136.61KB
返回 下载 相关 举报
Xcode4_入门经典教程.pdf_第1页
第1页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《Xcode4_入门经典教程.pdf》由会员分享,可在线阅读,更多相关《Xcode4_入门经典教程.pdf(14页珍藏版)》请在三一文库上搜索。

1、APPENDIX A Introducing Xcode 4 When learning about any Apple product, it s important to keep in mind that Apple likes to change things (sometimes quite dramatically). This book was written based on Xcode 3.2 tools, which have looked very much the same for the past decade (like the versions of Xcode

2、that preceded them, and the NeXT tools before those). In mid-2010, Apple released the first “ developer preview” of Xcode 4, a release that, to borrow a phrase from Steve Jobs, “ changes everything.” Xcode 4 pulls all of Xcode and Interface Builder into a single window. No more floating windows with

3、 tools and inspectors; instead, everything is consolidated into a single iTunes- like view, as shown in Figure A.1. FIGURE A.1 Xcode 4 consolidates Xcode and Interface Builder (and all their associated windows) into a single view. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 1 2 APPENDIX A: Introd

4、ucing Xcode 4 The bad news is that if you re used to using Xcode 3.2, Xcode 4 is a bit of a shock. The good news is that (almost) everything you know and love about the earlier Xcode is still present; you just have to know where to look. The best news? If you re already programming for iOS, you re t

5、hrough the tough stuff! You don t have to relearn iOS development; you just need to learn where Apple hid all of your tools! In preview form, Xcode 4 still has many rough edges and features that feel incom- plete, so it s difficult to predict when it will become Apple s primary development platform.

6、 Even after the release of Xcode 4.0, Xcode 3.2 will likely remain the plat- form of choice for many developers because of its maturity and stability. I recommend that, as a new developer, you begin coding in Xcode 3.2 to avoid any surprises that come with adopting just-released software. On the oth

7、er hand, I fully understand the desire to play with the latest and greatest toys from Apple, so I ve created this appendix to help you get started in Xcode 4. Let s walk through the tasks you need to perform when working on your iOS projects. Installing Xcode You install the developer tools exactly

8、as in the past. Download the latest Xcode 4 release from http:/ and run the installer package. Unlike the 3.2.x versions, however, Xcode 4 will be installed in a folder called Xcode4 at the root of your hard drive. If you have an earlier version installed, it can coexist with Xcode 4 with no problem

9、, as shown in Figure A.2. Xcode 3 Xcode 4 FIGURE A.2 If you install Xcode 4, it can coexist with ear- lier versions of the developer tools. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 2 Creating a New Project 3 As with 3.2.x, the developer applications themselves are located in the Applications f

10、older within the main installation directory (/Xcode4/Applications). Your main interest, obviously, will be in the Xcode application, which wraps up the functionali- ty of Xcode and Interface Builder into a single integrated tool. Creating a New Project To create a new project, start Xcode and eithe

11、r use the shortcut on the Xcode wel- come screen or choose File, New Project from the menu bar to begin a new iOS proj- ect. Choose Application from the iOS category on the left, and then pick from one of the available templates on the right, as shown in Figure A.3. FIGURE A.3 Create a new iOS proje

12、ct with- in Xcode 4. One small difference is that Xcode 4 refers to the deployment platform (iPhone, iPad) as the Device Family rather than the Product. Choose the appropriate device, and then click Next to proceed. In a new step, Xcode prompts you for the product name and a company identifier. Thes

13、e are used to automatically set the bundle identifier for your application. Recall that the bundle identifier uniquely identifies your product on the App Store. Click Next to continue. You are prompted for a project name. Then, after saving, you are presented with the Xcode 4 project workspace. The

14、Xcode 4 workspace consists of four main areas, as shown in Figure A.4. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 3 4 APPENDIX A: Introducing Xcode 4 . Toolbar: Displays project status and provides easy access to common func- tions . Navigator: Manages files and groups . Editor: Edits project co

15、ntent . Utility: Consolidates the Xcode and Interface Builder inspectors, help, and libraries Toolbar Utility Editor Navigator FIGURE A.4 Find your way around the new Xcode interface. Did you Know? A fifth area, the “ debugger,” appears below the editor when needed, but I tend to consider this to be

16、 an extension of the code editor. You ll want to familiarize yourself with all the features offered within each of these areas because all will come into play during your development. Navigating Your Code After you ve created or loaded a project, the Xcode workspace displays the project s files and

17、groups in the upper-left corner, in an area called the navigator. The con- 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 4 Navigating Your Code 5 tents of a file selected in the navigator display in the center of the Xcode window, as shown in Figure A.5. Although not all the same groups present in

18、Xcode 3.2 are visi- ble in the project navigator, everything you need to get started is. Add Files Filter Files File Contents Toggle Navigator Selected File FIGURE A.5 Xcode displays files, file groups, and the contents of the files just like you re used to. In general, the editing works identically

19、 to what you ve experienced in Xcode 3.2, but some enhancements make your development even easier. Code completion, for example, works even better recognizing things such as interface definitions (try typing interface) and providing structure for the file. The most notable enhance- ment, however, is

20、 the assistant editing mode. Did you Know? Xcode 4 eliminates smart groups. Instead, you can use the search field and icons at the bottom of the project navigator area to filter based on filename, recent edits, source control status, and save status. Did you Know? If you want to remove the navigator

21、 temporarily, you can drag its right edge to resize it, or just click the third button from the right on the Xcode toolbar. This but- ton toggles the visibility of the navigator off and on. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 5 6 APPENDIX A: Introducing Xcode 4 Using the Assistant Editing

22、 Mode The assistant editing mode displays related “ counterpart” files side by side with the file you are editing. In other words, if you re editing a .m implementation file, the corresponding .h interface file will be available beside it, as shown in Figure A.6. Editing the interface file? The impl

23、ementation file is automatically selected and made available. Standard Editing Mode Assistant Editing Mode FIGURE A.6 The assistant editing mode makes your file s counter- parts immedi- ately available. You can toggle between the standard editing mode and the assistant mode using the two leftmost ic

24、ons in the upper-right corner of the Xcode window. Adding Files To add new files (classes, for example) to the project, you can follow the same process that you did in Xcode 3.2 (choose File, New File from the menu bar), you can click the + button at the bottom of the navigator, or you can open and

25、drag and drop from the File Template Library. To show the File Template Library, click the sec- ond icon from the right in the top right of the Xcode toolbar. This hides and shows the Xcode utility area. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 6 Navigating Your Code 7 When the utility area is

26、 open, you ll notice that near the bottom is a pane that dis- plays a set of four icons. This is the Library pane, and the icons represent the File Template Library, Code Snippet Library, Object Library, and Media Library. Click the icon for the File Template Library and your screen should resemble

27、Figure A.7. Utility Area Toggle File Template Library Library Pane FIGURE A.7 Use the File Template Library to quickly add new files to your project. To use the templates, drag an icon from the File Template Library list into the proj- ect navigator. You are prompted for a filename for your new clas

28、s, as shown in Figure A.8. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 7 8 APPENDIX A: Introducing Xcode 4 When appropriate, Xcode even creates the interface and XIB files to accompany your new class. Adding Frameworks As you build more complex projects, you will need to include more iOS framewor

29、ks in your applications. In Xcode 3.2, you easily added frameworks much like you would add a new file. In Xcode 4, this process has been made a bit more obscure. To add an existing framework to your project, select the main project icon within the Xcode navigator, and then the icon for your applicat

30、ion within the Targets section to the right of the navigator. Finally, click the Build Phases tab at the top of the edi- tor area. Your screen should now resemble Figure A.9. Make sure the Link Binary with Libraries section is expanded, and then click the + button at the bottom of the section. Final

31、ly, you are prompted to choose the frame- work you want to use. Select it, and then click Add, as shown in Figure A.10. FIGURE A.8 Drag and drop to create new classes. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 8 Navigating Your Code 9 Build Phases Target Add Framework Project Icon FIGURE A.9 Na

32、vigate to the build phases for your project. FIGURE A.10 Choose the framework you want to add. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 9 10 APPENDIX A: Introducing Xcode 4 After adding the framework, you ll notice that a new framework icon appears in the project navigator. You can drag this i

33、nto the Frameworks group for safekeeping. Setting Project Options and Icons You can still edit your project plist file to make many of the standard configuration changes that you ve grown accustomed to in Xcode 3.2. In addition, Apple has “ prettified” many of the common settings and made them avail

34、able with an Info section for the project. To access this area, follow the same steps as if you were adding a new framework (select the project icon, then the target icon), but then click the Info tab, as shown in Figure A.11. Using these options, you can configure many of the most frequently needed

35、 settings for your project. You can even add your application icons by simply adding them as resources and then clicking + under Icons to choose which you want to use. Getting Help One Xcode feature I ve always loved is how easy it is to get helpand the help sys- tem is even better in 4.0. You can s

36、till use all the same help tools you know and love from Xcode 3.2; specifically, you can access the full, searchable, developer documen- tation by choosing Help, Developer Documentation from the menu. You can also Option-click keywords in your code to display a pop-up Quick Help window that contains

37、 context-aware information about what you are working on. Information Target Project Icon FIGURE A.11 Access common project settings in the Info area. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 10 Building Interfaces 11 In Xcode 4, you can use the utility area to toggle on and off a display of Q

38、uick Help information that will remain visible while you are editing. To do this, click the sec- ond button from the right in the toolbar to di splay the utility area, if it isn t already visible. Next, click the second icon from the right at the top of the utility area (two wavy lines in a black sq

39、uare, called Symbols). This opens the Quick Help pane, which displays information about the objects you re using, as you use them, as shown in Figure A.12. Utility Symbols Quick Help FIGURE A.12 Use the utility area s Quick Help pane to display context- sensitive help information. Building Interface

40、s The biggest and best new feature of Xcode 4 is Interface Builder integration. More precisely, Interface Builder is gone; you can complete a project from start to finish entirely in Xcode 4, without having to switch between applications. To see this in action, all you have to do is click an XIB fil

41、e in your project. The editor area trans- forms into an interface editor, as shown in Figure A.13. After the initial delight of seeing the interface appear directly in Xcode, you ll proba- bly start asking where the heck did they put everything. That s a great question. Everything you re used to usi

42、ng the Document window, inspectors, and Object Library are all there; they re just hiding. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 11 12 APPENDIX A: Introducing Xcode 4 Accessing XIB File Objects The objects that typically would be represented in the Interface Builder Document window are now

43、located between the navigator and the editor. By default, only icon representations of the objects are visible, but this is easily corrected by clicking the arrow at the bottom of the section, as shown in Figure A.14. FIGURE A.13 The features of Interface Builder are now inte- grated into Xcode 4! T

44、oggle Icon/List XIB File Objects FIGURE A.14 The Document window is replaced by a list of objects between the navigator and the editor. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 12 Building Interfaces 13 You can interact with these items the same way you would in the Interface Builder Document

45、window. You can Control-drag to or from them to make connections and expand view hierarchies to see their contents. Of course, this isn t going to do you much good unless you can actually add items to interface. Using the Object Library To access the interface Object Library, open the utility area,

46、and then click the cube icon at the top of Library pane, as shown in Figure A.15. Now things should be looking familiar. Object Library Utility FIGURE A.15 Access the Object Library from the utility area. You can drag items from the library directly into your interface design, just as you could in I

47、nterface Builder. You can also use the two buttons near the top of the pane to switch between list and icon views, and the search field at the bottom to quickly focus on a specific interface object. Did you Know? You can now drag objects into the editor area outside your main view. This can be helpf

48、ul for preparing objects before adding them to your view or for experimenting with different interfaces. The objects are in your XIB file and will be instantiated, but will not be loaded as part of the main view. 27_9780672332203_AppA.qxd 3/21/11 3:51 PM Page 13 14 APPENDIX A: Introducing Xcode 4 Ac

49、cessing Inspectors The last missing piece to the Interface Builder puzzle is the location of the inspec- tors. You ve grown accustomed to accessing the attributes, size, connections, and identity inspectors throughout the projects in this book. In Xcode 4, all of these are located in the utility area. To find them, first make sure the utility area is visible, and then look to the last four icons at the top of the utility area. These icons repre- sent the four missing inspectors: Attributes, Size, Connections, and Identity, as sho

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1