Suchen und Finden
Service
More iPhone 3 Development - Tackling iPhone SDK 3
David Mark, Jeff LaMarche
Verlag Apress, 2010
ISBN 9781430225065 , 552 Seiten
Format PDF, OL
Kopierschutz Wasserzeichen
Contents at a Glance
5
Table of contents
6
About the Authors
13
About the Technical Reviewer
14
Acknowledgments
15
Preface
16
Chapter 1 Here We Go Round Again
17
What This Book Is
17
What You Need to Know
17
What You Need Before You Can Begin
18
What’s In this Book
20
Are You Ready?
22
Chapter 2 The Anatomy of Core Data
24
A Brief History of Core Data
25
Creating a Core Data Template Application
25
Core Data Concepts and Terminology
27
The Data Model and Persistent Store
28
The Data Model Class: NSManagedObjectModel
29
The Persistent Store and the Persistent Store Coordinator
31
Reviewing the Data Model
33
Entities and the Data Model Editor
33
Entities
33
Properties
34
Attributes
34
Relationships
35
Fetched Properties
36
Fetch Requests
36
Managed Objects
36
Key-Value Coding
36
Managed Object Context
37
Saves on Terminate
38
Loading Data from the Persistent Store
39
The Fetched Results Controller
41
Creating a Fetched Results Controller
41
The Fetched Results Controller Delegate Methods
44
Will Change Content Delegate Method
44
Did Change Content Delegate Method
45
Did Change Object Delegate Method
45
Did Change Section Delegate Method
50
Retrieving a Managed Object from the Fetched ResultsController
51
Creating and Inserting a New Managed Object
51
Deleting Managed Objects
53
Putting Everything in Context
54
Chapter 3 A Super Start: Adding, Displaying, and Deleting Data
56
Setting up the Xcode Project
57
Application Architecture
58
Modifying the Application Delegate Interface
59
Adding to the Application Delegate Implementation
60
Creating the Table View Controller
61
Setting up Main Window.xib
62
Connecting the Outlets
65
Designing the Data Model
65
Adding an Entity
66
Editing the New Entity
67
Adding Attributes to the New Entity
69
Adding the Name Attribute
69
Editing the Attribute
70
Attribute Types
71
The Integer Datatypes
71
The Decimal, Double, and Float Datatypes
72
The String Datatype
72
The Boolean Datatype
72
The Date Datatype
72
The Binary Datatype
72
The Transformable Datatype
73
Setting the Name Attributes’s Type
73
Adding the Rest of the Attributes
74
Creating Hero List View Controller
75
Declaring the Fetched Results Controller
75
Drag Two Icons to Your Project
78
Designing the Hero List View Controller Interface
79
Implementing the Hero View Controller
81
Let ‘Er Rip
94
Done, but Not Done
96
Chapter 4 The Devil in the Detail View
97
Table-Based vs. Nib-Based Detail Views
98
Detail Editing View Challenges
99
Controlling Table Structure with Arrays
101
Paired Arrays
101
Nested Arrays
102
Paired Nested Arrays
103
Representing Our Table Structure with Arrays
103
Nested Arrays, Categorically Speaking
104
Updating the SuperDB Project
104
Formatting of Attributes
106
Creating the Detail View Controller
108
Declaring Instance Variables and Properties
110
Implementing the Viewing Functionality
111
Using the New Controller
117
Declaring the Outlet
117
Adding the Instance to MainWindow.xib
118
Pushing the New Instance onto the Stack
119
Trying Out the View Functionality
120
Adding Editing Subcontrollers
121
Creating the Superclass
122
Creating the String Attribute Editor
126
Creating the Date Attribute Editor
129
Using the Attribute Editors
132
Implementing a Selection List
134
Creating the Generic Selection List Controller
134
Devil’s End
139
Chapter 5 Preparing for Change: Migrations and Versioning
140
About Data Models
141
Data Models Are Compiled
141
Data Models Can Have Multiple Versions
142
Creating a New Data Model Version
143
The Current Data Model Version
144
Data Model Version Identifiers
144
Using the Versioned Data Model
145
Migrations
146
Lightweight vs. Standard
147
Standard Migrations
147
Setting up Your App to Use Lightweight Migrations
147
Time to Migrate On
149
Chapter 6 Custom Managed Objects
150
Updating the Data Model
153
Adding the Age Attribute
154
Adding the Favorite Color Attribute
154
Adding a Minimum Length to the Name Attribute
155
Creating the Hero Class
156
Tweaking the Hero Header
158
Defaulting
159
Validation
160
Single-Attribute Validations
161
Multiple-Attribute Validations
163
Virtual Accessors
164
Adding Validation Feedback
165
Updating the Managed Object Attribute Editor Header File
165
Updating the Managed Object Attribute Editor Implementation File
166
Updating the Subclasses to Use Validation
167
Updating ManagedObjectStringEditor
167
Updating ManagedObjectDateEditor
168
Updating ManagedObjectSingleSelectionListEditor
168
Creating the Value Transformer
168
Creating the Color Attribute Editor
171
Displaying the New Attributes in Hero Edit Controller
174
The Display Problem
176
Adding View-Only Support to Hero Edit Controller
178
Hiding the Disclosure Indicator
178
Handling Taps on Read-Only Attributes
179
Color Us Gone
180
Chapter 7 Relationships, Fetched Properties, and Expressions
181
Expanding Our Application: Superpowers and Reports
182
Relationships
184
To-One Relationships
185
To-Many Relationships
186
Inverse Relationships
188
Delete Rules
189
Fetched Properties
190
Creating Relationships and Fetched Properties in the Data Model Editor
191
Adding the Power Entity
191
Creating the Powers Relationship
192
Creating the Inverse Relationship
193
Creating the olderHeroes Fetched Property
193
Creating the youngerHeroes Fetched Property
197
Creating the sameSexHeroes Fetched Property
198
Creating the oppositeSexHeroes Fetched Property
199
Adding Relationships and Fetched Properties to the Hero Class
201
The Big Refactor
202
Renaming the Class
203
Refactoring the hero Instance Variable
205
Removing the Arrays
205
Supporting Save and Cancel Buttons
205
Adding the isNew Method to NSManagedObject
207
Adding the Save and Cancel Buttons
208
Adding Support for To-Many Relationships
209
Turning on Edit Mode
209
Setting Row Indentation
209
Setting the Correct Number of Rows for To-Many Sections
211
The Set Problem
211
Specifying the Editing Style for the Rows
213
Displaying To-Many Sections
213
Updating Row Selection for To-Many Relationships
217
Handling To-Many Inserts and Deletes
221
Using the New Generic Controller
223
Adding Factory Methods for Hero and Power
223
Deleting the Nib Instance
227
Updating HeroListController
227
Creating the Fetched Property Attribute Controller
228
Cleaning Up Deleted Objects
230
Wonderful to the Core
233
Chapter 8 Peer-to-Peer Over Bluetooth Using GameKit
235
This Chapter’s Application
236
Network Communication Models
239
Client-Server Model
239
Peer-to-Peer Model
240
Hybrid Client-Server/Peer-to-Peer
241
The GameKit Session
242
Creating the Session
242
Finding and Connecting to Other Sessions
243
Listening for Other Sessions
244
Sending Data to a Peer
244
Packaging Up Information to Send
245
Receiving Data from a Peer
246
Closing Connections
247
The Peer Picker
247
Creating the Peer Picker
247
Handling a Peer Connection
248
Creating the Session
248
Creating the Project
249
Turning Off the Idle Timer
249
Importing the GameKit Framework
250
Designing the Interface
251
Setting Up the View Controller Header
252
Designing the Game Board
256
Creating the TicTacToePacket Object
258
Implementing the Tic-Tac-Toe View Controller
262
Trying It Out
278
Game On!
279
Chapter 9 Online Play: Bonjour and Network Streams
280
This Chapter’s Application
280
Overview of the Process
282
Setting Up a Listener
282
Callback Functions and Run Loop Integration
283
Configuring a Socket
284
Declaring a Socket Context
284
Creating a Socket
285
Specifying a Port for Listening
286
Registering the Socket with the Run Loop
289
Implementing the Socket Callback Function
289
Stopping the Listener
290
Bonjour
290
Creating a Service for Publication
291
Publishing a Bonjour Service
292
Stopping a Bonjour Service
293
Delegate Methods for Publication
293
Searching for Published Bonjour Services
294
Browser Delegate Methods
295
Resolving a Discovered Service
296
Streams
297
Opening a Stream
298
The Stream and Its Delegate
298
Receiving Data from a Stream
299
Sending Data Through the Stream
300
Putting It All Together
301
Updating Tic-Tac-Toe for Online Play
301
Adding the Packet Categories
302
Implementing the Online Session Object
304
Creating the Listener Object
315
Creating the Peer Browser
320
Creating the Peer Browser Files
320
Writing the Peer Browser Header
321
Building the Peer Browser Interface
321
Implementing the Peer Browser View Controller
322
Updating TicTacToeViewController to Support Online Play
327
Time to Play
337
Chapter 10 Working with Data from the Web
338
Setting Up the Application Skeleton
340
Declaring Actions and Outlets
340
Designing the Interface
342
Implementing the Stubs
344
Retrieving Data Using Foundation Objects
345
Retrieving Data Synchronously
348
The URL Request
348
Retrieving Data Asynchronously
353
NSURLConnection Delegate Methods
354
Adding Asynchronous Retrieval to WebWorks
355
Request Types and Form Parameters
359
Specifying the HTTP Request Types
359
Form Parameters
360
GET Parameters
361
POST Parameters
361
Building the RequestTypes Application
362
404 Conclusion Not Found
367
Chapter 11 MapKit
368
This Chapter’s Application
369
Overview and Terminology
370
The Map View
371
Map Types
371
User Location
373
Coordinate Regions
373
Converting Degrees to Distance
375
Accommodating Aspect Ratio
376
Setting the Region to Display
376
The Map View Delegate
376
Map Loading Delegate Methods
377
Region Change Delegate Methods
377
Annotations
378
The Annotation Object
379
The Annotation View
379
Adding and Removing Annotations
380
Selecting Annotations
381
Providing the Map View with Annotation Views
381
Reverse Geocoding
382
Building the MapMe Application
384
Declaring Outlets and Actions
384
Building the Interface
385
Writing the Annotation Object Class
387
Implementing MapMeViewController
390
Linking the Map Kit and Core Location Frameworks
398
Go East, Young Programmer
399
Chapter 12 Sending Mail
400
This Chapter’s Application
400
The MessageUI Framework
403
Creating the Mail Compose View Controller
403
Prepopulating the Subject Line
403
Prepopulating Recipients
403
Setting the Message Body
404
Adding Attachments
404
Presenting the Mail Compose View
404
The Mail Compose View Controller Delegate Method
404
Building the MailPic Application
405
Declaring Outlets and Actions
406
Building the User Interface
406
Implementing the View Controller
407
Linking the MessageUI Framework
412
Mailing It In…
412
Chapter 13 iPod Library Access
413
This Chapter’s Application
413
Working with the iPod Library
415
Media Items
416
Media Item Persistent ID
417
Media Type
417
Filterable String Properties
419
Nonfilterable Numeric Attributes
419
Retrieving Lyrics
420
Retrieving Album Artwork
421
Retrieving the Date Last Played
421
Media Item Collections
421
Creating a New Collection
421
Retrieving Media Items
421
Creating Derived Collections
422
Media Queries and Media Property Predicates
422
The Media Picker Controller
425
Handling Media Picker Cancels
426
Handling Media Picker Selections
426
The Music Player Controller
426
Creating the Music Player Controller
427
Determining If the Music Player Controller Is Playing
427
Specifying the Music Player Controller’s Queue
427
Getting or Setting the Currently Playing Media Item
428
Skipping Tracks
428
Seeking
429
Playback Time
429
Repeat and Shuffle Modes
429
Adjusting the Music Player Controller’s Volume
430
Music Player Controller Notifications
431
Building the Simple Player Application
432
Adding Media Item Collection Functionality
432
Declaring Outlets and Actions
436
Building the User Interface
438
Implementing the Simple Player View Controller
442
Taking Simple Player for a Spin
456
Avast! Rough Waters Ahead!
456
Chapter 14 Keeping Your Interface Responsive
458
Exploring the Concurrency Problem
460
Creating the Stalled Application
461
Declaring Actions and Outlets
461
Designing the Interface
461
Implementing the Stalled View Controller
462
Timers
465
Creating a Timer
465
Stopping a Timer
466
Limitations of Timers
466
Fixing Stalled with a Timer
467
Creating the Batch Object
467
Updating the Controller Header
469
Updating the Nib
470
Updating the View Controller Implementation
470
Operation Queues & Concurrency
475
Threads
476
Race Conditions
476
Mutex Locks and @synchronized
478
Atomicity and Thread Safety
479
Deadlocks
481
Sleepy Time
481
Operations
482
Operation Dependencies
483
Operation Priority
483
Other Operation State
484
Cancelling an Operation
485
Operation Queues
485
Adding Operations to the Queue
485
Setting the Maximum Concurrent Operation Count
485
Suspending the Queue
486
Fixing Stalled with an Operation Queue
486
Creating Square Root Application
487
Changes to Stalled View Controller.h
492
Adjusting the User Interface
493
Updating Stalled View Controller.m
494
Queue ’em Up
500
Chapter 15 Debugging
502
The Debugger
503
Breakpoints
504
The Debugger Editing Pane
507
The Stack Trace
508
The Variable List
509
The Debugging Controls
510
Trying Out the Debug Controls
511
The Breakpoint Window and Symbolic Breakpoints
515
Conditional Breakpoints
516
Breakpoint Actions
518
The GDB Console
520
The Info Command
520
Working with Breakpoints
520
Creating Breakpoints
521
Removing Breakpoints
521
Printing Data and Object Values
522
Calling Functions and Methods
522
Static Analysis
523
Specific Bugs
524
Overreleasing Memory
524
NSZombie
528
Infinite Recursion
530
Missed Outlet and Action Connections
532
GDB: Stopped at Concluding Paragraph
532
Chapter 16 The Road Goes Ever On…
534
Getting Unstuck
534
Apple’s Documentation
535
Mailing Lists
535
Discussion Forums
535
Web Sites
536
Blogs
536
And If All Else Fails…
537
Farewell
537
Index
538