100% found this document useful (1 vote)
16 views

Learn Objective C for Java Developers 1st Edition James Bucanek 2024 scribd download

Developers

Uploaded by

rankaecomba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
16 views

Learn Objective C for Java Developers 1st Edition James Bucanek 2024 scribd download

Developers

Uploaded by

rankaecomba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Download Full ebookname - Read Now at ebookname.

com

Learn Objective C for Java Developers 1st Edition


James Bucanek

https://ebookname.com/product/learn-objective-c-for-java-
developers-1st-edition-james-bucanek/

OR CLICK BUTTON

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Learn Objective C on the Mac 1st Edition Dalrymple

https://ebookname.com/product/learn-objective-c-on-the-mac-1st-
edition-dalrymple/

ebookname.com

Learn Objective C on the Mac 1st Edition Mark Dalrymple

https://ebookname.com/product/learn-objective-c-on-the-mac-1st-
edition-mark-dalrymple/

ebookname.com

Professional Eclipse 3 for Java Developers 1st Edition


Berthold Daum

https://ebookname.com/product/professional-eclipse-3-for-java-
developers-1st-edition-berthold-daum/

ebookname.com

Kingdom to Commune Protestant Pacifist Culture between


World War I and the Vietnam Era First Edition Patricia
Appelbaum
https://ebookname.com/product/kingdom-to-commune-protestant-pacifist-
culture-between-world-war-i-and-the-vietnam-era-first-edition-
patricia-appelbaum/
ebookname.com
Complex Analysis and Geometry Proceedings of a Conference
at The Ohio State University June 3 6 1999 Jeffery D.
Mcneal (Editor)
https://ebookname.com/product/complex-analysis-and-geometry-
proceedings-of-a-conference-at-the-ohio-state-university-
june-3-6-1999-jeffery-d-mcneal-editor/
ebookname.com

Defy Your Doctor and Be Healed C. Thomas Corriher

https://ebookname.com/product/defy-your-doctor-and-be-healed-c-thomas-
corriher/

ebookname.com

Carbon Nanotube Based Composites Processing Properties


Modelling and Application 1st Edition Antonio Pantano

https://ebookname.com/product/carbon-nanotube-based-composites-
processing-properties-modelling-and-application-1st-edition-antonio-
pantano/
ebookname.com

The Two Koreas and the Politics of Global Sport 1st


Edition Brian Bridges

https://ebookname.com/product/the-two-koreas-and-the-politics-of-
global-sport-1st-edition-brian-bridges/

ebookname.com

Introduction to Physical Anthropology 14th Edition Robert


Jurmain

https://ebookname.com/product/introduction-to-physical-
anthropology-14th-edition-robert-jurmain/

ebookname.com
Vintage Moquegua History Wine and Archaeology on a
Colonial Peruvian Periphery 1st Edition Prudence M. Rice

https://ebookname.com/product/vintage-moquegua-history-wine-and-
archaeology-on-a-colonial-peruvian-periphery-1st-edition-prudence-m-
rice/
ebookname.com
www.it-ebooks.info
■ CONTENTS

Learn Objective-C
for Java Developers

■■■

James Bucanek

xxv
www.it-ebooks.info
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

www.it-ebooks.info
■ CONTENTS AT A GLANCE

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

iii

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ 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

www.it-ebooks.info
■ CONTENTS

About the Author

James Bucanek has spent the past 30 years programming and developing microprocessor systems.
He has experience with a broad range of computer hardware and software, from embedded consumer
products to industrial robotics. His development projects include the first local area network for the
Apple II, distributed air conditioning control systems, a piano teaching system, digital oscilloscopes,
silicon wafer deposition furnaces, and collaborative writing tools for K-12 education. James holds a Java
Developer Certification from Sun Microsystems and was awarded a patent for optimizing local area
networks. James is currently focused on Macintosh and iPhone software development, where he can
combine his deep knowledge of UNIX and object-oriented languages with his passion for elegant design.
James holds an Associates degree in classical ballet from the Royal Academy of Dance.

xxi

www.it-ebooks.info
■ CONTENTS

About the Technical Reviewer

Evan DiBiase lives in Pittsburgh, Pennsylvania with his fiancée, Ellen,


and their cat, Millie. After graduating from high school, he spent several
years working at a software startup developing machine learning
applications in Java before enrolling in the School of Computer Science
at Carnegie Mellon University, where he will graduate in May 2010. Evan
also hosted the Pittsburgh chapter of Cocoaheads from 2007 to 2009, has interned at
Apple in the Objective-C group, and enjoys programming in Cocoa for Mac OS X and
iPhone in his spare time.

xxii

www.it-ebooks.info
■ CONTENTS

Acknowledgments

This book would not have been possible without the tireless efforts of the Apress editors. I am
eternally indebted to my technical editor, Evan DiBiase, who painstakingly checked every symbol,
method, and line of code for accuracy. I thank Douglas Pundick for his astute structural changes,
and I would have been completely lost without the talented red pen of my copy editor, Elizabeth
Berry. The unflagging Kylie Johnson held the entire project on course and, amazingly, on schedule.
Finally, I’d like to chastise Clay Andres who once plucked me out of a WWDC conference and told
me I could write books.

xxiii

www.it-ebooks.info
■ CONTENTS

Introduction

Objective-C is a wonderful language that has received far less attention than it deserves. It has suddenly
become (more) popular with the success of Apple’s Mac OS X and iPhone, where it is the supreme
development language. If you’re going to learn a language to write applications for Mac OS X or the
iPhone, Objective-C is the language to learn.
The Objective-C language does not feel like it was developed by a committee or a computer
science major. It’s a language for minimalists and anarchists. Yet it retains many of the features that
make Java one of the great programming languages of our time. Objective-C lets you write applications
that are every bit as structured and formal as anything you can write in Java. But at the same time, if you
want to bore a hole through the language and head off in a direction where no one has gone before, it
won’t stand in your way.
After programming in Objective-C for a few years, I was struck at how “Java-like” my programs
were. If I’d known then just how many of my Java techniques and concepts were directly transferable to
Objective-C, it would have saved me months of study and experimentation. I wrote this book so that you
can avoid the same fate.

Who This Book Is For


This book is for any Java developer interested in learning and exploring Objective-C as quickly as
possible.

How This Book Is Structured


This book is organized into four parts: the Objective-C language, translating technologies, design
patterns, and advanced Objective-C.
The first part describes the basics of the Objective-C language itself. It explains how Objective-C
is like, and unlike, Java. It details the language syntax, class declarations, inheritance, and so on.
The second part examines specific technologies, like garbage collection, the file system, and
introspection. Each chapter presents side-by-side examples of Java code and the equivalent code in
Objective-C. Tables list the Java classes that you’re familiar with along with the Cocoa classes that
perform the same role. Each chapter then goes on to advanced topics, often exploring techniques
unique to Objective-C.
The third part is organized by design pattern. Java developers use many important design
patterns, such as the factory and Model-View-Controller patterns. These chapters show how each
pattern is implemented in Objective-C—often in ways that may surprise you.
The final section of the book explores advanced Objective-C topics: memory management,
integrating Objective-C with C, and the Objective-C runtime environment.

