Learn Ojective-C on the Mac ppt

371 2.1K 0
Learn Ojective-C on the Mac ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... typos, and then rebuild the program If the program runs on a web site, we then have to retest and redeploy the program to upgrade to Word-Length-2 Another way to construct this program is to move the names completely out of the code and put them all into a text file, one name on each line Let’s all say it together: this is indirection Rather than putting the names directly in the source code, the program... struct elements There are also more complex data structures, such as linked lists and trees When you call a function, you pass the data to the function, and it manipulates the data Functions are the center of the procedural programming experience: you decide which functions you want to use, and then you call those functions, passing in the data they need The Shape of Things to Draw Consider a program... your problem to the support person, who then directs you to the specific department that can handle your problem The person there then directs you to the second-level technician with the skills to help you out And if you’re like us, at this point, you find out you called the wrong number, and you have to be transferred to some other department for help This runaround is a form of indirection Luckily, computers... @"YES" Notice that the return type of boolString() is a pointer to an NSString This means the function returns one of the fancy Cocoa strings that you saw earlier when you first met NSLog() If you look at the return statements, you’ll see the at sign in front of the returned values, a dead giveaway that they’re NSString values main() is the final function After the preliminaries of declaring the return type... page of the Apress web site) This project is located in the 02.01 - Hello Objective-C folder To create the project, start by launching Xcode You can find the Xcode application in /Developer/Applications We put the Xcode icon in the Dock for easy access You might want to do that too Once Xcode finishes launching, you’ll see the Welcome screen, as shown in Figure 2-1 On the left side, you can select the next... the search field, and check the Treat Warnings as Errors checkbox, as shown in the following image Also make sure that the Configuration pop-up menu at the top says All 15 16 Chapter 2: Extensions to C Here’s another cool fact about NSString: the name itself highlights one of the nice features of Cocoa Most Cocoa elements are named in a very straightforward manner, striving to describe the features they... We then look in the argv array to see what that file path is argv[1] contains the filename the user has given us (In case you’re curious, the argv[0] parameter holds the name of the program.) If you’re running the program in Terminal, it’s easy to specify the name of the file on the command line, like so: $ /Word-Length-4 /tmp/words.txt Joe-Bob "Handyman" Brown is 24 characters long Jacksonville "Sly" Murphy... zero The Second Function The second function, boolString(), maps a numeric BOOL value to a string that’s readable by mere humans: NSString *boolString (BOOL yesNo) { if (yesNo == NO) { return (@"NO"); } else { return (@"YES"); } } // boolString The if statement in the middle of the function should come as no surprise It just compares yesNo to the constant NO, and returns @"NO" if they match Otherwise,... Andrew tonight Rather than driving across town, dropping off the books, and driving back, you ask your friendly neighbor to deliver the box This is another kind of indirection: you have someone else do the work instead of doing it yourself In programming, you can take indirection to multiple levels, writing code that consults other code, which accesses yet another level of code You’ve probably had the. .. action, we move on to our next project, 02.02 - BOOL Party, which compares pairs of integers to see if they’re different Aside from main(), the program defines two functions The first, areIntsDifferent(), takes two integer values and returns a BOOL: YES if the integers are different and NO if they are the same A second function, boolString(), takes a BOOL parameter and returns the string @"YES" if the . from the Mac App Store. To get there, click the App Store icon in the dock (see Figure 1-1), or find the App Store in the Applications folder. In the Mac. Extensions to C 13 The #import <Foundation/Foundation.h> statement tells the compiler to look at the Foundation.h header file in the Foundation framework. Introducing

Ngày đăng: 06/03/2014, 03:20

Từ khóa liên quan

Mục lục

  • Learn Objective-c on the Mac

    • Contents at a Glance

    • Contents

    • Foreword

    • About the Authors

    • About the Technical Reviewer

    • Acknowledgments

    • Working with This Book

    • Chapter 1: Hello

      • Before You Start

      • Where the Future Was Made Yesterday

      • What’s Coming Up

      • Getting Ready

      • Summary

      • Chapter 2: Extensions to C

        • The Simplest Objective-C Program

          • Building Hello Objective-C

          • Deconstructing Hello Objective-C

            • That Wacky #import Thing

            • Introducing Frameworks

            • NSLog() and @"strings"

              • The NS Prefix: A Prescription Against Name Collisions

              • NSString : Where it’s @

              • Are You the Boolean Type?

                • Mighty BOOL in Action

                  • The First Function

                  • The Second Function

                  • The Comparison Itself

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan