Programming in objective c by stephen g kochan pdf


 

This book is a tutorial for the computer programming language C. Unlike BASIC or. Pascal, C GNU c Introduction to C++ (and C) Programming. Stephen G. Kochan .. In , Kochan wrote Programming in Objective-C ( Sams,. ), and followed .. /usr/docs/classes/ruthenpress.info */. Kochan, Stephen G. Programming in Objective-C / Stephen G. Kochan. -- 2nd ed. p. cm. ISBN (pbk.) 1. Objective-C (Computer program.

Author:DELANA LEGREE
Language:English, Spanish, German
Country:Austria
Genre:Health & Fitness
Pages:192
Published (Last):01.12.2015
ISBN:788-8-44185-749-7
Distribution:Free* [*Register to download]
Uploaded by: CHRISTIA

69631 downloads 181392 Views 31.35MB PDF Size Report


Programming In Objective C By Stephen G Kochan Pdf

Stephen G. Kochan - pdf download free book. Programming In C . Kochan's most recent title, Programming in Objective-C, is a tutorial on an object-oriented. Download Programming in Objective-C (Developer's Library) by Stephen G. Kochan PDF. By Stephen G. Kochan. Updated for OS X Mavericks, iOS 7, and. Objective C Developers Library By Stephen G. Kochan EPUB KINDLE PDF EBOOK. Read Download Online Free Now Programming In.

All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the informa- tion contained herein. Kochan, Stephen G. Includes index. ISBN pbk. Objective-C Computer program language 2. Object-oriented programming Computer science 3. Macintosh Computer --Programming. K Pearson cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.

The purpose of this book is as its name implies: to teach you how toprogram in Objective-C 2. It does not profess to teach you in detail how to use the de-velopment tools that are available for entering and debugging programs, or to provide in-depth instructions on how to develop interactive graphical applications. In fact, mastering that material will be much easier when you have a solidfoundation of how to program in Objective-C.

This book does not assume much, if any,previous programming experience. This book teaches Objective-C by example.

As I present each new feature of the lan-guage, I usually provide a small complete program example to illustrate the feature. Just asa picture is worth a thousand words, so is a properly chosen program example. You arestrongly encouraged to run each program all of which are available online and comparethe results obtained on your system to those shown in the text. By doing so, you willlearn the language and its syntax, but you will also become familiar with the process ofcompiling and running Objective-C programs.

A framework is a set of classes and routines that have been logically grouped together tomake developing programs easier. Much of the power of programming in Objective-Crests on the extensive frameworks that are available.

So an ap-proach was needed to get input into a program and produce output. I also introduce the mechanism for defining a class and the means for sending messages to instances or objects. Instructors and seasoned Objective-C programmers will notice that I use static typing for declaring objects.

I think this is the best way for the student to get started because the compiler can catch more errors, making the programs more self-documenting and encouraging the new programmer to explicitly declare the data types when they are known. Making decisions is fundamental to any computer programming language. Details about methods, multiple arguments to methods, and local variables are discussed here.

This feature makes the development of programs easier because you can take advantage of what comes from above. Inheritance and the notion of subclasses make modifying and extending existing class definitions easy. Chapter 9 discusses three fundamental characteristics of the Objective-C language. Polymorphism, dynamic typing, and dynamic binding are the key concepts covered here.

Chapters 10—13 round out the discussion of the Objective-C language, covering issues such as initialization of objects, blocks, protocols, categories, the preprocessor, and some of the underlying C features, including functions, arrays, structures, and pointers.

These un- derlying features are often unnecessary and often best avoided when first developing object-oriented applications. Chapter 13 also introduces a recent addi- tion to the C language known as blocks. This should be learned after you learn about how to write functions, since the syntax of the former is derived from the latter. Chapters 15—19 cover important features of the Foundation framework.

These include number and string objects, collections, the file system, memory management, and the process of copying and archiving objects.

This chapter illustrates a step-by-step approach to writing a simple iOS appli-cation, followed by a more sophisticated calculator application that enables you to useyour iPhone to perform simple arithmetic calculations with fractions.

