1. Trang chủ
  2. » Công Nghệ Thông Tin

Objective-C Recipes doc

453 2,2K 0

Đ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

Cấu trúc

  • Cover

    • Contents at a Glance

    • Contents

    • About the Author

    • About the Technical Reviewer

    • Acknowledgments

    • Preface

  • Application Development

    • 1.1 Creating a Terminal Application

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.2 Writing to the Console

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.3 Creating a New Custom Class

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.4 Code Property Assessors

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.5 Code Property Assessors with @synthesize

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.6 Adding a Class Method to a Custom Class

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.7 Adding an Instance Method to a Custom Class

      • Problem

      • Solution

      • How It Works

      • Usage

    • 1.8 Extending a Class with a Category

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.9 Creating a Mac Window-Based Application from Terminal

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.10 Adding a User Control to a Mac Application

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.11 Creating a Mac Window-Based Application From Xcode

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.12 Creating an iOS Application from Xcode

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.13 Adding User Controls to an iOS Application with Target-Action

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 1.14 Adding User Controls to an iOS Application with Delegation

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

  • Working With Strings and Numbers

    • 2.1 Creating a String Object

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.2 Reading Strings from Files on a Mac

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.3 Reading Strings from Files on iOS

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.4 Writing Strings to Files on a Mac

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.5 Writing Strings To Files On iOS

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.6 Comparing Strings

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.7 Manipulating Strings

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.8 Searching Through Strings

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.9 Localizing Strings

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.10 Converting Numbers to Strings

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.11 Converting Strings to Numbers

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 2.12 Formatting Numbers

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

  • Working with Object Collections

    • 3.1 Creating an Array

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.2 Referencing Objects in Arrays

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.3 Obtaining the Array Count

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.4 Iterating Through an Array

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.5 Sorting an Array

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.6 Querying an Array

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.7 Manipulating Array Contents

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.8 Saving Arrays to the File System

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.9 Reading Arrays from the File System

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.10 Creating a Dictionary

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.11 Referencing Objects in Arrays

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.12 Obtaining the Dictionary Count

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.13 Iterating Through a Dictionary

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.14 Manipulating Dictionary Contents

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.15 Saving Dictionaries to the File System

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.16 Reading Dictionaries from the File System

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.17 Creating a Set

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.18 Obtaining the Set Count

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.19 Comparing Sets

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.20 Iterating Through a Set

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 3.21 Manipulating Set Contents

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

  • File System

    • 4.1 Referencing and Using the File Manager

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.2 Getting Mac System Directory References

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.3 Getting Key iOS Directory References

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.4 Getting File Attributes

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.5 Getting the List of Files and SubDirectories in a Directory

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.6 Managing Directories

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.7 Managing Files

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.8 Checking File Status

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.9 Changing File Attributes

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.10 Using Delegation with NSFileManager

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.11 Working with Data Using NSData

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 4.12 Caching Content with NSCache

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

  • Working With Dates, Times, and Timers

    • 5.1 Creating a Date Object for Today

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 5.2 Creating Custom Dates by Component

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 5.3 Comparing Two Dates

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 5.4 Converting a String to a Date

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 5.5 Formatting Dates for Display

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 5.6 Adding and Subtracting Dates

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 5.7 Using a Timer to Schedule and Repeat Tasks

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

  • Asynchronous Processing

    • 6.1 Running a Process in a New Thread

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 6.2 Communicating Between the Main Thread and a Background Thread

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 6.3 Locking Threads with NSLock

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 6.4 Locking Threads with @synchronized

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 6.5 Asynchronous Processing with Grand Central Dispatch (GCD)

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 6.6 Using Serial Queues in GCD

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 6.7 Implement Asynchronous Processing Using NSOperationQueue

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

  • Consuming Web Content

    • 7.1 Downloading a File

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 7.2 Consuming a Web Service Using XML

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 7.3 Consuming a Web Service Using JSON

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 7.4 Asynchronously Consuming Web Content

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

  • Memory Management

    • 8.1 Understanding Memory Management

      • Problem

      • Solution

    • 8.2 Setting up an Application without ARC

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 8.3 Using Reference Counting to Manage Memory

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 8.4 Adding Memory Management to Your Custom Classes

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 8.5 Using Autorelease

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 8.6 Enabling Garbage Collection for Mac Applications

      • Problem

      • Solution

      • How It Works

  • Working with Object Graphs

    • Object-Orientated Vocabulary

    • 9.1 Creating an Object Graph

      • Problem

      • Solution

      • How It Works

      • Working with an Object Graph

      • The Code

      • Usage

    • 9.2 Using Key-Value Coding

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 9.3 Using Key Paths in Your Object Graph Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 9.4 Aggregating Information with Key Paths

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 9.5 Implementing the Observer Pattern

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 9.6 Inspecting Classes and Objects

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 9.7 Archiving Your Object Graph

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

  • Core Data

    • 10.1 Adding Core Data Support to an Application

      • Problem

      • Solution

      • How It Works

      • Link to Core Data Framework

      • Adding the Core Data Stack

      • The Code

      • Usage

    • 10.2 Adding an Entity Description

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 10.3 Adding a Managed Object to an Application

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 10.4 Adding a Managed Object to Core Data

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 10.5 Retrieving Objects from the Data Store

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 10.6 Posting Changes to the Data Store

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 10.7 Using One-To-One Relationships with Core Data

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 10.8 Using One-To-Many Relationships with Core Data

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 10.9 Managing Data Store Versioning

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

  • Objective-C Beyond Mac and iOS

    • 11.1 Installing GNUstep on Windows

      • Problem

      • Solution

      • How It Works

    • 11.2 Objective-C Hello World on Windows

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 11.3 Downloading Objective-J for Web Apps

      • Problem

      • Solution

      • How It Works

      • Usage

    • 11.4 Coding a Hello World Objective-J Application

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

    • 11.5 Adding a Button to an Objective-J Application

      • Problem

      • Solution

      • How It Works

      • The Code

      • Usage

  • Index

    • A, B

    • C

    • D, E

    • F

    • G, H

    • I

    • J

    • K, L

    • M, N

    • O, P, Q, R

    • S

    • T, U

    • V

    • W

    • X, Y, Z

