0% found this document useful (0 votes)
5 views

Learn Objective C for Java Developers 1st Edition James Bucanek (Auth.) - The ebook in PDF and DOCX formats is ready for download

The document provides information on downloading various ebooks, including 'Learn Objective C for Java Developers' by James Bucanek. It lists multiple recommended titles for Java developers and includes links to download them. The book covers Objective-C language fundamentals, programming patterns, and advanced topics, aimed at Java developers transitioning to Objective-C.

Uploaded by

mirsadrnec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Learn Objective C for Java Developers 1st Edition James Bucanek (Auth.) - The ebook in PDF and DOCX formats is ready for download

The document provides information on downloading various ebooks, including 'Learn Objective C for Java Developers' by James Bucanek. It lists multiple recommended titles for Java developers and includes links to download them. The book covers Objective-C language fundamentals, programming patterns, and advanced topics, aimed at Java developers transitioning to Objective-C.

Uploaded by

mirsadrnec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Visit ebookfinal.

com to download the full version and


explore more ebooks or textbooks

Learn Objective C for Java Developers 1st Edition


James Bucanek (Auth.)

_____ Click the link below to download _____


https://ebookfinal.com/download/learn-objective-c-for-java-
developers-1st-edition-james-bucanek-auth/

Explore and download more ebooks or textbook at ebookfinal.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Jasperreports Reporting for Java Developers 1st Edition


David Heffelfinger

https://ebookfinal.com/download/jasperreports-reporting-for-java-
developers-1st-edition-david-heffelfinger/

Learning Cocoa with Objective C 2nd Edition James Duncan


Davidson

https://ebookfinal.com/download/learning-cocoa-with-objective-c-2nd-
edition-james-duncan-davidson/

Learn Java for Web Development Modern Java Web Development


1st Edition Vishal Layka

https://ebookfinal.com/download/learn-java-for-web-development-modern-
java-web-development-1st-edition-vishal-layka/

Beginning Xcode Programmer to Programmer 1st Edition James


Bucanek

https://ebookfinal.com/download/beginning-xcode-programmer-to-
programmer-1st-edition-james-bucanek/
Learn Java Fundamentals A Primer for Java Development and
Programming 1st Edition Jeff Friesen

https://ebookfinal.com/download/learn-java-fundamentals-a-primer-for-
java-development-and-programming-1st-edition-jeff-friesen/

Effective Unit Testing A guide for Java Developers 1st


Edition Lasse Koskela

https://ebookfinal.com/download/effective-unit-testing-a-guide-for-
java-developers-1st-edition-lasse-koskela/

Objective C phrasebook 2nd ed Edition David Chisnall

https://ebookfinal.com/download/objective-c-phrasebook-2nd-ed-edition-
david-chisnall/

Learn Java In a Weekend 1st Edition Joseph P. Russell

https://ebookfinal.com/download/learn-java-in-a-weekend-1st-edition-
joseph-p-russell/

Microservices for Java developers a hands on introduction


to frameworks and containers First Edition. Edition Posta

https://ebookfinal.com/download/microservices-for-java-developers-a-
hands-on-introduction-to-frameworks-and-containers-first-edition-
edition-posta/
Learn Objective C for Java Developers 1st Edition James
Bucanek (Auth.) Digital Instant Download
Author(s): James Bucanek (auth.)
ISBN(s): 9781430223702, 1430223707
Edition: 1
File Details: PDF, 4.01 MB
Year: 2009
Language: english
■ CONTENTS

Learn Objective-C
for Java Developers

■■■

James Bucanek

xxv
Learn Objective-C for Java Developers
Copyright © 2009 by James Bucanek
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information storage
or retrieval system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-4302-2369-6
ISBN-13 (electronic): 978-1-4302-2370-2
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit
of the trademark owner, with no intention of infringement of the trademark.
Lead Editors: Clay Andres, Douglas Pundick
Technical Reviewer: Evan DiBiase
Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham,
Tony Campbell, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman,
Matthew Moodie, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick,
Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Project Manager: Kylie Johnston
Copy Editor: Elizabeth Berry
Compositor: Lynn L’Heureux
Indexer: Ann Rogers/Ron Strauss
Artist: April Milne
Cover Designer: Anna Ishchenko
Manufacturing Director: Michael Short
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th
Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-
ny@springer-sbm.com, or visit http://www.springeronline.com.
For information on translations, please e-mail info@apress.com, or visit
http://www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional
use. eBook versions and licenses are also available for most titles. For more information, reference
our Special Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have
any liability to any person or entity with respect to any loss or damage caused or alleged to be
caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com.

ii
■ CONTENTS AT A GLANCE

To the memories of my brother, John, and my father, “Dr. B.”

iii
■ CONTENTS

Contents at a Glance

About the Author ........................................................................................................xxi


About the Technical Reviewer ................................................................................. xxii
Acknowledgments ................................................................................................... xxiii
Introduction ................................................................................................................xiv