xxiv

www.it-ebooks.info
■ INTRODUCTION

I strongly encourage you to read the first part in its entirety. The second and third parts can be
read straight through, or you can skim them and refer back to them later for solutions. The advanced
topics in the final section address specific situations, like working with the iPhone’s memory manager,
which can be explored as needed. Many chapters start out with the basics and then progress to more
esoteric features, so feel free to skip to the next chapter once you’ve learned what you want.

Prerequisites
This book assumes that you have some experience programming in Java. You should be familiar with the
basics of the language, the concepts of classes, objects, inheritance, and interfaces, and have a working
knowledge of the core Java classes. It will help if you have some functional knowledge of individual Java
technologies, like introspection and exceptions, but these aren’t absolutely necessary to learn the
Objective-C equivalents. While I would hope that you are already familiar with design patterns, they
aren’t a prerequisite.

Downloading the Code


The source code for this book is available to readers at http://www.apress.com in the Downloads
section of this book’s home page. Please feel free to visit the Apress web site and download all the code
there. You can also check for errata and find related titles from Apress.

Contacting the Author


You can reach me at james@objectivec4java.com.

xxv

www.it-ebooks.info
Discovering Diverse Content Through
Random Scribd Documents
IV

The Lifuans furnish an illustration which seems decisive. But they are
savages, and on that account their example may be invalidated. It is
well to take another illustration from a people whose high and long-
continued civilisation is now undisputed.
The civilisation of China is ancient: that has long been a familiar fact.
But for more than a thousand years it was merely a legend to
Western Europeans; none had ever reached China, or, if they had,
they had never returned to tell the tale; there were too many fierce
and jealous barbarians between the East and the West. It was not
until the end of the thirteenth century, in the pages of Marco Polo,
the Venetian Columbus of the East,—for it was an Italian who
discovered the Old World as well as the New,—that China at last
took definite shape alike as a concrete fact and a marvellous dream.
Later, Italian and Portuguese travellers described it, and it is
interesting to note what they had to say. Thus Perera in the
sixteenth century, in a narrative which Willes translated for Hakluyt’s
“Voyages,” presents a detailed picture of Chinese life with an
admiration all the more impressive since we cannot help feeling how
alien that civilisation was to the Catholic traveller and how many
troubles he had himself to encounter. He is astonished, not only by
the splendour of the lives of the Chinese on the material side, alike
in large things and in small, but by their fine manners in all the
ordinary course of life, the courtesy in which they seemed to him to
exceed all other nations, and in the fair dealing which far surpassed
that of all other Gentiles and Moors, while in the exercise of justice
he found them superior even to many Christians, for they do justice
to unknown strangers, which in Christendom is rare; moreover, there
were hospitals in every city and no beggars were ever to be seen. It
was a vision of splendour and delicacy and humanity, which he
might have seen, here and there, in the courts of princes in Europe,
but nowhere in the West on so vast a scale as in China.
The picture which Marco Polo, the first European to reach China (at
all events in what we may call modern times), presented in the
thirteenth century was yet more impressive, and that need not
surprise us, for when he saw China it was still in its great Augustan
age of the Sung Dynasty. He represents the city of Hang-Chau as the
most beautiful and sumptuous in the world, and we must remember
that he himself belonged to Venice, soon to be known as the most
beautiful and sumptuous city of Europe, and had acquired no small
knowledge of the world. As he describes its life, so exquisite and
refined in its civilisation, so humane, so peaceful, so joyous, so well
ordered, so happily shared by the whole population, we realise that
here had been reached the highest point of urban civilisation to
which Man has ever attained. Marco Polo can think of no word to
apply to it—and that again and again—but Paradise.
The China of to-day seems less strange and astonishing to the
Westerner. It may even seem akin to him—partly through its decline,
partly through his own progress in civilisation—by virtue of its direct
and practical character. That is the conclusion of a sensitive and
thoughtful traveller in India and Japan and China, G. Lowes
Dickinson. He is impressed by the friendliness, the profound
humanity, the gaiety, of the Chinese, by the unequalled self-respect,
independence, and courtesy of the common people. “The
fundamental attitude of the Chinese towards life is, and has always
been, that of the most modern West, nearer to us now than to our
mediæval ancestors, infinitely nearer to us than India.”[6]
So far it may seem scarcely as artists that these travellers regard the
Chinese. They insist on their cheerful, practical, social, good-
mannered, tolerant, peaceable, humane way of regarding life, on the
remarkably educable spirit in which they are willing, and easily able,
to change even ancient and deep-rooted habits when it seems
convenient and beneficial to do so; they are willing to take the world
lightly, and seem devoid of those obstinate conservative instincts by
which we are guided in Europe. The “Resident in Peking” says they
are the least romantic of peoples. He says it with a nuance of
dispraise, but Lowes Dickinson says precisely the same thing about
Chinese poetry, and with no such nuance: “It is of all poetry I know
the most human and the least symbolic or romantic. It contemplates
life just as it presents itself, without any veil of ideas, any rhetoric or
sentiment; it simply clears away the obstruction which habit has built
up between us and the beauty of things and leaves that, showing in
its own nature.” Every one who has learnt to enjoy Chinese poetry
will appreciate the delicate precision of this comment. The quality of
their poetry seems to fall into line with the simple, direct, childlike
quality which all observers note in the Chinese themselves. The
unsympathetic “Resident in Peking” describes the well-known
etiquette of politeness in China: “A Chinaman will inquire of what
noble country you are. You return the question, and he will say his
lowly province is so-and-so. He will invite you to do him the honour
of directing your jewelled feet to his degraded house. You reply that
you, a discredited worm, will crawl into his magnificent palace.” Life
becomes all play. Ceremony—the Chinese are unequalled for
ceremony, and a Government Department, the Board of Rites and
Ceremonies, exists to administer it—is nothing but more or less
crystallised play. Not only is ceremony here “almost an instinct,” but,
it has been said, “A Chinese thinks in theatrical terms.” We are
coming near to the sphere of art.
The quality of play in the Chinese character and Chinese civilisation
has impressed alike them who have seen China from afar and by
actual contact. It used to be said that the Chinese had invented
gunpowder long before Europeans and done nothing with it but
make fireworks. That seemed to the whole Western world a terrible
blindness to the valuable uses of gunpowder, and it is only of late
years that a European commentator has ventured to remark that
“the proper use of gunpowder is obviously to make fireworks, which
may be very beautiful things, not to kill men.” Certainly the Chinese,
at all events, appreciate to the full this proper use of gunpowder.
“One of the most obvious characteristics of the Chinese is their love
of fireworks,” we are told. The gravest people and the most
intellectual occupy themselves with fireworks, and if the works of
Bergson, in which pyrotechnical allusions are so frequent, are ever
translated into Chinese, one can well believe that China will produce
enthusiastic Bergsonians. All toys are popular; everybody, it is said,
buys toys of one sort or another: paper windmills, rattles, Chinese
lanterns, and of course kites, which have an almost sacred
significance. They delight, also, in more complicated games of skill,
including an elaborate form of chess, far more difficult than ours.[7]
It is unnecessary to add that to philosophy, a higher and more
refined form of play, the Chinese are peculiarly addicted, and
philosophic discussion is naturally woven in with an “art of exquisite
enjoyment”—carried probably to greater perfection than anywhere
else in the world. Bertrand Russell, who makes this remark, in the
suggestive comments on his own visit to China, observes how this
simple, child-like, yet profound attitude towards life results in a
liberation of the impulses to play and enjoyment which “makes
Chinese life unbelievably restful and delightful after the solemn
cruelties of the West.” We are reminded of Gourmont’s remark that
“pleasure is a human creation, a delicate art, to which, as for music
or painting, only a few are apt.”
The social polity which brings together the people who thus view life
is at once singular and appropriate. I well remember how in youth a
new volume of the Sacred Books of the East Series, a part of the
Confucian Lî-kî, came into my hands and how delighted I was to
learn that in China life was regulated by music and ceremony. That
was the beginning of an interest in China that has not ceased to
grow, though now, when it has become a sort of fashion to exalt the
spiritual qualities of the Chinese above those of other peoples, one
may well feel disinclined to admit any interest in China. But the
conception itself, since it seems to have had its beginning at least a
thousand years before Christ, may properly be considered
independently of our Western fashions. It is Propriety—the whole
ceremony of life—in which all harmonious intercourse subsists; it is
“the channel by which we apprehend the ways of Heaven,” in no
supernatural sense, for it is on the earth and not in the skies that
the Confucian Heaven lies concealed. But if human feelings, the
instincts—for in this matter the ancient Chinese were at one with our
modern psychologists,—are the field that has to be cultivated, and it
is ceremony that ploughs it, and the seeds of right action that are to
be planted on it, and discipline that is to weed it, and love that is to
gather in the fruits, it is in music, and the joy and peace that
accompany music, that it all ends. Indeed, it is also in music that it
all begins. For the sphere in which ceremonies act is Man’s external
life; his internal life is the sphere of music. It is music that moulds
the manners and customs that are comprised under ceremony, for
Confucius held that there can be music without sound where “virtue
is deep and silent”; and we are reminded of the “Crescendo of
Silences” on the Chinese pavilion in Villiers de l’Isle Adam’s story, “Le
Secret de l’ancienne Musique.” It is music that regulates the heart
and mind and with that development brings joy, and joy brings
repose. And so “Man became Heaven.” “Let ceremonies and music
have their course until the earth is filled with them!”
It is sometimes said that among Chinese moralists and philosophers
Lao-tze, the deepest of them all, alone stands aside from the chorus
in praise of music and ceremony. When once Confucius came to
consult Lao-tze concerning the rules of propriety, and reverence for
the teaching of the sages of antiquity, we are told, Lao-tze replied:
“The men of whom you speak, sir, have, if you please, together with
their bones, mouldered.” Confucius went away, puzzled if not
dissatisfied He was willing to work not only from within outwards,
but from without inwards, because he allowed so large a place for
social solidity, for traditionalism, for paternalism, though he
recognised that ceremony is subordinate in the scheme of life, as
colour is in a painting, the picture being the real thing. Lao-tze was
an individualist and a mystic. He was little concerned with moralities
in the ordinary sense. He recognised no action but from within
outwards. But though Confucius could scarcely have altogether
grasped his conception, he was quite able to grasp that of Confucius,
and his indifference to tradition, to rule and propriety was simply an
insistence on essential reality, on “music.” “Ceremonies,” he said,
“are the outward expression of inward feeling.” He was no more
opposed to the fundamental Chinese conception than George Fox
was opposed to Christianity in refusing to observe the mere forms
and ceremonies of the Church. A sound Confucianism is the outward
manifestation of Taoism (as Lao-tze himself taught it), just as a
sound socialism is the outward manifestation of a genuine
individualism. It has been well said that Chinese socialistic solidarity
rests on an individualistic basis, it is not a bureaucratic State
socialism; it works from within outward. (One of the first European
visitors to China remarked that there a street was like a home.) This
is well shown by so great and typical a Chinese philosopher as Meh-
ti,[8] who lived shortly after Confucius, in the fifth century B.C. He
taught universal love, with universal equality, and for him to love
meant to act. He admitted an element of self-interest as a motive for
such an attitude. He desired to universalise mutual self-help.
Following Confucius, but yet several centuries before Jesus, he
declared that a man should love his neighbour, his fellow man, as
himself. “When he sees his fellow hungry, he feeds him; when he
sees him cold, he clothes him; ill, he nurses him; dead, he buries
him.” This, he said, was by no means opposed to filial piety; for if
one cares for the parents of others, they in turn will care for his. But,
it was brought against him, the power of egoism? The Master
agreed. Yet, he said, Man accepts more difficult things. He can
renounce joy, life itself, for even absurd and ridiculous ends. A single
generation, he added, such is the power of imitation, might suffice
to change a people’s customs. But Meh-ti remained placid. He
remarked that the great ones of the earth were against human
solidarity and equality; he left it at that. He took no refuge in
mysticism. Practical social action was the sole end he had in view,
and we have to remember that his ideals are largely embodied in
Chinese institutions.[9]
We may understand now how it is that in China, and in China alone
among the great surviving civilisations, we find that art animates the
whole of life, even its morality. “This universal presence of art,”
É
remarks an acute yet discriminating observer, Émile Hovelaque,
whom I have already quoted,[10] “manifested in the smallest utensil,
the humblest stalls, the notices on the shops, the handwriting, the
rhythm of movement, always regular and measured, as though to
the tune of unheard music, announces a civilisation which is
complete in itself, elaborated in the smallest detail, penetrated by
one spirit, which no interruption ever breaks, a harmony which
becomes at length a hallucinatory and overwhelming obsession.” Or,
as another writer has summed up the Chinese attitude: “For them
the art of life is one, as this world and the other are one. Their aim
is to make the Kingdom of Heaven here and now.”
It is obvious that a natural temperament in which the art-impulse is
so all-embracing, and the æsthetic sensibility so acute, might well
have been of a perilous instability. We could scarcely have been
surprised if, like that surpassing episode in Egyptian history of which
Akhenaten was the leader and Tell-el-Amarna the tomb, it had only
endured for a moment. Yet Chinese civilisation, which has
throughout shown the dominating power of this sensitive
temperament, has lasted longer than any other. The reason is that
the very excesses of their temperament forced the Chinese to fortify
themselves against its perils. The Great Wall, built more than two
thousand years ago, and still to-day almost the most impressive
work of man on the earth, is typical of this attitude of the Chinese.
They have exercised a stupendous energy in fortifying themselves
against the natural enemies of their own temperament. When one
looks at it from this point of view, it is easy to see that, alike in its
large outlines and its small details, Chinese life is always the art of
balancing an æsthetic temperament and guarding against its
excesses. We see this in the whole of the ancient and still prevailing
system of Confucian morality with its insistence on formal ceremony,
even when, departing from the thought of its most influential
founder,—for ceremonialism in China would have existed even if
Confucius had not lived,—it tended to become merely an external
formalism. We see it in the massive solidarity of Chinese life, the
systematic social organisation by which individual responsibility, even
though leaving individuality itself intact, is merged in the
responsibility of the family and the still larger group. We see it in the
whole drift of Chinese philosophy, which is throughout sedative and
contemplative. We see it in the element of stoicism on the one hand
and cruelty on the other which in so genuinely good-natured a
people would otherwise seem puzzling. The Chinese love of flowers
and gardens and landscape scenery is in the same direction, and
indeed one may say much the same of Chinese painting and Chinese
poetry.[11] That is why it is only to-day that we in the West have
reached the point of nervous susceptibility which enables us in some
degree to comprehend the æsthetic supremacy which the Chinese
reached more than a thousand years ago.
Thus, during its extremely long history—for the other great
civilisations with which it was once contemporary have passed away
or been disintegrated and transformed—Chinese civilisation has
borne witness to the great fact that all human life is art. It may be
because they have realised this so thoroughly that the Chinese have
been able to preserve their civilisation so long, through all the
violent shocks to which it has been subjected. There can be no
doubt, however, that, during the greater part of the last thousand
years, there has been, however slow and gradual, a decline in the
vitality of Chinese civilisation, largely due, it may well be, to the
crushing pressure of an excessive population. For, however
remarkable the admiration which China arouses even to-day, its
finest flowering periods in the special arts lie far in the past, while in
the art of living itself the Chinese have long grown languid. The
different reports of ancient and modern travellers regarding one
definite social manifestation, the prevalence of beggary, cannot fail
to tell us something regarding the significant form of their social life.
Modern travellers complain of the plague constituted by the
prevalence of beggars in China; they are even a fixed and
permanent institution on a trades-union basis. But in the sixteenth
century Galeotto Perera noticed with surprise in China the absence
of beggars, as Marco Polo had before him, and Friar Gaspar de Cruz
remarked that the Chinese so abhorred idleness that they gave no
alms to the poor and mocked at the Portuguese for doing so: “Why
give alms to a knave? Let him go and earn it.” Their own priests, he
adds, they sometimes whipped as being knaves. (It should be noted
at the same time that it was considered reasonable only to give half
the day to work, the other half to joy and recreation.) But they built
great asylums for the helpless poor, and found employment for blind
women, gorgeously dressed and painted with ceruse and vermilion,
as prostitutes, who were more esteemed in early China than they
have been since. That is a curious instance of the unflinching
practicality still shown by the Chinese in endless ways. The
undoubted lassitude in the later phases of this long-lived Chinese
culture has led to features in the art of life, such as beggary and dirt
among the poor, not manifested in the younger offshoot of Chinese
and Korean culture in Japan, though it is only fair to point out that
impartial English observers, like Parker, consider this prevalence of
vermin and dirt as simply due to the prevalence of poverty, and not
greater than we find among the poor in England and elsewhere in
the West. Marco Polo speaks of three hundred public baths in one
city alone in his time. We note also that in the more specialised arts
the transcendence of China belongs to the past, and even
sometimes a remote past. It is so in the art of philosophy, and the
arts of poetry and painting. It is so also in the art of pottery, in
which Chinese supremacy over the rest of the world has been
longest recognised—has not the word “china” for centuries been our
name for the finest pottery?—and is most beyond measure. Our
knowledge of the pottery of various cultures excels that of any other
human products because of all it is the most perdurable. We can
better estimate their relative æsthetic worth now than in the days
when a general reverence for Greek antiquity led to a popular belief
in the beauty of Greek pottery, though scarcely a single type of its
many forms can fairly be so considered or even be compared to the
products of the Minoan predecessors of Greek culture, however
interesting they may still remain for us as the awkward and
inappropriate foundation for exquisite little pictures. The greatest
age of this universal human art was in China and was over many
centuries ago. But with what devotion, with what absolute
concentration of the spirit, the Chinese potters of the great period
struggled with the problem of art is finely illustrated by the well-
known story which an old Chinese historian tells of the sacrifice of
the divine T’ung, the spirit who protects potters. It happened that a
complicated problem had baffled the potters. T’ung laid down his life
to serve them and to achieve the solution of the problem. He
plunged into the fire and the bowl came out perfect. “The vessel’s
perfect glaze is the god’s fat and blood; the body material is the
god’s body of flesh; the blue of the decoration, with the brilliant
lustre of gems, is the essence of the god’s pure spirit.” That story
embodies the Chinese symbol of the art of living, just as we embody
our symbol of that art in the Crucifixion of Jesus. The form is
diverse; the essence is the same.
V