These classes define addresscard and address book classes. Methods enable you to perform simple operations such asadding and removing address cards from the address book, looking up someone, listingthe contents of the address book, and so on.

You might want to learn more about the underlying C programming language—oryou might want to start writing Cocoa programs to run on Mac OS X, or develop moresophisticated iOS applications. SupportIf you go to classroomM. The forum has turned into a rich community of active members whoare happy to help other members solve their problems and answer their questions.

Pleasego, join, and participate! AcknowledgmentsI would like to acknowledge several people for their help in the preparation of the firstedition of this text. I am also grateful to Mike Gaines for providing his input. I was lucky enough to have Mike review the first two editions of this text. Not only did he point outweaknesses, but he was also generous enough to offer his suggestions.

Having the cover art from a friend made the book even more special. I am so grateful to Mark Taber for all editions from Pearson for putting up with all delays and for being kind enough to work around my schedule and to tolerate my consis- tent missing of deadlines while working on the second and third editions.

I am extremely grateful to Michael de Haan and Wendy Mui for doing an incredible, unsolicited job proofreading the second edition and thanks Wendy for your work on the third edition as well. Their meticulous attention to detail has resulted in a list of both typographical and substantive errors that have been addressed in the second printing.

Publishers take note: these two pairs of eyes are priceless! Stephen G. All rights reserved.

Books: Programming in Objective-C - Stephen G. ruthenpress.info

Make changes to the program shown in theEdit window to match Program 2. You can begin by creat-ing a directory in which to store your program examples. Then you must run a text edi-tor, such as vi or emacs, to enter your program:sh For Objective-C files, you can choose any name you want; just make sure the last twocharacters are.

This indicates to the compiler that you have an Objective-C program. This is the general format of thegcc command:gcc —framework Foundation files -o progname This option says to use information about the Foundation framework:-framework Foundation Just remember to use this option on your command line. Therefore, I suggest you start learning to useXcode to develop your programs.

There is a learning curve to do this, but the effort willbe well worth it in the end. You can use this to your advantage in developing programs that are easier to read. The first seven lines of the program introduce the concept of the comment.

A commentstatement is used in a program to document a program and enhance its readability. You can insert comments into an Objective-C program in two ways. The compiler ignores any characters that follow these slashes, up to the end of the line. This marks the beginning of the comment. These types of comments have to be terminated. Methods allow manipulation of fractions, such as addition, subtraction, etc. Get into the habit of inserting comment statements in the program as you write it or type it into the computer, for three good reasons.

First, documenting the program while the particular program logic is still fresh in your mind is far easier than going back and rethinking the logic after the program has been completed. Second, by inserting com- ments into the program at such an early stage of the game, you can reap the benefits of the comments during the debug phase, when program logic errors are isolated and debugged.

Not only can a comment help you and others read through the program, but it also can help point the way to the source of the logic mistake. Inserting comments while developing the program makes this sometimes tedious task a bit easier to handle. This next line of Program 2.

You imported the file Foundation. In Program 2. The reserved word int that precedes main specifies the type of value main returns,which is an integer more about that soon. This is done by enclosing all the program statements of theroutine within a pair of curly braces. In the simplest case, a statement is just an expressionthat is terminated with a semicolon. The system treats all the program statements includedbetween the braces as part of the main routine.

Program 2. The first statement in Program 2. The next statement specifies that a routine named NSLog is to be invoked, or called. Collectively, this is known as a constant NSString object. Note If you have C programming experience, you might be puzzled by the leading character. Without that leading character, you are writing a constant C-style string; with it, you are writing an NSString string object.

More on this topic in Chapter The NSLog routine is a function in the Objective-C library that simply displays or logsits argument or arguments, as you will see shortly. You must terminate all program statements in Objective-C with a semicolon ;. Thisis why a semicolon appears immediately after the closed parenthesis of the NSLog call. Before you exit your program, you should release the allocated memory pool andobjects that are associated with it with a line such as the following:[pool drain]; Again, Xcode automatically inserts this line into your program for you.

Again, we deferdetailed explanation of what this does until later. Instance Variables are Stored in Structures Fact 2: He has been programming on Macintosh computers since the introduction of the first Mac in , and he wrote Programming C for the Mac as part of the Apple Press Library.