PART 1 ■ ■ ■ Language
Chapter 1: Introduction ............................................................................................. 3
Chapter 2: Java and C: Key Differences ................................................................... 11
Chapter 3: Welcome to Objective-C ........................................................................ 27
Chapter 4: Creating an Xcode Project ..................................................................... 55
Chapter 5: Exploring Protocols and Categories ...................................................... 75
Chapter 6: Sending Messages .................................................................................. 87
Chapter 7: Making Friends with nil ....................................................................... 103

PART 2 ■ ■ ■ Translating Technologies


Chapter 8: Strings and Primitive Values................................................................ 117
Chapter 9: Garbage Collection ............................................................................... 135
Chapter 10: Introspection ...................................................................................... 147
Chapter 11: Files ..................................................................................................... 163
Chapter 12: Serialization ........................................................................................ 185
Chapter 13: Communicating Near and Far .......................................................... 211
Chapter 14: Exception Handling ........................................................................... 239

iv
■ CONTENTS AT A GLANCE

Chapter 15: Threads ............................................................................................... 257

PART 3 ■ ■ ■ Programming Patterns


Chapter 16: Collection Patterns ............................................................................. 287
Chapter 17: Delegation Pattern ............................................................................. 315
Chapter 18: Provider/Subscriber Pattern ............................................................. 325
Chapter 19: Observer Pattern ................................................................................ 339
Chapter 20: Model-View-Controller Pattern ........................................................ 353
Chapter 21: Lazy Initialization Pattern ................................................................. 403
Chapter 22: Factory Pattern ................................................................................... 411
Chapter 23: Singleton Pattern ................................................................................ 429

PART 4 ■ ■ ■ Advanced Objective-C


Chapter 24: Memory Management ....................................................................... 435
Chapter 25: Mixing C and Objective-C.................................................................. 457
Chapter 26: Runtime .............................................................................................. 465

Index ......................................................................................................................... 477

v
■ CONTENTS AT A GLANCE

Contents
About the Author ........................................................................................................xxi
About the Technical Reviewer ................................................................................. xxii
Acknowledgments ................................................................................................... xxiii
Introduction ................................................................................................................xiv

PART 1 ■ ■ ■ Language
Chapter 1: Introduction ............................................................................................. 3
What is Objective-C? ................................................................................................. 3
History ................................................................................................................... 4
A Modern Object-Oriented Language ................................................................. 4
State of the Art Compiler ...................................................................................... 5
Performance .......................................................................................................... 5
Dynamism ............................................................................................................. 5
Developer Productivity......................................................................................... 8
Learning a New Language ........................................................................................ 8
Terminology and Culture Shock .............................................................................. 9
Defining Better ........................................................................................................ 10
Summary ................................................................................................................. 10
Chapter 2: Java and C: Key Differences ................................................................... 11
Primitive Types ....................................................................................................... 11
Constants ................................................................................................................. 14
Typedefs .................................................................................................................. 15
Pointers .................................................................................................................... 15
Structures ................................................................................................................ 16
Object References ................................................................................................... 17
Arrays ....................................................................................................................... 18
static ......................................................................................................................... 19
Functions ................................................................................................................. 20
extern ....................................................................................................................... 20

vii
■ CONTENTS

Preprocessor............................................................................................................ 21
#include and #import ......................................................................................... 21
#define ................................................................................................................. 22
#if 23
Initializing Automatic Variables ............................................................................ 24
Labels: break, continue, and goto.......................................................................... 24
Summary ................................................................................................................. 26
Chapter 3: Welcome to Objective-C ........................................................................ 27
Defining an Objective-C Class ............................................................................... 27
Object Pointers........................................................................................................ 29
Sending Messages ................................................................................................... 30
Naming Methods .................................................................................................... 31
Parameter and Return Types ................................................................................. 33
Method Selectors .................................................................................................... 34
Instance Variables ................................................................................................... 34
isa35
Properties ............................................................................................................ 35
Property Attributes ............................................................................................. 38
Overriding Properties ............................................................................................. 40
Accessing Properties ............................................................................................... 40
Scope........................................................................................................................ 41
Class Name Scope ............................................................................................... 41
Instance Variable Scope ..................................................................................... 41
Method Scope ..................................................................................................... 42
Forward @class Directive ....................................................................................... 43
self and super .......................................................................................................... 44
Class Methods ......................................................................................................... 45
Constructing Objects .............................................................................................. 47
Writing an init Method ....................................................................................... 49
Chaining Initializers ........................................................................................... 50
Designated Initializer ......................................................................................... 52
Convenience Constructors ................................................................................ 52
Destructors .............................................................................................................. 53
What’s Missing?....................................................................................................... 54
Chapter 4: Creating an Xcode Project ..................................................................... 55
Download the Project ............................................................................................. 55

viii
■ CONTENTS