It will be seen that when we analyse the experiences of life and look
at it simply, in the old-fashioned way, liberated from the artificial
complexities of a temporary and now, it may be, departing
civilisation, what we find is easy to sum up. We find, that is to say,
that Man has forced himself to move along this line, and that line,
and the other line. But it is the same water of life that runs in all
these channels. Until we have ascended to a height where this is
clear, to see all our little dogmatisms will but lead us astray.
We may illuminatingly change the analogy and turn to the field of
chemistry. All these various elements of life are but, as it were,
allotropic forms of the same element. The most fundamental among
these forms is that of art, for life in all its forms, even morality in the
narrowest sense, is, as Duprat has argued, a matter of technique,
and technique at once brings us to the elements of art. If we would
understand what we are dealing with, we may, therefore, best study
these forms under that of art.
There is, however, a deeper chemical analogy than this to be seen.
It may well be, indeed, that it is more than an analogy. In chemistry
we are dealing, not merely with the elements of life, but with the
elements of the world, even of what we call our universe. It is not
unreasonable to think that the same law holds good for both. We
see that the forms of life may all be found, and then better
understood, in one form. Some day, perhaps, we shall also see that
that fact is only a corollary of the larger fact—or, if any one prefers
so to regard it, the smaller fact—that the chemical elements of our
world can be regarded as all only transmutations of one element.
From of old, men instinctively divined that this might be so, though
they were merely concerned to change the elements into gold, the
element which they most highly valued. In our own times this
transmutation is beginning to become, on a minute scale, a
demonstrable fact, though it would seem easier to transmute
elements into lead than into gold. Matter, we are thus coming to see,
may not be a confused variety of separate substances, but simply a
different quantitative arrangement of a single fundamental stuff,
which might possibly be identical with hydrogen or some other
already known element. Similarly we may now believe that the men
of old who thought that all human life was made of one stuff were
not altogether wrong, and we may, with greater assurance than they
were able to claim, analyse the modes of human action into different
quantitative or other arrangements of which the most fundamental
may well be identical with art.
This may perhaps become clearer if we consider more in detail one
of the separate arts, selecting the most widely symbolic of all, the
art that is most clearly made of the stuff of life, and so able to
translate most truly and clearly into beautiful form the various
modalities of life.
CHAPTER II
THE ART OF DANCING
I

