You are previewing Sams Teach Yourself Objective-C in 24 Hours, Second Edition.
O'Reilly logo
Sams Teach Yourself Objective-C in 24 Hours, Second Edition

Book Description

Full-color figures and code appear as they do in Xcode 5.

In just 24 sessions of one hour or less, you can master the Objective-C language and start using it to write powerful native applications for even the newest Macs and iOS devices! Using this book’s straightforward, step-by-step approach, you’ll get comfortable with Objective-C’s unique capabilities and Apple’s Xcode 5 development environment…make the most of Objective-C objects and messaging…work effectively with design patterns, collections, blocks, Foundation Classes, threading, Git…and a whole lot more. Every lesson builds on what you’ve already learned, giving you a rock-solid foundation for real-world success!

Step-by-Step Instructions carefully walk you through the most common Objective-C development tasks.
Quizzes and Exercises at the end of each chapter help you test your knowledge.
Notes present information related to the discussion.
Tips offer advice or show you easier ways to perform tasks.
Cautions alert you to possible problems and give you advice on how to avoid them.

• Use Xcode 5 to write modern Objective-C software more quickly and efficiently
• Master Objective-C’s object-oriented features and techniques
• Manage projects more efficiently with the Git source code repository
• Write more dynamic code with Objective-C’s powerful messaging architecture
• Declare classes, instance variables, properties, methods, and actions
• Work with mutable and immutable data types
• Organize data with collections, including arrays, dictionaries, and sets
• Painlessly manage memory with Automatic Reference Counting (ARC)
• Expand and extend classes with protocols, delegates, categories, and extensions
• Get started with Apple’s powerful classes and frameworks
• Create and work with code blocks
• Manage queues and threading with Grand Central Dispatch