Creating a Project.................................................................................................... 56
Getting Started ........................................................................................................ 58
Designing the Application...................................................................................... 59
Designing the User Interface ............................................................................. 61
Adding a Controller ............................................................................................ 64
Making a Binding ................................................................................................ 65
KVC .................................................................................................................. 66
KVO .................................................................................................................. 67
Controllers ....................................................................................................... 67
Bindings ........................................................................................................... 67
Adding an Array Controller ................................................................................ 67
Getting Down to Business ...................................................................................... 68
Debugging Your Application.................................................................................. 72
Creating Sandbox Applications ............................................................................. 73
Summary ................................................................................................................. 74
Chapter 5: Exploring Protocols and Categories ...................................................... 75
Protocols .................................................................................................................. 75
Informal Protocol .................................................................................................... 77
Combining Formal and Informal Protocols ......................................................... 78
Categories ................................................................................................................ 79
Using Categories for Organization .................................................................... 81
Hiding Methods .................................................................................................. 81
Augmenting Foreign Classes.............................................................................. 82
Extensions ........................................................................................................... 84
Summary ................................................................................................................. 85
Chapter 6: Sending Messages .................................................................................. 87
Compiling Messages ............................................................................................... 88
Undeclared Methods .......................................................................................... 88
Ambiguous Methods .......................................................................................... 89
Coercion .............................................................................................................. 90
Sending Messages Programmatically.................................................................... 90
Immediate Messages .......................................................................................... 91
Deferred Messages .............................................................................................. 92
Object-Oriented Method Invocation .................................................................... 94
Calling Methods Directly........................................................................................ 96

ix
■ CONTENTS

Variable Arguments ................................................................................................ 97


Unimplemented Methods.................................................................................... 100
Summary ............................................................................................................... 102
Chapter 7: Making Friends with nil ....................................................................... 103
Messages to nil Are Safe ....................................................................................... 104
nil Returns Zero .................................................................................................... 107
Designing With nil ................................................................................................ 108
Property Accessors ............................................................................................ 111
Absent Behavior ................................................................................................ 111
Consistency With Nothing ............................................................................... 113
No Free Rides ........................................................................................................ 113
Summary ............................................................................................................... 114

PART 2 ■ ■ ■ Translating Technologies


Chapter 8: Strings and Primitive Values................................................................ 117
Wrapping Scalar Primitives .................................................................................. 117
Scalar Type Conversion .................................................................................... 118
Converting Strings to Scalars ........................................................................... 119
Wrapping Arrays ................................................................................................... 119
Wrapping Arbitrary Values ................................................................................... 121
Wrapping nil .......................................................................................................... 123
Strings .................................................................................................................... 123
Converting Objects to Strings .......................................................................... 125
C Strings ............................................................................................................. 125
Formatting Strings ................................................................................................ 128
NSFormatter ...................................................................................................... 131
NSNumberFormatter ................................................................................... 132
NSDateFormatter.......................................................................................... 133
Summary ............................................................................................................... 134
Chapter 9: Garbage Collection ............................................................................... 135
Choosing to Use Garbage Collection .................................................................. 136
Writing Code with Garbage Collection ............................................................... 136
Writing Finalize Methods ..................................................................................... 138
Creating Weak References.................................................................................... 138
Creating Strong References .................................................................................. 140
Encouraging Garbage Collection ......................................................................... 141

x
■ CONTENTS

GC vs. Non-GC Pointers ....................................................................................... 142


Write Barriers .................................................................................................... 142
Allocating Collectable Memory ....................................................................... 142
Garbage Collection Pitfalls ............................................................................... 143
Interior Pointers ............................................................................................ 143
Opaque Pointers ........................................................................................... 143
Enumerating Weak Collections ................................................................... 144
Uninitialized Stack References .................................................................... 144
Other Pitfalls .................................................................................................. 145
Design Patterns to Avoid ...................................................................................... 145
Debugging ............................................................................................................. 145
Summary ............................................................................................................... 145
Chapter 10: Introspection ...................................................................................... 147
Testing for Methods .............................................................................................. 147
Testing Class Membership ................................................................................... 149
Key-Value Coding ................................................................................................. 150
Using Key-Value Coding .................................................................................. 152
Designing KVC-Compliant Classes ................................................................. 153
Custom Key Values ........................................................................................... 155
Inspecting Classes................................................................................................. 155
Exploring Protocols............................................................................................... 157
Exploring Methods ............................................................................................... 158
Exploring Properties ............................................................................................. 160
Exploring Instance Variables ............................................................................... 161
Summary ............................................................................................................... 162
Chapter 11: Files ..................................................................................................... 163
File System APIs .................................................................................................... 163
Identifying Items in the File System .................................................................... 164
File and Path Names ......................................................................................... 165
Working Directory ............................................................................................ 167
File URLs............................................................................................................ 168
Creating and Deleting Directories ................................................................... 169
Locating Special Directories ............................................................................ 169
Requesting a File from the User........................................................................... 171
Symbolic Links, Hard Links, and Aliases............................................................. 172
Working With the Contents of a Directory.......................................................... 173

