Learning Objective-C 2.0: A Hands-on Guide to Objective-C for Mac and iOS Developers, Second Edition

Book description

Get Started Fast with Objective-C 2.0 Programming for OS X Mountain Lion, iOS 5.1, and Beyond

Fully updated for Xcode 4.4, Learning Objective-C 2.0, Second Edition, is today’s most useful beginner’s guide to Objective-C 2.0. One step at a time, it will help you master the newest version of Objective-C 2.0 and start writing high-quality programs for OS X 10.8 Mountain Lion, iOS 5.1, and all of Apple’s newest computers and devices.

Top OS X and iOS developer Robert Clair first reviews the essential object and C concepts that every Objective-C 2.0 developer needs to know. Next, he introduces the basics of the Objective-C 2.0 language itself, walking through code examples one line at a time and explaining what’s happening behind the scenes.

This revised edition thoroughly introduces Apple’s new Automated Reference Counting (ARC), while also teaching conventional memory-management techniques that remain indispensable. Carefully building on what you’ve already learned, Clair progresses to increasingly sophisticated techniques in areas ranging from frameworks to security. Every topic has been carefully chosen for its value in real-world, day-to-day programming, and many topics are supported by hands-on practice exercises.

Coverage includes

·      Reviewing key C techniques and concepts, from program structure and formats to variables and scope

·      Understanding how objects and classes are applied in Objective-C 2.0

·      Writing your first Objective-C program with Xcode 4.4

·      Using messaging to efficiently perform tasks with objects

·      Getting started with Apple’s powerful frameworks and foundation classes

·      Using Objective-C control structures, including Fast Enumeration and exception handling

·      Adding methods to classes without subclassing

·      Using declared properties to save time and simplify your code

·      Mastering ARC and conventional memory management, and knowing when to use each

·      Using Blocks to prepare for concurrency with Apple’s Grand Central Dispatch

·      Leveraging Xcode 4.4 improvements to enums and @implementation

