Objective-C For Dummies
Format: PDF / Kindle (mobi) / ePub
Learn the primary programming language for creating iPhone and Mac apps
The only thing hotter than the iPhone right now is new apps for the iPhone. Objective-C is the primary language for programming iPhone and Mac OS X applications, and this book makes it easy to learn Objective-C.
Even if you have no programming experience, Objective-C For Dummies will teach you what you need to know to start creating iPhone apps. It provides an understanding of object-oriented programming in an entertaining way that helps you learn.
- iPhone and Mac apps are hot, and most are created with Objective-C
- Covers Xcode 3.2, which is included in Mac OS X Snow Leopard
- Explains object-oriented programming concepts in a straightforward but fun style that makes learning easy
- Ideal for those with no programming experience as well as those who may know other languages but are new to Objective-C
- Prepares you to start creating iPhone and Mac OS X apps
- Understand Mac programming concepts and patterns, and why to use them
- Bonus CD includes all code samples used in the book
Objective-C For Dummies gives you the tools to turn your idea for an iPhone app into reality.
Note: CD-ROM/DVD and other supplementary materials are not included as part of eBook file.
complete line in the Project window. Now, explore the statement NSLog(@”Hello, World!”); All it does is display (or print, if you like) “Hello World” on the Debugger Console. To start with, NSLog is a function, just like main. Inside of it is a string (a variable that stores more than a single non-numerical character is known as a string). @”Hello, World!” The @ sign before the quotation mark tells the compiler that this is not a C string. It is actually a Cocoa object called an NSString that has
see Figure 2-34). Figure 2-34: Getting quick help. The header file for a symbol Headers are a big deal in code because they’re the place where you find the class declaration, which includes all of its instance variables and method declarations — you learn about classes and headers in Chapter 6). To get the header file for a symbol, press Ô and double-click the symbol in the Text Editor (for example, see Figure 2-35, where I pressed Ô and then doubleclicked NSLog). This works for you classes as
necessary to reach a goal. Functions in a procedural program are more like the command and control structure of a large corporation (think GM) or the army. Which is more flexible? So let’s get on with understanding objects. Understanding How Objects Behave An object-oriented program consists of a network of interconnected objects, essentially modules that call upon each other to solve a part of the puzzle. The objects work like a team. Each object has a specific role to play in the overall
especially relevant in the following code. As I said, I’ll show you a way to have a single string on multiple lines in the section “Using Constants.” NSLog(@” A char = %i bytes”, sizeof(char)); NSLog(@” An unsigned char = %i bytes”, sizeof(unsigned char)); NSLog(@” A short = %i bytes”, sizeof(short)); NSLog(@” An unsigned short = %i bytes”, sizeof(unsigned short)); NSLog(@” An int = %i bytes”, sizeof(int)); 91 92 Part II: Speaking the Language of Objective-C NSLog(@” An unsigned int = %i
two budgets, vacationBudget Europe and vacationBudgetEngland, I need a way to let the function know which budget it should update. One way would be to have a set of functions for each country. I could create spendDollarsInEurope and spendDollarsInEngland functions (and corresponding chargeForeignCurrencyEurope and chargeForeignCurrencyEngland functions that would convert euros and pounds into dollars ,respectively), and each one them would update the corresponding budget. For example: void