xi
■ CONTENTS

File Properties ....................................................................................................... 175


High-Level File Operations .................................................................................. 177
NSWorkspace ........................................................................................................ 178
Random File Access .............................................................................................. 178
NSFileManager Delegate ...................................................................................... 180
Alternate APIs ........................................................................................................ 181
Summary ............................................................................................................... 184
Chapter 12: Serialization ........................................................................................ 185
Archiving................................................................................................................ 185
Archive Types .................................................................................................... 186
Archive Coders .................................................................................................. 187
Archives and Documents ................................................................................. 188
Adding Keyed Archive Support to Your Class ................................................. 189
Adding Sequential Archive Support to Your Class ......................................... 192
Supporting Both Keyed and Sequential Archiving ......................................... 192
Archiving Complications .................................................................................. 193
Transient Properties ..................................................................................... 194
Duplicate Objects ......................................................................................... 195
Limiting the Object Graph ........................................................................... 196
Class Version Compatibility ......................................................................... 197
Objective-C Serialization...................................................................................... 203
Property Lists .................................................................................................... 203
XML .................................................................................................................... 206
Copying Objects .................................................................................................... 207
Summary ............................................................................................................... 210
Chapter 13: Communicating Near and Far .......................................................... 211
Communicating Within a Single Process ............................................................ 211
Communicating with Other Processes................................................................ 212
Low-Level Communications ............................................................................ 212
NSPort ............................................................................................................ 213
NSPipe ........................................................................................................... 213
NSFileHandle ................................................................................................ 214
NSStream ....................................................................................................... 215
High-Level Communications........................................................................... 217
Distributed Notifications ............................................................................. 217
Distributed Objects....................................................................................... 218

xii
■ CONTENTS

Networking ............................................................................................................ 231


Network Services............................................................................................... 231
URL Loading...................................................................................................... 232
Trivial URL Request ...................................................................................... 232
Asynchronous URL Request......................................................................... 233
Writing to a URL............................................................................................ 235
Downloading a URL...................................................................................... 236
Caches and Cookies ...................................................................................... 237
Summary ............................................................................................................... 237
Chapter 14: Exception Handling ........................................................................... 239
Using Exceptions .................................................................................................. 239
Exception Handling Differences .......................................................................... 241
No Catch or Specify .......................................................................................... 241
Throw Any Object ............................................................................................. 241
Re-Throw an Exception .................................................................................... 242
Catch Order ....................................................................................................... 242
Chaining ............................................................................................................ 243
Call Stack ........................................................................................................... 243
Performance ...................................................................................................... 244
Uncaught Exceptions ....................................................................................... 244
Legacy Exceptions................................................................................................. 247
Assertions .............................................................................................................. 248
Alternatives to Exceptions .................................................................................... 252
Simple Errors ..................................................................................................... 253
POSIX Error Codes ............................................................................................ 253
Core Foundation Error Codes .......................................................................... 253
Cocoa Errors ...................................................................................................... 253
Error Domains............................................................................................... 254
Customization and Display.......................................................................... 254
Localization ................................................................................................... 255
Recovery ........................................................................................................ 255
Combining Errors and Exceptions ...................................................................... 256
Summary ............................................................................................................... 256
Chapter 15: Threads ............................................................................................... 257
Thread API ............................................................................................................. 257
Starting a Thread................................................................................................... 258

xiii
■ CONTENTS

Managing Threads ................................................................................................ 260


Putting a Thread to Sleep ................................................................................. 260
Thread Properties ............................................................................................. 263
Information ................................................................................................... 263
Thread-Specific Values ......................................................................................... 263
Priority ........................................................................................................... 264
Stack Size ....................................................................................................... 264
Name.............................................................................................................. 264
Terminating a Thread ........................................................................................... 264
Run Loops.............................................................................................................. 265
Starting a Run Loop .......................................................................................... 265
Run Loop Modes ............................................................................................... 267
Stopping a Run Loop ........................................................................................ 267
Customizing Run Loops ................................................................................... 268
Thread Notifications ............................................................................................. 268
Thread Synchronization ....................................................................................... 269
The @synchronize Directive ............................................................................ 270
Mutual Exclusion Semaphore Objects ............................................................ 270
NSRecursiveLock .......................................................................................... 271
NSLock ........................................................................................................... 271
NSConditionLock ......................................................................................... 273
NSDistributedLock ....................................................................................... 277
Spin Locks.......................................................................................................... 278
Operations ............................................................................................................. 280
Timers .................................................................................................................... 281
Summary ............................................................................................................... 283

PART 3 ■ ■ ■ Programming Patterns