She got hooked on programming while earning a B. Michael Trent has been programming in Objective-C since —and programming Macs since well before that. He lives in Santa Clara, California, with his lovely wife,Angela.

We Want to Hear from You! As the reader of this book, you are our most important critic and commentator. Please note that we cannot help you with technical problems related to the topic of this book, and that due to the high volume of mail we receive, we might not be able to reply to every message. At first,Apple did not welcome third- party application development. Developers were not satisfied with the many inherent limitations of web-based applications, and Apple shortly there- after announced that developers would be able to develop so-called native applications for the iPhone.

The availability of an iPhone simulator made it possible for developers to debug their applications directly on their development system, obviating the need to download and test the program on an actual iPhone or iPod Touch device.

With the introduction of the iPad in ,Apple started to genericize the terminol- ogy used for the operating system and the SDK that now support different devices with different physical sizes and screen resolutions.

Programming in Objective-C, 3rd Edition

As with other texts on Objective-C, I could write mine to assume that the reader already knew how to write C programs. I could also teach the language from the perspective of using the rich library of routines, such as the Foundation and UIKit frameworks. I had several problems adopting this approach. First, learning the entire C language be- fore learning Objective-C is wrong. C is a procedural language containing many features that are not necessary for programming in Objective-C, especially at the novice level.

In fact, resorting to some of these features goes against the grain of adhering to a good ob- ject-oriented programming methodology. This starts the program- mer in the wrong direction, and gives the wrong orientation and mindset for fostering a good object-oriented programming style. Instead, I decided to take the unconventional approach of teaching Objective-C and the underlying C language as a single integrated language, from an object-oriented program- ming perspective.

The purpose of this book is as its name implies: It does not profess to teach you in detail how to use the de- velopment tools that are available for entering and debugging programs, or to provide in- depth instructions on how to develop interactive graphical applications. In fact, mastering that material will be much easier when you have a solid foundation of how to program in Objective-C.

This book does not assume much, if any, previous programming experience. You might want to learn more about the underlying C programming language—oryou might want to start writing Cocoa programs to run on Mac OS X, or develop moresophisticated iOS applications. SupportIf you go to classroomM.

The forum has turned into a rich community of active members whoare happy to help other members solve their problems and answer their questions. Pleasego, join, and participate! AcknowledgmentsI would like to acknowledge several people for their help in the preparation of the firstedition of this text.

I am also grateful to Mike Gaines for providing his input. I was lucky enough to have Mike review the first two editions of this text. Not only did he point outweaknesses, but he was also generous enough to offer his suggestions.

Having the cover art from a friend made the book even more special. I am so grateful to Mark Taber for all editions from Pearson for putting up with all delays and for being kind enough to work around my schedule and to tolerate my consis- tent missing of deadlines while working on the second and third editions.

I am extremely grateful to Michael de Haan and Wendy Mui for doing an incredible, unsolicited job proofreading the second edition and thanks Wendy for your work on the third edition as well. Their meticulous attention to detail has resulted in a list of both typographical and substantive errors that have been addressed in the second printing. Publishers take note: these two pairs of eyes are priceless!

Stephen G. All rights reserved. Make changes to the program shown in theEdit window to match Program 2. You can begin by creat-ing a directory in which to store your program examples. Then you must run a text edi-tor, such as vi or emacs, to enter your program:sh For Objective-C files, you can choose any name you want; just make sure the last twocharacters are. This indicates to the compiler that you have an Objective-C program.

This is the general format of thegcc command:gcc —framework Foundation files -o progname This option says to use information about the Foundation framework:-framework Foundation Just remember to use this option on your command line.

Therefore, I suggest you start learning to useXcode to develop your programs.

PDF Programming in Objective-C Stephen Kochan Full Book

There is a learning curve to do this, but the effort willbe well worth it in the end. You can use this to your advantage in developing programs that are easier to read. The first seven lines of the program introduce the concept of the comment. A commentstatement is used in a program to document a program and enhance its readability.

You can insert comments into an Objective-C program in two ways. The compiler ignores any characters that follow these slashes, up to the end of the line. This marks the beginning of the comment. These types of comments have to be terminated. Methods allow manipulation of fractions, such as addition, subtraction, etc.