Table of contents

  1. Title Page
  2. Copyright Page
  3. Praise for the First Edition of Learning Objective-C 2.0
  4. Dedication Page
  5. Contents at a Glance
  6. Contents
  7. Preface
    1. About This Book
    2. Who Should Read This Book
    3. What You Need to Know
    4. About the Examples
    5. About the Exercises
    6. Objective-C—A Moving Target
    7. ARC or Not
    8. How This Book Is Organized
    9. We Want to Hear from You!
    10. Reader Services
  8. Acknowledgments
  9. About the Author
  10. Part I: Introduction to Objective-C
    1. 1. C, the Foundation of Objective-C
      1. The Structure of a C Program
      2. Variables
      3. Operators
      4. Expressions and Statements
      5. Program Flow
      6. Preprocessor
      7. Command Line Compiling and Debugging
      8. Summary
      9. Exercises
    2. 2. More about C Variables
      1. Memory Layout of a C Program
      2. Automatic Variables
      3. External Variables
      4. Declaration Keywords
      5. Scope
      6. Dynamic Allocation
      7. Summary
      8. Exercises
    3. 3. An Introduction to Object-Oriented Programming
      1. Object-Oriented Programming
      2. An Introduction to Objective-C
      3. Objective-C Additions
      4. Summary
    4. 4. Your First Objective-C Program
      1. Building with Xcode
      2. Objective-C Program Structure
      3. An Object-Oriented “Hello World”
      4. main.m
      5. Summary
      6. Exercises
  11. Part II: Language Basics
    1. 5. Messaging
      1. Methods
      2. Messaging
      3. Messaging Details
      4. Under the Hood
      5. Message Forwarding
      6. Efficiency
      7. Introspection and Other Runtime Fun
      8. Summary
      9. Exercises
    2. 6. Classes and Objects
      1. Defining a Class
      2. Subclassing a Class
      3. Creating Objects
      4. Destroying Objects
      5. Copying Objects
      6. Summary
      7. Exercises
    3. 7. The Class Object
      1. Class Objects
      2. Other Class Methods
      3. Mimicking Class Variables
      4. Summary
      5. Exercises
    4. 8. Frameworks
      1. What Is a Framework?
      2. Cocoa and Cocoa Touch
      3. AppKit
      4. UIKit
      5. Core Foundation
      6. Core Graphics
      7. Core Animation
      8. Other Apple-Supplied Frameworks
      9. Third-Party Frameworks
      10. Under the Hood
      11. Summary
    5. 9. Common Foundation Classes
      1. Immutable and Mutable Classes
      2. Class Clusters
      3. NSString
      4. Collection Classes
      5. NSNumber
      6. NSNull
      7. NSData
      8. NSURL
      9. Objective-C Literals and Object Subscripting
      10. Structures
      11. Geometry Structures on iOS
      12. Summary
      13. Exercises
    6. 10. Control Structures in Objective-C
      1. if Statements
      2. for Statements and Implicit Loops
      3. while Statements and NSEnumerator
      4. Fast Enumeration
      5. An Example Using Fast Enumeration
      6. Exceptions
      7. Summary
      8. Exercises
    7. 11. Categories, Extensions, and Security
      1. Categories
      2. Associative References
      3. Extensions
      4. Instance Variable Scope (Access Control)
      5. Hiding Your Instance Variable Declarations
      6. Access Control for Methods
      7. Namespaces
      8. Security
      9. Calling C Functions from Objective-C
      10. Summary
      11. Exercises
    8. 12. Properties
      1. Accessing Instance Variables Outside of an Object (Don’t Do It)
      2. Declaring and Implementing Accessors
      3. Accessors Using Properties
      4. Synthesized Instance Variables
      5. @synthesize by Default
      6. Synthesis Summary
      7. Private Properties
      8. The @property Statement
      9. More about @dynamic
      10. Properties without Instance Variables
      11. Properties and Memory Management
      12. A Look Ahead at Automatic Reference Counting (ARC)
      13. Subclassing and Properties
      14. Hidden Setters for readonly Properties
      15. Properties as Documentation
      16. Dot Syntax
      17. Summary
      18. Exercises
    9. 13. Protocols
      1. The Rationale for Protocols
      2. Using Protocols
      3. TablePrinter Example
      4. Protocol Objects and Testing for Conformance
      5. Informal Protocols
      6. Summary
      7. Exercises
  12. Part III: Advanced Concepts
    1. 14. Memory Management Overview
      1. The Problem
      2. The Solutions: Objective-C Memory Management
      3. Onward
    2. 15. Reference Counting
      1. Reference Counting Basics
      2. Receiving Objects
      3. Ownership
      4. dealloc
      5. Returning Objects
      6. retainCount
      7. Multithreading
      8. When Retain Counts Go Bad
      9. Retain Cycles
      10. The Final Goodbye: When Programs Terminate
      11. Summary
      12. Exercises
    3. 16. ARC
      1. What ARC Is and Is Not
      2. How ARC Works
      3. ARC Imposes Some Rules
      4. New Variable Qualifiers
      5. Properties
      6. Retain Cycles
      7. ARC and Core Foundation
      8. Casting to and from void*
      9. ARC and Extra Autorelease Pools
      10. ARC and Exceptions
      11. Using ARC
      12. ARC Uses Runtime Functions
      13. More Information
      14. Summary
      15. Exercises
    4. 17. Blocks
      1. Function Pointers
      2. NSInvocation
      3. Blocks
      4. Some Philosophical Reservations
      5. Summary
      6. Exercises
    5. 18. A Few More Things
      1. Enums with a Fixed Underlying Type
      2. Forward Declarations of Methods in the @implementation Block Are No Longer Needed
      3. Some New Documentation
      4. Summary
      5. Exercises
  13. Part IV: Appendices
    1. A. Reserved Words and Compiler Directives
    2. B. Toll-Free Bridged Classes
    3. C. 32- and 64-Bit
      1. Kernel and User Programs in 64-Bit
      2. Coding Differences for 64-Bit Programs
      3. Performance
      4. Compiling for 32-Bit and 64-Bit
      5. More Information
    4. D. The Fragile Base Class Problem
    5. E. Resources for Objective-C
      1. Apple Resources
      2. Internet Resources
      3. Groups
      4. Books
  14. Index
  15. Footnotes
    1. Preface
    2. Chapter 1
    3. Chapter 2
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 11
    11. Chapter 12
    12. Chapter 13
    13. Chapter 17

Product information

  • Title: Learning Objective-C 2.0: A Hands-on Guide to Objective-C for Mac and iOS Developers, Second Edition
  • Author(s): Robert Clair
  • Release date: November 2012
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780133047462