Chapter 16: Collection Patterns ............................................................................. 287
Immutable Collections ......................................................................................... 288
Ordered Collections .............................................................................................. 292
Common Methods ............................................................................................ 292
NSArray, NSMutableArray ............................................................................... 294
NSPointerArray ................................................................................................. 295
Dictionary Collections .......................................................................................... 297
Common Methods ............................................................................................ 297

xiv
■ CONTENTS

NSDictionary, NSMutableDictionary.............................................................. 298


NSMapTable...................................................................................................... 298
Set Collections....................................................................................................... 299
Common Methods ............................................................................................ 299
NSSet, NSMutableSet ....................................................................................... 300
NSCountedSet ................................................................................................... 301
NSIndexSet ........................................................................................................ 301
NSHashTable .................................................................................................... 302
Composite Pattern ................................................................................................ 303
Collection Equality Contracts .............................................................................. 303
Comparing Collections......................................................................................... 305
Iterator Pattern...................................................................................................... 306
Using Fast Enumeration................................................................................... 306
Using Enumerators ........................................................................................... 307
Addressing Collection Objects ......................................................................... 308
Adding Enumeration Support.......................................................................... 309
Sorting Collections................................................................................................ 310
Objective-C Message Sorting ........................................................................... 311
C Function Sorting ............................................................................................ 311
Sort Descriptors ................................................................................................ 312
Filtering Collections ............................................................................................. 312
Collection Concurrency ....................................................................................... 313
Enumerate a Copy of the Collection ............................................................... 313
Defer Changes to the Collection ...................................................................... 313
Thread Safety .................................................................................................... 314
Garbage Collection and Weak Collections...................................................... 314
Summary ............................................................................................................... 314
Chapter 17: Delegation Pattern ............................................................................. 315
Understanding Delegates ..................................................................................... 315
Using Delegates .................................................................................................... 318
Delegate Methods ................................................................................................. 319
Delegate Protocols ................................................................................................ 320
Incorporating the Delegation Pattern ................................................................. 323
Summary ............................................................................................................... 323
Chapter 18: Provider/Subscriber Pattern ............................................................. 325
Notifications .......................................................................................................... 325

xv
■ CONTENTS

Notification Centers ............................................................................................. 329


Posting Synchronous Notifications ..................................................................... 329
Being a Discriminating Observer......................................................................... 330
Removing an Observer ......................................................................................... 331
Notification Queuing ............................................................................................ 332
Queuing a Notification ..................................................................................... 333
Coalescing Notifications .................................................................................. 334
Dequeuing Notifications .................................................................................. 334
Distributed Notifications ..................................................................................... 334
Distributed Notifications Center ..................................................................... 336
Property List Values .......................................................................................... 336
Asynchronous Notification Delivery ............................................................... 336
Suspending a Distributed Notification Center ............................................... 337
Summary ............................................................................................................... 337
Chapter 19: Observer Pattern ................................................................................ 339
Key-Value Observing at Work .............................................................................. 340
Registering a Key-Value Observer ....................................................................... 343
Processing Key-Value Change Notifications ...................................................... 345
Unregistering an Observer ................................................................................... 346
Making Your Classes KVO Compliant ................................................................. 347
Sending Manual KVO Notifications ................................................................ 347
Creating Property Dependencies .................................................................... 349
Overriding Key-Value Observing ..................................................................... 351
Optimizing Key-Value Observing ........................................................................ 352
Summary ............................................................................................................... 352
Chapter 20: Model-View-Controller Pattern ........................................................ 353
Understanding Model-View-Controller.............................................................. 354
MVC Variations ................................................................................................. 355
Combined Controller and Data Model ....................................................... 355
Mediating Controller .................................................................................... 355
Direct View and Data Model Binding .......................................................... 356
Other Variations ............................................................................................ 356
The Advantages of MVC ................................................................................... 357
Modularity ..................................................................................................... 357
Flexibility ....................................................................................................... 357
Reuse .............................................................................................................. 358

xvi
■ CONTENTS

Scaling............................................................................................................ 358
Bindings ................................................................................................................. 358
Interface Builder ................................................................................................... 360
NIB Documents ................................................................................................ 361
The NIB Document Window............................................................................ 361
Object Properties .............................................................................................. 361
Placeholder Objects .......................................................................................... 362
Connections ...................................................................................................... 363
Outlets............................................................................................................ 363
Actions ........................................................................................................... 364
Bindings ......................................................................................................... 365
Owner Object .................................................................................................... 367
Custom Objects ................................................................................................. 367
Object Instantiation .......................................................................................... 369
NIB Object Initialization .................................................................................. 369
Views ...................................................................................................................... 369
View Geometry .................................................................................................. 372
Coordinate Points ......................................................................................... 372
Coordinate System........................................................................................ 373
Pen Orientation ............................................................................................. 374
Drawing Bounds ........................................................................................... 375
Drawing Lines and Shapes ........................................................................... 375
Custom Views .................................................................................................... 376
Invalidating and Drawing Views .................................................................. 376
Graphics Context .......................................................................................... 377
The Graphics Context State Stack................................................................ 378
Drawing Tools ............................................................................................... 380
Animation ...................................................................................................... 381
iPhone View Classes ..................................................................................... 383
Advanced View Topics .................................................................................. 383
Document Model .................................................................................................. 384
Events and Responders ........................................................................................ 385
The Dynamic Application ................................................................................ 385
Events................................................................................................................. 387
Event Objects .................................................................................................... 387
Key Events ......................................................................................................... 388
Mouse Events .................................................................................................... 389