Table of Contents

  1. About This eBook
  2. Title Page
  3. Copyright Page
  4. Contents at a Glance
  5. Table of Contents
  6. About the Author
  7. Acknowledgments
  8. We Want to Hear from You!
  9. Reader Services
  10. Introduction
    1. Who Should Read This Book
    2. What This Book Covers
    3. Downloading the Sample Files
    4. How This Book Is Organized
  11. Part I: Getting Started with Objective-C
    1. Hour 1. Overview of the Developer Program
      1. Introducing Objective-C
      2. Enrolling as an Apple Developer
      3. Choosing Your Program
      4. Setting Up the Development Environment
      5. Summary
      6. Q&A
      7. Workshop
    2. Hour 2. Object-Oriented Programming with Objective-C
      1. Object-Oriented Programming in the Objective-C World
      2. Creating C with Objects
      3. Managing Inheritance in the Objective-C World
      4. Summary
      5. Q&A
      6. Workshop
    3. Hour 3. Using Object-Oriented Features in Objective-C
      1. Communicating to Methods with Messages
      2. Allocating and Initializing Objects
      3. Summary
      4. Q&A
      5. Workshop
    4. Hour 4. Using Xcode 5
      1. Getting to Work with Xcode
      2. Keeping Track of Your Source Code
      3. Using a Remote Repository
      4. Summary
      5. Q&A
      6. Workshop
    5. Hour 5. Using Compiler Directives
      1. Exploring Your Projects
      2. Working with Compiler Directives
      3. Using Objective-C Compiler Directives
      4. Summary
      5. Q&A
      6. Workshop
  12. Part II: Working with the Objective-C Basics
    1. Hour 6. Exploring Messaging and a Testbed App
      1. Setting Up the Testbed Apps
      2. Adding a Text Field and Connecting It to Your Code
      3. Sending a Message to the Text Field
      4. Reviewing the Message Syntax
      5. Summary
      6. Q&A
      7. Workshop
    2. Hour 7. Declaring a Class in an Interface File
      1. Letting Xcode Do the Work
      2. Exploring Class Hierarchies
      3. Declaring Classes
      4. Summary
      5. Q&A
      6. Workshop
    3. Hour 8. Declaring Instance Variables in an Interface File
      1. Declaring Instance Variables and Properties
      2. Using the Class
      3. Creating an Instance Variable for CurrencyConverter with id
      4. Creating an Instance Variable for CurrencyConverter with the Class Name
      5. Creating an Instance Variable for CurrencyConverter with a Superclass Name
      6. Managing Instance Variable Visibility
      7. Summary
      8. Q&A
      9. Workshop
    4. Hour 9. Declaring Properties in an Interface File
      1. Comparing Interface Variables and Properties
      2. Using Declared Properties
      3. Using Attributes
      4. Implementing Properties
      5. Summary
      6. Q&A
      7. Workshop
    5. Hour 10. Declaring Methods in an Interface File
      1. Working with Methods in a Class
      2. Reviewing Method Syntax
      3. Summary
      4. Q&A
      5. Workshop
    6. Hour 11. Declaring Actions in an Interface File
      1. Introducing Actions
      2. Comparing Actions in OS X and iOS
      3. Summary
      4. Q&A
      5. Workshop
    7. Hour 12. Routing Messages with Selectors
      1. Getting Inside Objective-C Messages
      2. Getting Inside the Objective-C Runtime
      3. Working with SEL and @selector ()
      4. Using performSelector
      5. Using NSInvocation
      6. Testing Whether an Instance Can Respond to a Selector
      7. Summary
      8. Q&A
      9. Workshop
    8. Hour 13. Building on the Foundation
      1. Exploring the Foundation Framework
      2. Foundation Classes
      3. Foundation Paradigms and Policies
      4. Summary
      5. Q&A
      6. Workshop
    9. Hour 14. Defining a Class in an Implementation File
      1. Working with a New Project
      2. Creating a New App
      3. Implementing a Method
      4. Expanding the Class with init Methods
      5. Summary
      6. Q&A
      7. Workshop
    10. Hour 15. Organizing Data with Collections
      1. Collecting Objects
      2. Getting Familiar with Property Lists
      3. Comparing the Collection Classes
      4. Creating a Collection
      5. Using Objective-C Literal Syntax
      6. Enumerating a Collection
      7. Testing Membership in a Collection
      8. Accessing an Object in a Collection
      9. Summary
      10. Q&A
      11. Workshop
    11. Hour 16. Managing Memory and Runtime Objects
      1. Managing Objects in Memory
      2. Managing Reference Counts Manually
      3. Managing Reference Counts with ARC
      4. Variable Qualifiers
      5. Autoreleasing Variables
      6. Summary
      7. Q&A
      8. Workshop
  13. Part III: Expanding and Extending Classes
    1. Hour 17. Extending a Class with Protocols and Delegates
      1. Exploring the Pros and Cons of Subclassing
      2. Introducing the Example
      3. Working with Protocols
      4. Working with Delegates
      5. Putting Protocols and Delegates Together
      6. Looking Deeper Inside Protocols
      7. Summary
      8. Q&A
      9. Workshop
    2. Hour 18. Extending a Class with Categories and Extensions
      1. Comparing Categories and Protocols
      2. Comparing Categories with Subclasses
      3. Working with Categories
      4. Using Class Extensions
      5. Working with Informal Protocols
      6. Summary
      7. Q&A
      8. Workshop
    3. Hour 19. Using Associative References and Fast Enumeration
      1. Catching Up on Objective-C 2.0 Time-Saving Features
      2. Extending Classes by Adding Instance Variables (Sort of)
      3. Using Fast Enumeration
      4. Summary
      5. Q&A
      6. Workshop
    4. Hour 20. Working with Blocks
      1. Revisiting Blocks
      2. Looking at Callbacks
      3. Introducing Blocks
      4. Exploring Blocks in Cocoa
      5. Looking Deeper into Cocoa Blocks and Memory
      6. Summary
      7. Q&A
      8. Workshop
  14. Part IV: Beyond the Basics
    1. Hour 21. Handling Exceptions and Errors
      1. Rethinking Exceptions and Errors
      2. Introducing the Exception and Error Classes
      3. Identifying an Exception
      4. Throwing an Exception
      5. Catching an Exception
      6. Summary
      7. Q&A
      8. Workshop
    2. Hour 22. Grand Central Dispatch: Using Queues and Threading
      1. Getting Started with Concurrency
      2. Introducing Queues
      3. Using Dispatch Queues
      4. Summary
      5. Q&A
      6. Workshop
    3. Hour 23. Working with the Debugger
      1. Logging Information
      2. Using Console Logs
      3. Using Smart Breakpoints
      4. Summary
      5. Q&A
      6. Workshop
    4. Hour 24. Using Xcode Debug Gauges for Analysis
      1. Putting Debug Gauges in Perspective
      2. Using Instruments
      3. Summary
      4. Q&A
      5. Workshop
  15. Part V: Appendixes
    1. Appendix A. C Syntax Summary
      1. Data Types
      2. Control Structures
    2. Appendix B. Apps, Packages, and Bundles
      1. Looking Inside a Project Bundle
      2. lproj Files
      3. Asset Catalogs
      4. plist Files
      5. Precompiled Header Files (.pch)
    3. Appendix C. Archiving and Packaging Apps for Development and Testing
      1. Archiving
  16. Index