Get into the habit of inserting comment statements in the program as you write it or type it into the computer, for three good reasons.

First, documenting the program while the particular program logic is still fresh in your mind is far easier than going back and rethinking the logic after the program has been completed. Second, by inserting com- ments into the program at such an early stage of the game, you can reap the benefits of the comments during the debug phase, when program logic errors are isolated and debugged. Not only can a comment help you and others read through the program, but it also can help point the way to the source of the logic mistake.

Inserting comments while developing the program makes this sometimes tedious task a bit easier to handle. This next line of Program 2. You imported the file Foundation.

In Program 2. The reserved word int that precedes main specifies the type of value main returns,which is an integer more about that soon.

This is done by enclosing all the program statements of theroutine within a pair of curly braces. In the simplest case, a statement is just an expressionthat is terminated with a semicolon. The system treats all the program statements includedbetween the braces as part of the main routine.

Program 2. The first statement in Program 2. The next statement specifies that a routine named NSLog is to be invoked, or called. Collectively, this is known as a constant NSString object. Note If you have C programming experience, you might be puzzled by the leading character.

Without that leading character, you are writing a constant C-style string; with it, you are writing an NSString string object.

More on this topic in Chapter The NSLog routine is a function in the Objective-C library that simply displays or logsits argument or arguments, as you will see shortly. You must terminate all program statements in Objective-C with a semicolon ;. Thisis why a semicolon appears immediately after the closed parenthesis of the NSLog call.

Before you exit your program, you should release the allocated memory pool andobjects that are associated with it with a line such as the following:[pool drain]; Again, Xcode automatically inserts this line into your program for you.

Again, we deferdetailed explanation of what this does until later. By convention, 0 means that the program ended normally. You should understand what that message means now. Remember that every Objective-C program statement must be terminated by a semicolon. Programming in Objective-C is even more fun! A newline character tells the system to do precisely what its name implies: go to a new line. Any characters to be printed after the newline character then appear on the next line of the display.

In fact, the newline character is very similar in concept to the carriage return key on a typewriter remember those? Displaying the Values of Variables 21 Study the program listed in Program 2.

You must define all program variables before you canuse them in a program. The definition of a variable specifies to the Objective-C compilerhow the program should use it. The compiler needs this information to generate the 22 Chapter 2 Programming in Objective-C correct instructions to store and retrieve values into and out of the variable.

A variable defined as type int can be used to hold only integral values—that is, values without deci- mal places. Examples of integral values are 3, 5, —20, and 0. Numbers with decimal places, such as 2. The integer variable sum stores the result of the addition of the two integers 50 and We have intentionally left a blank line following the definition of this variable to visually separate the variable declarations of the routine from the program statements; this is strictly a matter of style.

Sometimes adding a single blank line in a program can make the program more readable. The NSLog routine call in Program 2. These arguments are separated by a comma. The first argument to the NSLog routine is always the character string to be displayed. However, along with the display of the character string, you often want to have the value of certain program variables dis- played as well. In this case, you want to have the value of the variable sum displayed after these characters are displayed: The sum of 50 and 25 is The percent character inside the first argument is a special character recognized by the NSLog function.

The character that immediately follows the percent sign specifies what type of value is to be displayed at that point. In the previous program, the NSLog routine recognizes the letter i as signifying that an integer value is to be displayed. Now try to predict the output from Program 2. This statement could have equivalently been expressedusing three separate statements, as follows:int value1;int value2;int sum; After the three variables have been defined, the program assigns the value 50 to thevariable value1 and then the value 25 to value2.

The sum of these two variables is thencomputed and the result assigned to the variable sum. The call to the NSLog routine now contains four arguments. Once again, the firstargument, commonly called the format string, describes to the system how theremaining arguments are to be displayed. SummaryAfter reading this introductory chapter on developing programs in Objective-C, youshould have a good feel of what is involved in writing a program in Objective-C—andyou should be able to develop a small program on your own.

Similar files:


Copyright © 2019 ruthenpress.info. All rights reserved.
DMCA |Contact Us