xvii
■ CONTENTS

Mouse Down Event....................................................................................... 389


Mouse Drag and Mouse Up Events ............................................................. 389
Mouse Tracking ............................................................................................ 390
The Responder Chain ....................................................................................... 391
Action Messages ............................................................................................ 392
Sending Action Messages ............................................................................. 393
Menu Actions ................................................................................................ 393
Disabling Action Menu Items ...................................................................... 394
Designing with the Responder Chain.......................................................... 395
Data Models .......................................................................................................... 395
Legacy Table and Tree Models ........................................................................ 395
Collection Controllers ...................................................................................... 397
Core Data ........................................................................................................... 398
Custom Data Model Objects ............................................................................ 398
Controllers ............................................................................................................. 399
Custom Controllers .......................................................................................... 399
Creating a Custom NSApplication............................................................... 399
Creating a Custom NSDocument ................................................................ 400
NSController Controllers ................................................................................. 400
About TicTacToe ................................................................................................... 401
Info.plist............................................................................................................. 402
Undo .................................................................................................................. 402
Resources........................................................................................................... 403
Localized Resources ......................................................................................... 403
Summary ............................................................................................................... 403
Chapter 21: Lazy Initialization Pattern ................................................................. 403
Implementing the Pattern .................................................................................... 403
Lazy Initialization of Global Variables ................................................................ 404
The Class +initialize Method................................................................................ 407
Summary ............................................................................................................... 410
Chapter 22: Factory Pattern ................................................................................... 411
URL Factory ........................................................................................................... 411
Matrix Class ........................................................................................................... 411
Java Matrix Factory ........................................................................................... 419
Objective-C Matrix Class Cluster ..................................................................... 423
Summary ............................................................................................................... 428

xviii
■ CONTENTS

Chapter 23: Singleton Pattern ................................................................................ 429


Implementing Singletons ..................................................................................... 429
Lazy Singletons ..................................................................................................... 430
Singleton Factory .................................................................................................. 431
Summary ............................................................................................................... 432

PART 4 ■ ■ ■ Advanced Objective-C


Chapter 24: Memory Management ....................................................................... 435
C Memory Allocation ............................................................................................ 436
Objective-C Reference Counting ......................................................................... 436
Autorelease Pools .................................................................................................. 437
Autorelease Pool Lifetime ................................................................................ 438
Returned References ........................................................................................ 438
Autoreleased Objects ........................................................................................ 440
Managed Memory Patterns.................................................................................. 441
New Object Patterns ......................................................................................... 441
Autoreleased Object Pattern ............................................................................ 441
Returning Autoreleased Objects ...................................................................... 442
Setter Patterns ................................................................................................... 442
init Patterns ....................................................................................................... 444
dealloc Patterns................................................................................................. 445
Implicitly Retained Objects .............................................................................. 446
Managed Memory Problems................................................................................ 447
Overretained or Underreleased Objects ......................................................... 447
Overreleased or Underretained Objects ......................................................... 448
Prematurely Released Objects ......................................................................... 450
Circular References ........................................................................................... 451
Creating Autorelease Pools .................................................................................. 452
Mixing Managed Memory and Garbage Collection ........................................... 453
Summary ............................................................................................................... 455
Chapter 25: Mixing C and Objective-C.................................................................. 457
Using C in Objective-C ......................................................................................... 457
Calling C Functions from Objective-C ............................................................ 457
Using Objective-C Objects in C ....................................................................... 458
Core Foundation ................................................................................................... 458
The Toll-Free Bridge ......................................................................................... 459

xix
■ CONTENTS

C Memory Management .................................................................................. 462


Using Core Foundation Memory Management Patterns .......................... 463
Using Core Foundation with Garbage Collection ...................................... 463
Using Core Foundation with Managed Memory........................................ 464
Summary ............................................................................................................... 464
Chapter 26: Runtime .............................................................................................. 465
Process ................................................................................................................... 465
Environment ..................................................................................................... 466
Command-Line Arguments ............................................................................. 466
Process Attributes ............................................................................................. 466
Version ............................................................................................................... 467
Controlling Development and Deployment Versions ............................... 467
Testing for Classes, Methods, and Functions ............................................. 467
Packages and Bundles .......................................................................................... 468
Frameworks ........................................................................................................... 468
User Defaults ......................................................................................................... 470
isa Swizzling .......................................................................................................... 472
64-Bit Programming ............................................................................................. 473
Summary ............................................................................................................... 475
Epilogue ................................................................................................................. 475
Index ......................................................................................................................... 477