Dancing and building are the two primary and essential arts. The art
of dancing stands at the source of all the arts that express
themselves first in the human person. The art of building, or
architecture, is the beginning of all the arts that lie outside the
person; and in the end they unite. Music, acting, poetry proceed in
the one mighty stream; sculpture, painting, all the arts of design, in
the other. There is no primary art outside these two arts, for their
origin is far earlier than man himself; and dancing came first.[12]
That is one reason why dancing, however it may at times be scorned
by passing fashions, has a profound and eternal attraction even for
those one might suppose farthest from its influence. The joyous beat
of the feet of children, the cosmic play of philosophers’ thoughts rise
and fall according to the same laws of rhythm. If we are indifferent
to the art of dancing, we have failed to understand, not merely the
supreme manifestation of physical life, but also the supreme symbol
of spiritual life.
The significance of dancing, in the wide sense, thus lies in the fact
that it is simply an intimate concrete appeal of a general rhythm,
that general rhythm which marks, not life only, but the universe, if
one may still be allowed so to name the sum of the cosmic
influences that reach us. We need not, indeed, go so far as the
planets or the stars and outline their ethereal dances. We have but
to stand on the seashore and watch the waves that beat at our feet,
to observe that at nearly regular intervals this seemingly
monotonous rhythm is accentuated for several beats, so that the
waves are really dancing the measure of a tune. It need surprise us
not at all that rhythm, ever tending to be moulded into a tune,
should mark all the physical and spiritual manifestations of life.
Dancing is the primitive expression alike of religion and of love—of
religion from the earliest human times we know of and of love from
a period long anterior to the coming of man. The art of dancing,
moreover, is intimately entwined with all human tradition of war, of
labour, of pleasure, of education, while some of the wisest
philosophers and the most ancient civilisations have regarded the
dance as the pattern in accordance with which the moral life of men
must be woven. To realise, therefore, what dancing means for
mankind—the poignancy and the many-sidedness of its appeal—we
must survey the whole sweep of human life, both at its highest and
at its deepest moments.
II