Nội dung

[...]... Specifies the category for your app in the App Store 31 32 CHAPTER 1: Application Development Option Description Create DocumentBased Application Include the setup that you need to work with an NSDocumentbased application Document Extension Document extension associated with this app (for document-based apps) Use Core Data Automatically includes the Core Data Stack to be used for data persistence Use Automatic... NSLog(@"car is %@", car.name); Or you can use properties with standard Objective-C messaging: [car setName:@"New Car Name"]; NSLog(@"car.name is %@", [car name]); You will see both examples of accessing properties as you look at more Objective-C code Dot notation (the first example) is a relatively new Objective-C feature that was added with Objective-C 2.0 Note that dot notation has the advantage of being... Figure 1-3 CHAPTER 1: Application Development Figure 1-3 Window after action method executed 1.11 Creating a Mac Window-Based Application From Xcode Problem The recipes so far have simply been using the compiler from the command line to create Objective-C programs However, if you want to develop a rich Mac application, you need to use Xcode to get it ready for the App Store NOTE: The Mac App Store is... course, Car doesn’t do much until you add your own custom properties and methods, which you’ll see in the upcoming recipes 1.4 Code Property Assessors Problem Custom classes need to represent the attributes of the entities they are modeling You need to know how to define and implement properties in Objective-C to do this Solution To implement properties for custom classes, you must declare properties in the... rather Reference Counting manage memory yourself Include Unit Test Automatically includes setup that you need for unit testing your app Include Spotlight Importer An option for document-based applications to allow the app’s document files to be referenced by Spotlight After you choose your initial settings, click Next to choose your project location Here you may choose to use the version control system... maccommandlineapp, you will see output that looks something like this: car.name is Sports Car car.name is New Car Name logout [Process completed] 1.6 Adding a Class Method to a Custom Class Problem In Objective-C, you can send messages to either classes or objects to get things done If you want your custom class to be able to respond to a message, you must first code a class method Solution To add a... see output that looks something like this: Today's date is 2011-12-19 14:23:11 +0000 and this class represents a car logout [Process completed] 1.7 Adding an Instance Method to a Custom Class Problem In Objective-C, you can send messages to either classes or objects to get things done If you want objects that have been instantiated from your custom class to be able to respond to a message, you must first... New Car logout [Process completed] 1.8 Extending a Class with a Category Problem You would like to add methods and behavior to a class, but you would rather not create an entire new subclass Solution In Objective-C, you can use categories to define and implement properties and methods that can later be attached to a class To do this, you need two files: a header file to list your interface and an implementation... Objective-C 2.0 Note that dot notation has the advantage of being more familiar to programmers who are used to other programming languages where dot notation is the standard practice The second example, regular Objective-C messaging, is still used often Choosing one method over another is mostly a matter of personal preference See Listings 1-4 through 1-6 for the code The Code Listing 1-4 Car.h #import ... Development 1.5 Code Property Assessors with @synthesize Problem Custom classes need to represent the attributes of the entities they are modeling You need to know how to define and implement properties in Objective-C to do this If you don’t want to code your own getter and setter methods, you can use the @synthesize as an alternative Solution To implement properties with @synthesize, you still need to declare . compiles Objective-C programs. Here are some options that you may set when using clang to compile your Objective-C programs:  -fobj means that Objective-C. as you look at more Objective-C code. Dot notation (the first example) is a relatively new Objective-C feature that was added with Objective-C 2.0. Note

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