xx
Discovering Diverse Content Through
Random Scribd Documents
THE BANKS OF THE AISNE.
In the background: Chapel of the Glass-Works. To the left of the
Chapel, a German Machine-Gun was posted, below a crane.

From Vauxrot to Pasly, the lines were separated by the Aisne. On


both banks of the river were outposts and advanced trenches with
machine-guns (photo below).
From Vauxrot, proceed to Pasly (see map, p. 53).
From the church at Pasly there is an interesting walk to the caves
seen in the photograph on p. 59 shutting in the horizon to the north
of the village. Follow the road for nearly half-a-mile, then turn to the
right into the road which goes up the side of the hill and skirts the
caves. The latter were fortified by the Germans, and afterwards
inhabited by the population of Pasly.
THE DAM AT VAUXROT.
A nest of Machine-Guns was posted near the pile.
PASLY.
On the horizon Hill containing caves.

A monument to the school-teachers shot by the Germans in 1870,


was destroyed by the enemy in 1914 (photo below).
SCHOOL-TEACHERS’ MONUMENT DESTROYED BY THE
GERMANS AT PASLY.
(see above)

The road leads back to the village. Return via Vauxrot to the Place
de Laon, then follow on the left the Avenue de Laon to Saint-Paul.
The defence-works visited between Pasly, the glass-works and the
distillery, extended from there in an almost straight and formidable
entrenched line to the National Road from Paris to Maubeuge (N. 2).
ORGANIZED CAVE AT PASLY.

After crossing this road, about half-way between Soissons and


Crouy, they encircle the hamlet of St-Paul on the north and east.
This fortified hamlet formed the Saint-Paul salient and protected the
faubourg of Saint-Waast.
ENTRANCE TO CAVE AT PASLY.

From Saint-Paul the trenches, sloping towards the south, extended


in front of the strongly fortified Faubourg of Saint-Médard and
rejoined the Aisne at the point where the river forms a great loop
above Soissons. It was the eastern sector of the defences, covering
alike the Faubourg of Saint-Waast and the bridge-head on the right
bank.
To go from Saint-Paul to Saint-Médard, return to the Place de Laon.
Take on the left the Boulevard de Laon, then the Boulevard de Metz
which continues it, to the Place d’ Alsace-Lorraine. Take the Rue de
Bouvines on the left to the Abbey of Saint-Médard.
The Faubourg of Saint-Médard is as old as the town itself. In fact, it
existed in the Roman era, and later became one of the favorite
residences of the Merovingian Kings, who owned a large “villa”
there.
DESTROYED BRIDGE OVER THE AISNE.
This bridge connected Pasly with Soissons.
IN THE ST-PAUL SALIENT.

About 556, Clotaire I had the greatly revered Bishop of Noyon, Saint-
Médard, buried in this villa, and erected over his grave a basilica,
round which a monastery was built.
After playing an important part in the history of the early Middle-
Ages, this monastery attracted 300 000 pilgrims as late as 1530. The
buildings were devastated during the many sieges to which Soissons
was subjected. Rebuilt in the 17th, they were converted in the 19th
century into a school for deaf-mutes and the blind.
Of the ancient buildings, there remains only a crypt, one of the
oldest in France and of great archæological interest.
Built in the 9th century and measuring about 80 feet in length, 8 feet
in width and 13 feet in height, this crypt (photo below) includes a
central gallery with groined vault, off which open chapels.
The vaulting rests on very thick walls, in which small niches have
been hollowed out as seats for the pilgrims.
THE CRYPT OF ST-MÉDARD.
One of the oldest crypts in France.
CHURCH OF ST-WAAST IN 1917.

Return to the Place d’Alsace-Lorraine, take the Rue du Champ-


Bouillant as far as the first street on the right (Rue Messire-P.-Leroy)
which leads to the Church of Saint-Waast.
FAUBOURG ST-WAAST.
Defence-Works in the Rue des Graviers, near the Church (see
Itinerary).

The church of Saint-Waast, built in the 19th century, consists of a


large central pile with aisles on each side of the nave. A graceful
belfry, ending in a spire, rises over the portal. The interior of the
building is not vaulted, but has a timber-work roof. The arches are
supported by square pillars and the walls ornamented with pictures.
The bombardments did great damage. Everywhere the roof was
broken in and a large part completely destroyed. In the walls are
numerous gaps, while the façade is pitted by shell-splinters. The
belfry, very badly damaged on the first story, had two of its sides in
the upper story completely demolished. The spire fell down in 1918.
The interior of the main building suffered less, but the timber-work
roof was badly damaged.
The Faubourg Saint-Waast led to the first lines of the north-east
sector of Soissons, which passed north of the hamlet of Saint-Paul.
Because of its situation, it had been put in a complete state of
defence and was continually bombarded. The railway station, gas-
works and most of the factories were destroyed. In places, it is
nothing more than a heap of ruins with, here and there, vestiges of
the old military works.
Return to the Rue du Champ-Bouillant, follow same as far as the
Aisne, crossing the latter at the Pont Saint-Waast.