“What do you dance?” When a man belonging to one branch of the


great Bantu division of mankind met a member of another, said
Livingstone, that was the question he asked. What a man danced,
that was his tribe, his social customs, his religion; for, as an
anthropologist has put it, “a savage does not preach his religion, he
dances it.”
There are peoples in the world who have no secular dances, only
religious dances; and some investigators believe with Gerland that
every dance was of religious origin. That view may seem too
extreme, even if we admit that some even of our modern dances,
like the waltz, may have been originally religious. Even still (as
Skene has shown among the Arabs and Swahili of Africa) so various
are dances and their functions among some peoples that they cover
the larger part of life. Yet we have to remember that for primitive
man there is no such thing as religion apart from life, for religion
covers everything. Dancing is a magical operation for the attainment
of real and important ends of every kind. It was clearly of immense
benefit to the individual and to society, by imparting strength and
adding organised harmony. It seemed reasonable to suppose that it
attained other beneficial ends, that were incalculable, for calling
down blessings or warding off misfortunes. We may conclude, with
Wundt, that the dance was, in the beginning, the expression of the
whole man, for the whole man was religious.[13]
Thus, among primitive peoples, religion being so large a part of life,
the dance inevitably becomes of supreme religious importance. To
dance was at once both to worship and to pray. Just as we still find
in our Prayer Books that there are divine services for all the great
fundamental acts of life,—for birth, for marriage, for death,—as well
as for the cosmic procession of the world as marked by ecclesiastical
festivals, and for the great catastrophes of nature, such as droughts,
so also it has ever been among primitive peoples. For all the solemn
occasions of life, for bridals and for funerals, for seed-time and for
harvest, for war and for peace, for all these things there were fitting
dances. To-day we find religious people who in church pray for rain
or for the restoration of their friends to health. Their forefathers also
desired these things, but, instead of praying for them, they danced
for them the fitting dance which tradition had handed down, and
which the chief or the medicine-man solemnly conducted. The gods
themselves danced, as the stars dance in the sky—so at least the
Mexicans, and we may be sure many other peoples, have held; and
to dance is therefore to imitate the gods, to work with them,
perhaps to persuade them to work in the direction of our own
desires. “Work for us!” is the song-refrain, expressed or implied, of
every religious dance. In the worship of solar deities in various
countries, it was customary to dance round the altar, as the stars
dance round the sun. Even in Europe the popular belief that the sun
dances on Easter Sunday has perhaps scarcely yet died out. To
dance is to take part in the cosmic control of the world. Every sacred
Dionysian dance is an imitation of the divine dance.
All religions, and not merely those of primitive character, have been
at the outset, and sometimes throughout, in some measure
saltatory. That was recognised even in the ancient world by acute
observers, like Lucian, who remarks in his essay on dancing that
“you cannot find a single ancient mystery in which there is no
dancing; in fact most people say of the devotees of the Mysteries
that ‘they dance them out.’” This is so all over the world. It is not
more pronounced in early Christianity, and among the ancient
Hebrews who danced before the ark, than among the Australian
aborigines whose great corroborees are religious dances conducted
by the medicine-men with their sacred staves in their hands. Every
American Indian tribe seems to have had its own religious dances,
varied and elaborate, often with a richness of meaning which the
patient study of modern investigators has but slowly revealed. The
Shamans in the remote steppes of Northern Siberia have their
ecstatic religious dances, and in modern Europe the Turkish
dervishes—perhaps of related stock—still dance in their cloisters
similar ecstatic dances, combined with song and prayer, as a regular
part of devotional service.
These religious dances, it may be observed, are sometimes ecstatic,
sometimes pantomimic. It is natural that this should be so. By each
road it is possible to penetrate towards the divine mystery of the
world. The auto-intoxication of rapturous movement brings the
devotees, for a while at least, into that self-forgetful union with the
not-self which the mystic ever seeks. The ecstatic Hindu dance in
honour of the pre-Aryan hill god, afterwards Siva, became in time a
great symbol, “the clearest image of the activity of God,” it has been
called, “which any art or religion can boast of.”[14] Pantomimic
dances, on the other hand, with their effort to heighten natural
expression and to imitate natural process, bring the dancers into the
divine sphere of creation and enable them to assist vicariously in the
energy of the gods. The dance thus becomes the presentation of a
divine drama, the vital reënactment of a sacred history, in which the
worshipper is enabled to play a real part.[15] In this way ritual arises.
It is in this sphere—highly primitive as it is—of pantomimic dancing
crystallised in ritual, rather than in the sphere of ecstatic dancing,
that we may to-day in civilisation witness the survivals of the dance
in religion. The divine services of the American Indian, said Lewis
Morgan, took the form of “set dances, each with its own name,
songs, steps, and costume.” At this point the early Christian,
worshipping the Divine Body, was able to join in spiritual communion
with the ancient Egyptian or the later Japanese[16] or the modern
American Indian. They are all alike privileged to enter, each in his
own way, a sacred mystery, and to participate in the sacrifice of a
heavenly Mass.
What by some is considered to be the earliest known Christian ritual
—the “Hymn of Jesus” assigned to the second century—is nothing
but a sacred dance. Eusebius in the third century stated that Philo’s
description of the worship of the Therapeuts agreed at all points
with Christian custom, and that meant the prominence of dancing, to
which indeed Eusebius often refers in connection with Christian
worship. It has been supposed by some that the Christian Church
was originally a theatre, the choir being the raised stage, even the
word “choir,” it is argued, meaning an enclosed space for dancing. It
is certain that at the Eucharist the faithful gesticulated with their
hands, danced with their feet, flung their bodies about. Chrysostom,
who referred to this behaviour round the Holy Table at Antioch, only
objected to drunken excesses in connection with it; the custom itself
he evidently regarded as traditional and right.
While the central function of Christian worship is a sacred drama, a
divine pantomime, the associations of Christianity and dancing are
by no means confined to the ritual of the Mass and its later more
attenuated transformations. The very idea of dancing had a sacred
and mystic meaning to the early Christians, who had meditated
profoundly on the text, “We have piped unto you and ye have not
danced.” Origen prayed that above all things there may be made
operative in us the mystery “of the stars dancing in Heaven for the
salvation of the Universe.” So that the monks of the Cistercian Order,
who in a later age worked for the world more especially by praying
for it (“orare est laborare”), were engaged in the same task on earth
as the stars in Heaven; dancing and praying are the same thing. St.
Basil, who was so enamoured of natural things, described the angels
dancing in Heaven, and later the author of the “Dieta Salutis” (said
to have been St. Bonaventura), which is supposed to have
influenced Dante in assigning so large a place to dancing in the
“Paradiso,” described dancing as the occupation of the inmates of
Heaven, and Christ as the leader of the dance. Even in more modern
times an ancient Cornish carol sang of the life of Jesus as a dance,
and represented him as declaring that he died in order that man
“may come unto the general dance.”[17]
This attitude could not fail to be reflected in practice. Genuine
dancing, not merely formalised and unrecognisable dancing, such as
the traditionalised Mass, must have been frequently introduced into
Christian worship in early times. Until a few centuries ago it
remained not uncommon, and it even still persists in remote corners
of the Christian world. In English cathedrals dancing went on until
the fourteenth century. At Paris, Limoges, and elsewhere in France,
the priests danced in the choir at Easter up to the seventeenth
century, in Roussillon up to the eighteenth century. Roussillon is a
Catalan province with Spanish traditions, and it is in Spain, where
dancing is a deeper and more passionate impulse than elsewhere in
Europe, that religious dancing took firmest root and flourished
longest. In the cathedrals of Seville, Toledo, Valencia, and Jeres
there was formerly dancing, though it now only survives at a few
special festivals in the first.[18] At Alaro in Mallorca, also at the
present day, a dancing company called Els Cosiers, on the festival of
St. Roch, the patron saint of the place, dance in the church in
fanciful costumes with tambourines, up to the steps of the high altar,
immediately after Mass, and then dance out of the church. In
another part of the Christian world, in the Abyssinian Church—an
offshoot of the Eastern Church—dancing is also said still to form part
of the worship.
Dancing, we may see throughout the world, has been so essential,
so fundamental, a part of all vital and undegenerate religion, that,
whenever a new religion appears, a religion of the spirit and not
merely an anæmic religion of the intellect, we should still have to
ask of it the question of the Bantu: “What do you dance?”
III

Dancing is not only intimately associated with religion, it has an


equally intimate association with love. Here, indeed, the relationship
is even more primitive, for it is far older than man. Dancing, said
Lucian, is as old as love. Among insects and among birds it may be
said that dancing is often an essential part of love. In courtship the
male dances, sometimes in rivalry with other males, in order to
charm the female; then, after a short or long interval, the female is
aroused to share his ardour and join in the dance; the final climax of
the dance is the union of the lovers. Among the mammals most
nearly related to man, indeed, dancing is but little developed: their
energies are more variously diffused, though a close observer of the
apes, Dr. Louis Robinson, has pointed out that the “spasmodic
jerking of the chimpanzee’s feeble legs,” pounding the partition of
his cage, is the crude motion out of which “the heavenly alchemy of
evolution has created the divine movements of Pavlova”; but it must
be remembered that the anthropoid apes are offshoots only from the
stock that produced Man, his cousins and not his ancestors. It is the
more primitive love-dance of insects and birds that seems to
reappear among human savages in various parts of the world,
notably in Africa, and in a conventionalised and symbolised form it is
still danced in civilisation to-day. Indeed, it is in this aspect that
dancing has so often aroused reprobation, from the days of early
Christianity until the present, among those for whom the dance has
merely been, in the words of a seventeenth-century writer, a series
of “immodest and dissolute movements by which the cupidity of the
flesh is aroused.”
But in nature and among primitive peoples it has its value precisely
on this account. It is a process of courtship and, even more than
that, it is a novitiate for love, and a novitiate which was found to be
an admirable training for love. Among some peoples, indeed, as the
Omahas, the same word meant both to dance and to love. By his
beauty, his energy, his skill, the male must win the female, so
impressing the image of himself on her imagination that finally her
desire is aroused to overcome her reticence. That is the task of the
male throughout nature, and in innumerable species besides Man it
has been found that the school in which the task may best be learnt
is the dancing-school. Those who have not the skill and the strength
to learn are left behind, and, as they are probably the least capable
members of the race, it may be in this way that a kind of sexual
selection has been embodied in unconscious eugenics, and aided the
higher development of the race. The moths and the butterflies, the
African ostrich and the Sumatran argus pheasant, with their fellows
innumerable, have been the precursors of man in the strenuous
school of erotic dancing, fitting themselves for selection by the
females of their choice as the most splendid progenitors of the
future race.[19]
From this point of view, it is clear, the dance performed a double
function. On the one hand, the tendency to dance, arising under the
obscure stress of this impulse, brought out the best possibilities the
individual held the promise of; on the other hand, at the moment of
courtship, the display of the activities thus acquired developed on
the sensory side all the latent possibilities of beauty which at last
became conscious in man. That this came about we cannot easily
escape concluding. How it came about, how it happens that some of
the least intelligent of creatures thus developed a beauty and a
grace that are enchanting even to our human eyes, is a miracle,
even if not affected by the mystery of sex, which we cannot yet
comprehend.
When we survey the human world, the erotic dance of the animal
world is seen not to have lost, but rather to have gained, influence.
It is no longer the males alone who are thus competing for the love
of the females. It comes about by a modification in the earlier
method of selection that often not only the men dance for the
women, but the women for the men, each striving in a storm of
rivalry to arouse and attract the desire of the other. In innumerable
parts of the world the season of love is a time which the nubile of
each sex devote to dancing in each other’s presence, sometimes one
sex, sometimes the other, sometimes both, in the frantic effort to
display all the force and energy, the skill and endurance, the beauty
and grace, which at this moment are yearning within them to be
poured into the stream of the race’s life.
From this point of view we may better understand the immense
ardour with which every part of the wonderful human body has been
brought into the play of the dance. The men and women of races
spread all over the world have shown a marvellous skill and patience
in imparting rhythm and measure to the most unlikely, the most
rebellious regions of the body, all wrought by desire into potent and
dazzling images. To the vigorous races of Northern Europe in their
cold damp climate, dancing comes naturally to be dancing of the
legs, so naturally that the English poet, as a matter of course,
assumes that the dance of Salome was a “twinkling of the feet.”[20]
But on the opposite side of the world, in Japan and notably in Java
and Madagascar, dancing may be exclusively dancing of the arms
and hands, in some of the South Sea Islands of the hands and
fingers alone. Dancing may even be carried on in the seated
posture, as occurs at Fiji in a dance connected with the preparation
of the sacred drink, ava. In some districts of Southern Tunisia
dancing, again, is dancing of the hair, and all night long, till they
perhaps fall exhausted, the marriageable girls will move their heads
to the rhythm of a song, maintaining their hair in perpetual balance
and sway. Elsewhere, notably in Africa, but also sometimes in
Polynesia, as well as in the dances that had established themselves
in ancient Rome, dancing is dancing of the body, with vibratory or
rotatory movements of breasts or flanks. The complete dance along
these lines is, however, that in which the play of all the chief muscle-
groups of the body is harmoniously interwoven. When both sexes
take part in such an exercise, developed into an idealised yet
passionate pantomime of love, we have the complete erotic dance.
In the beautiful ancient civilisation of the Pacific, it is probable that
this ideal was sometimes reached, and at Tahiti, in 1772, an old
voyager crudely and summarily described the native dance as “an
endless variety of posturings and wagglings of the body, hands, feet,
eyes, lips, and tongue, in which they keep splendid time to the
measure.” In Spain the dance of this kind has sometimes attained its
noblest and most harmoniously beautiful expression. From the
narratives of travellers, it would appear that it was especially in the
eighteenth century that among all classes in Spain dancing of this
kind was popular. The Church tacitly encouraged it, an Aragonese
Canon told Baretti in 1770, in spite of its occasional indecorum, as a
useful safety-valve for the emotions. It was not less seductive to the
foreign spectator than to the people themselves. The grave traveller
Peyron, towards the end of the century, growing eloquent over the
languorous and flexible movements of the dance, the bewitching
attitude, the voluptuous curves of the arms, declares that, when one
sees a beautiful Spanish woman dance, one is inclined to fling all
philosophy to the winds. And even that highly respectable Anglican
clergyman, the Reverend Joseph Townsend, was constrained to state
that he could “almost persuade myself” that if the fandango were
suddenly played in church the gravest worshippers would start up to
join in that “lascivious pantomime.” There we have the rock against
which the primitive dance of sexual selection suffers shipwreck as
civilisation advances. And that prejudice of civilisation becomes so
ingrained that it is brought to bear even on the primitive dance. The
pygmies of Africa are described by Sir H. H. Johnston as a very
decorous and highly moral people, but their dances, he adds, are not
so. Yet these dances, though to the eyes of Johnston, blinded by
European civilisation, “grossly indecent,” he honestly, and
inconsistently, adds, are “danced reverently.”
IV