THE PONT ST-WAAST OR PONT DES ANGLAIS.


In the background, the Pont-Neuf, Sept. 1914.

The pont Saint-Waast, also called the Pont des Anglais (since the
war) dates from the Middle-Ages (photo above). Of the original
structure there remain the arches on the Saint-Waast side (restored).
The rest of the bridge consists of an iron platform which the
Germans destroyed on September 13, 1914, when they evacuated
the town.
Rebuilt by the British in 1914, together with a foot-bridge, it ensured
communication between the centre of the town and the Faubourg
Saint-Waast, in spite of incessant bombardments.
Return to the Cathedral by the Rue la Bannière, Rue de Montrevers,
and Rue de l’Hôtel-Dieu.
CONTENTS
Chief Historical
2
Facts
First German
4
Occupation, 1914
Second German
7
Occupation, 1918
The Bombardments 10
A Thirty-Months’
11
Siege

VISIT TO THE CITY


15–
The Cathedral
31
35–
St-Léger Church
39
40–
The Hôtel-de-Ville
41
St-Pierre-au-
42
Parvis Church
Maison de
43
l’Arquebuse
St-Jean-des-Vignes 44–
Abbey 50

VISIT TO THE SURROUNDINGS


St-Crépin-en-Chaye 53
Château
56–
Vauxrot-Pasly
60
Saint-Paul—Saint- 60–
Médard 61
Faubourg St- 62–
Waast 63

STREET DEFENCE-WORKS IN THE FAUBOURG ST-WAAST.


‘OFFICE NATIONAL DU
TOURISME’
17, Rue de Surène, PARIS-8e

The ‘Office National du Tourisme’ was created


by Act of Parliament on April 8th 1910, and
reorganized in 1917. It enjoys civil privileges
and financial autonomy.
It is directed by an Administrative Council
chosen by the Minister of Public Works.
Its mission is to seek out every means of
developing travel; to urge, and if necessary to
take any measure capable of ameliorating the
conditions of the transport, circulation and
sojourn of tourists.
It co-ordinates the efforts of touring societies
and industries, encourages them in the
execution of their programmes and stimulates
legislative and administrative initiative with
regard to the development of travel in France.
It promotes understanding between the Public
Services, the great Transport Companies, the
‘Syndicats d’Initiative’ and the ‘Syndicats
Professionnels’.
It organises propaganda in foreign countries;
and tends towards the creation of Travel Inquiry
Offices in France and abroad, with a view to
making known the scenery and monuments of
France, as well as the health-giving powers of
French mineral waters, spas and bathing
places.

ALL INQUIRIES WITH REGARD TO


TRAVELLING
SHOULD BE ADDRESSED
TO THE ‘TOURING-CLUB DE
FRANCE’
65, Avenue de la Grande-Armée, 65
PARIS
THE ‘TOURING-CLUB DE
FRANCE’

WHAT IS IT? WHAT ARE ITS USES?

The ‘Touring-Club de France’ (founded in 1890),


is at the present time the largest Touring
Association in the whole world. Its principal aim
is to introduce France—admirable country and
one of the loveliest on earth—to French people
themselves and to foreigners.
It seeks to develop travel in all its forms: on foot,
on horseback, on bicycle, in carriage, motor,
yacht or railway, and soon in aeroplane.
Every member of the Association receives a
badge and an identity ticket free of charge, as
also the ‘Revue Mensuelle’ every month.
Members have also the benefit of special prices
in a certain number of affiliated hotels; and this
holds good for the purchase of guide-books and
Staff (Etat-major) maps, as well as those of the
‘Ministère de l’Intérieur’, the T. C. F., etc. They
may insert notices regarding the sale or
purchase of travelling requisites, in the ‘Revue’
(1 fr. per line). The ‘Comité des Contentieux’ is
ready to give them counsel with regard to
travelling, and 3.000 delegates in all the
principal towns are able to give them advice and
information about the curiosities of art or of
nature in the neighbourhood, as well as
concerning the roads, hotels, motor-agents,
garages, etc.
Members are accorded free passage across the
frontier for a bicycle or motor-bicycle. For a
motor-car the Association gives a ‘Triptyque’
ensuring free passage through the ‘douane’,
etc.

ONE TRAVELS BEST IN FRANCE WHEN A


MEMBER
OF THE ‘TOURING-CLUB DE FRANCE’
MICHELIN TYRE Co., Ltd.,
LONDON
Touring Office:: 81, Fulham
Road, S. W.

MICHELIN & Cie, CLERMONT-FERRAND


Touring Office:: 97, Bd. Pereire, PARIS

Why ask the Way, when . . . . . . . . . .


...................
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookfinal.com

You might also like