From the vital function of dancing in love, and its sacred function in
religion, to dancing as an art, a profession, an amusement, may
seem, at the first glance, a sudden leap. In reality the transition is
gradual, and it began to be made at a very early period in diverse
parts of the globe. All the matters that enter into courtship tend to
fall under the sway of art; their æsthetic pleasure is a secondary
reflection of their primary vital joy. Dancing could not fail to be first
in manifesting this tendency. But even religious dancing swiftly
exhibited the same transformation; dancing, like priesthood, became
a profession, and dancers, like priests, formed a caste. This, for
instance, took place in old Hawaii. The hula dance was a religious
dance; it required a special education and an arduous training;
moreover, it involved the observance of important taboos and the
exercise of sacred rites; by the very fact of its high specialisation it
came to be carried out by paid performers, a professional caste. In
India, again, the Devadasis, or sacred dancing girls, are at once both
religious and professional dancers. They are married to gods, they
are taught dancing by the Brahmins, they figure in religious
ceremonies, and their dances represent the life of the god they are
married to as well as the emotions of love they experience for him.
Yet, at the same time, they also give professional performances in
the houses of rich private persons who pay for them. It thus comes
about that to the foreigner the Devadasis scarcely seem very unlike
the Ramedjenis, the dancers of the street, who are of very different
origin, and mimic in their performances the play of merely human
passions. The Portuguese conquerors of India called both kinds of
dancers indiscriminately Balheideras (or dancers) which we have
corrupted in Bayaderes.[21]
In our modern world professional dancing as an art has become
altogether divorced from religion, and even, in any biological sense,
from love; it is scarcely even possible, so far as Western civilisation
is concerned, to trace back the tradition to either source. If we
survey the development of dancing as an art in Europe, it seems to
me that we have to recognise two streams of tradition which have
sometimes merged, but yet remain in their ideals and their
tendencies essentially distinct. I would call these traditions the
Classical, which is much the more ancient and fundamental, and
may be said to be of Egyptian origin, and the Romantic, which is of
Italian origin, chiefly known to us as the ballet. The first is, in its
pure form, solo dancing—though it may be danced in couples and
many together—and is based on the rhythmic beauty and
expressiveness of the simple human personality when its energy is
concentrated in measured yet passionate movement. The second is
concerted dancing, mimetic and picturesque, wherein the individual
is subordinated to the wider and variegated rhythm of the group. It
may be easy to devise another classification, but this is simple and
instructive enough for our purpose.
There can scarcely be a doubt that Egypt has been for many
thousands of years, as indeed it still remains, a great dancing centre,
the most influential dancing-school the world has ever seen,
radiating its influence to south and east and north. We may perhaps
even agree with the historian of the dance who terms it “the
mother-country of all civilised dancing.” We are not entirely
dependent on the ancient wall-pictures of Egypt for our knowledge
of Egyptian skill in the art. Sacred mysteries, it is known, were
danced in the temples, and queens and princesses took part in the
orchestras that accompanied them. It is significant that the musical
instruments still peculiarly associated with the dance were originated
or developed in Egypt; the guitar is an Egyptian instrument and its
name was a hieroglyph already used when the Pyramids were being
built; the cymbal, the tambourine, triangles, castanets, in one form
or another, were all familiar to the ancient Egyptians, and with the
Egyptian art of dancing they must have spread all round the shores
of the Mediterranean, the great focus of our civilisation, at a very
early date.[22] Even beyond the Mediterranean, at Cadiz, dancing that
was essentially Egyptian in character was established, and Cadiz
became the dancing-school of Spain. The Nile and Cadiz were thus
the two great centres of ancient dancing, and Martial mentions them
both together, for each supplied its dancers to Rome. This dancing,
alike whether Egyptian or Gaditanian, was the expression of the
individual dancer’s body and art; the garments played but a small
part in it, they were frequently transparent, and sometimes
discarded altogether. It was, and it remains, simple, personal,
passionate dancing, classic, therefore, in the same sense as, on the
side of literature, the poetry of Catullus is classic.[23]
Ancient Greek dancing was essentially classic dancing, as here
understood. On the Greek vases, as reproduced in Emmanuel’s
attractive book on Greek dancing and elsewhere, we find the same
play of the arms, the same sideward turn, the same extreme
backward extension of the body, which had long before been
represented in Egyptian monuments. Many supposedly modern
movements in dancing were certainly already common both to
Egyptian and Greek dancing, as well as the clapping of hands to
keep time which is still an accompaniment of Spanish dancing. It
seems clear, however, that, on this general classic and Mediterranean
basis, Greek dancing had a development so refined and so special—
though in technical elaboration of steps, it seems likely, inferior to
modern dancing—that it exercised no influence outside Greece.
Dancing became, indeed, the most characteristic and the most
generally cultivated of Greek arts. Pindar, in a splendid Oxyrhynchine
fragment, described Hellas, in what seemed to him supreme praise,
as “the land of lovely dancing,” and Athenæus pointed out that he
calls Apollo the Dancer. It may well be that the Greek drama arose
out of dance and song, and that the dance throughout was an
essential and plastic element in it. Even if we reject the statement of
Aristotle that tragedy arose out of the Dionysian dithyramb, the
alternative suppositions (such as Ridgeway’s theory of dancing round
the tombs of the dead) equally involve the same elements. It has
often been pointed out that poetry in Greece demanded a practical
knowledge of all that could be included under “dancing.” Æschylus is
said to have developed the technique of dancing and Sophocles
danced in his own dramas. In these developments, no doubt, Greek
dancing tended to overpass the fundamental limits of classic dancing
and foreshadowed the ballet.[24]
The real germ of the ballet, however, is to be found in Rome, where
the pantomime with its concerted and picturesque method of
expressive action was developed, and Italy is the home of Romantic
dancing. The same impulse which produced the pantomime
produced, more than a thousand years later in the same Italian
region, the modern ballet. In both cases, one is inclined to think, we
may trace the influence of the same Etruscan and Tuscan race which
so long has had its seat there, a race with a genius for expressive,
dramatic, picturesque art. We see it on the walls of Etruscan tombs
and again in pictures of Botticelli and his fellow Tuscans. The
modern ballet, it is generally believed, had its origin in the
spectacular pageants at the marriage of Galeazzo Visconti, Duke of
Milan, in 1489. The fashion for such performances spread to the
other Italian courts, including Florence, and Catherine de’ Medici,
when she became Queen of France, brought the Italian ballet to
Paris. Here it speedily became fashionable. Kings and queens were
its admirers and even took part in it; great statesmen were its
patrons. Before long, and especially in the great age of Louis XIV, it
became an established institution, still an adjunct of opera but with
a vital life and growth of its own, maintained by distinguished
musicians, artists, and dancers. Romantic dancing, to a much
greater extent than what I have called Classic dancing, which
depends so largely on simple personal qualities, tends to be vitalised
by transplantation and the absorption of new influences, provided
that the essential basis of technique and tradition is preserved in the
new development. Lulli in the seventeenth century brought women
into the ballet; Camargo discarded the complicated costumes and
shortened the skirt, so rendering possible not only her own lively
and vigorous method, but all the freedom and airy grace of later
dancing. It was Noverre who by his ideas worked out at Stuttgart,
and soon brought to Paris by Gaetan Vestris, made the ballet a new
and complete art form; this Swiss-French genius not only elaborated
plot revealed by gesture and dance alone, but, just as another and
greater Swiss-French genius about the same time brought sentiment
and emotion into the novel, he brought it into the ballet. In the
French ballet of the eighteenth century a very high degree of
perfection seems thus to have been reached, while in Italy, where
the ballet had originated, it decayed, and Milan, which had been its
source, became the nursery of a tradition of devitalised technique
carried to the finest point of delicate perfection. The influence of the
French school was maintained as a living force into the nineteenth
century,—when it was renovated afresh by the new spirit of the age
and Taglioni became the most ethereal embodiment of the spirit of
the Romantic movement in a form that was genuinely classic,—
overspreading the world by the genius of a few individual dancers.
When they had gone, the ballet slowly and steadily declined. As it
declined as an art, so also it declined in credit and in popularity; it
became scarcely respectable even to admire dancing. Thirty or forty
years ago, those of us who still appreciated dancing as an art—and
how few they were!—had to seek for it painfully and sometimes in
strange surroundings. A recent historian of dancing, in a book
published so lately as 1906, declared that “the ballet is now a thing
of the past, and, with the modern change of ideas, a thing that is
never likely to be resuscitated.” That historian never mentioned
Russian ballet, yet his book was scarcely published before the
Russian ballet arrived to scatter ridicule over his rash prophecy by
raising the ballet to a pitch of perfection it can rarely have
surpassed, as an expressive, emotional, even passionate form of
living art.
The Russian ballet was an offshoot from the French ballet and
illustrates once more the vivifying effect of transplantation on the art
of Romantic dancing. The Empress Anna introduced it in 1735 and
appointed a French ballet-master and a Neapolitan composer to
carry it on; it reached a high degree of technical perfection during
the following hundred years, on the traditional lines, and the
principal dancers were all imported from Italy. It was not until recent
years that this firm discipline and these ancient traditions were
vitalised into an art form of exquisite and vivid beauty by the
influence of the soil in which they had slowly taken root. This
contact, when at last it was effected, mainly by the genius of Fokine
and the enterprise of Diaghilev, involved a kind of revolution, for its
outcome, while genuine ballet, has yet all the effect of delicious
novelty. The tradition by itself was in Russia an exotic without real
life, and had nothing to give to the world; on the other hand, a
Russian ballet apart from that tradition, if we can conceive such a
thing, would have been formless, extravagant, bizarre, not subdued
to any fine æsthetic ends. What we see here, in the Russian ballet
as we know it to-day, is a splendid and arduous technical tradition,
brought at last—by the combined skill of designers, composers, and
dancers—into real fusion with an environment from which during
more than a century it had been held apart; Russian genius for
music, Russian feeling for rhythm, Russian skill in the use of bright
colour, and, not least, the Russian orgiastic temperament, the
Russian spirit of tender poetic melancholy, and the general Slav
passion for folk-dancing, shown in other branches of the race also,
Polish, Bohemian, Bulgarian, and Servian. At almost the same time
what I have termed Classic dancing was independently revived in
America by Isadora Duncan, bringing back what seemed to be the
free naturalism of the Greek dance, and Ruth St. Denis, seeking to
discover and revitalise the secrets of the old Indian and Egyptian
traditions. Whenever now we find any restored art of theatrical
dancing, as in the Swedish ballet, it has been inspired more or less,
by an eclectic blending of these two revived forms, the Romantic
from Russia, the Classic from America. The result has been that our
age sees one of the most splendid movements in the whole history
of the ballet.
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!

ebookname.com

You might also like