Full Download iOS SDK Programming A Beginners Guide 1st Edition James Brannan PDF DOCX
Full Download iOS SDK Programming A Beginners Guide 1st Edition James Brannan PDF DOCX
com
https://ebookname.com/product/ios-sdk-programming-a-
beginners-guide-1st-edition-james-brannan/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/iphone-sdk-programming-a-beginner-s-
guide-5th-edition-james-brannan/
ebookname.com
https://ebookname.com/product/beginning-ios-5-development-exploring-
the-ios-sdk-1st-edition-dave-mark/
ebookname.com
https://ebookname.com/product/beginning-iphone-4-development-
exploring-the-ios-sdk-1st-edition-david-mark/
ebookname.com
https://ebookname.com/product/digital-cities-architectural-
design-07-08-2009-vol-79-n-4-1st-edition-neil-leach/
ebookname.com
Labor Relations in the Aviation and Aerospace Industries
1st Edition Robert W. Kaps
https://ebookname.com/product/labor-relations-in-the-aviation-and-
aerospace-industries-1st-edition-robert-w-kaps/
ebookname.com
https://ebookname.com/product/html-professional-projects-4th-edition-
john-w-gosney/
ebookname.com
https://ebookname.com/product/signals-and-systems-second-edition-i-j-
nagrath/
ebookname.com
https://ebookname.com/product/american-government-brief-edition-ninth-
edition-james-q-wilson/
ebookname.com
https://ebookname.com/product/mathematical-modeling-of-physical-
systems-an-introduction-engineering-technology-1st-edition-basmadjian/
ebookname.com
Radiography of Cultural Material 2nd Edition Andrew
Middleton
https://ebookname.com/product/radiography-of-cultural-material-2nd-
edition-andrew-middleton/
ebookname.com
iOS SDK
Programming:
A Beginner’s Guide
About the Authors
James A. Brannan is a senior developer with more than
15 years of experience. He has developed using everything
from AWK, to Visual Basic, to Java. His current interests
are iOS, Blackberry, Android, and Adobe Flex/Flash. He is
only $999,000 short of being the next app store overnight
millionaire. He lives in Gaithersburg, Maryland, with his wife,
two kids, two Macs, and bicycle.
Blake Ward has a PhD in Computer Science from Carnegie
Mellon University and has spent more than 30 years
programming and managing software development. He has
developed for a wide variety of mobile devices, ranging from the
Apple Newton and Palm Pilot to RIM’s Blackberry, the iPhone
and iPad, and Android phones. Blake has worked as a researcher
and in management at Apple, Xerox PARC, and numerous
startups. He is currently an independent iPhone and Android
developer, available through www.iphoneappquotes.com.
James A. Brannan
Blake Ward
ISBN: 978-0-07-175909-0
MHID: 0-07-175909-3
The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-175908-3,
MHID: 0-07-175908-5.
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we
use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such
designations appear in this book, they have been printed with initial caps.
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training
programs. To contact a representative please e-mail us at bulksales@mcgraw-hill.com.
Information has been obtained by McGraw-Hill from sources believed to be reliable. However, because of the possibility of human or mechanical
error by our sources, McGraw-Hill, or others, McGraw-Hill does not guarantee the accuracy, adequacy, or completeness of any information and
is not responsible for any errors or omissions or the results obtained from the use of such information.
TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGrawHill”) and its licensors reserve all rights in and to the work. Use of
this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work,
you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate,
sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent. You may use the work for your own noncommercial
and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these
terms.
THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE
ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY
INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM
ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY
OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the functions contained in the
work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill nor its licensors shall be liable to
you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill
has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill and/or its licensors
be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work,
even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever
whether such claim or cause arises in contract, tort or otherwise.
For Timothy Hill and Doctor Ronald Holt. This book is not some lofty political or
anthropological treatise, but it was fun writing.
—James
vii
viii iOS SDK Programming: A Beginner’s Guide
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
Contents
ACKNOWLEDGMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
ix
x iOS SDK Programming: A Beginner’s Guide
C Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Understanding Headers, Import, and Include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Try This: Creating a Header File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Preprocessor Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Try This: Using Preprocessor Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Data Types and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Control, Functions, and Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Arrays and Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
The printf Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Pointers ............................................................................ 36
Try This: Using Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Dereferencing a Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Pointers and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Try This: Using an Array with Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3 Just Enough Objective-C: Part One ...................................... 41
Objective-C Classes and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Class Interface and Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Try This: Generating an Objective-C Class’ Interface and Implementation . . . . . . . . . . . 43
The @interface and @implementation Compiler Directives . . . . . . . . . . . . . . . . . . . . . . . . . 44
Method Declaration and Definition ................................................. 44
Try This: Adding SayHello to the Simple Class ..................................... 45
Interface Anatomy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Implementation Anatomy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Public, Private, and Protected Instance Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Understanding Simple Messaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Using self in a Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Nested Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Class and Instance Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Try This: Adding sayGoodBye as a Class Method .................................. 51
The alloc and init Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Managing Memory Using Retain and Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Try This: Using Manual Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Instance Variables and Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Managing Memory Using Autorelease . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4 Just Enough Objective-C: Part Two ...................................... 61
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Retain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Assign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Releasing Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Contents xi
Multiple-Argument Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Try This: Creating a Simple Multiple-Argument Message . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Understanding the id Variable Type, Dynamic Typing, and Dynamic Binding . . . . . . . . 69
The id Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Dynamic Binding and Dynamic Typing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Understanding Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Overriding Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Overloading Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Using Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Using Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Handling Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
5 Deploying to an iPhone, Debugging, and Testing . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Installing Applications on an iPhone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Membership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Certificates, Devices, Application IDs, and Provisioning ...................... 80
Try This: Deploying an Application to iPhone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Using the Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Try This: Debugging an Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
NSZombieEnabled ........................................................... 97
Try This: Enabling Zombies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Instruments—Leaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Try This: Find a Memory Leak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Distributing Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Ad Hoc Deployment and Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Distributing Your App via the App Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
6 UIApplication and UIApplicationDelegate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Try This: Adding a UIView and UIViewController to a UIApplicationDelegate . . . . . . 110
Connecting UIWindow, UIApplication, and UIApplicationDelegate . . . . . . . . . . . . . . . . . 117
Try This: Exploring Main Window.xib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
UIApplication and UIApplicationDelegate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
The main.m File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Handling Application Life Cycle Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Application Interruptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Try This: Handling Application Interruptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
7 UIView and UIViewController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
The UIView Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
The UIViewController Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
View-Based Application Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
xii iOS SDK Programming: A Beginner’s Guide
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
Acknowledgments
T hanks to the technical editor, Steven Weber, and everybody at McGraw-Hill, particularly
Roger Stewart, Joya Anthony, Jody McKenzie, Vastavikta Sharma, and Bob Campbell.
Special thanks to Everaldo and his Crystal Project Icons licensed under the LGPL. These
icons have made the examples much more visually appealing in both this book and others.
And of course, thanks to Neil Salkind, our book agent, who introduced us to computer book
writing and kept the ship navigating straight despite some stormy moments. Finally, thanks to
the iPhone SDK Forum (www.iphonesdk.com). In no small part, the idea for a tutorial-based
approach for this book came directly from your video tutorials offered on your site.
xvii
This page intentionally left blank
Introduction
R esponse to the iPhone, the iPod touch, and now the iPad has been nothing short of
overwhelming. The App Store has captured the hobbyist’s imagination like no other
platform in recent memory. Hobbyists have made—and will continue to make—money from
their creations sold on the App Store. And we aren’t necessarily talking about high-minded
technical innovations. The media has reported that apps that make your iPhone pass gas have
made folks hundreds of thousands of dollars. Rival farting App developers have even gone so
far as to sue one another over the App Store’s precious revenue. The iOS family of devices
and the App Store are here to stay—and there’s still plenty of opportunity for you to create
the next great app.
As proof of this popularity, after posting a few tutorial videos on Vimeo, James heard
from people from Asia, Europe, and South America about those videos. So, when we decided
to write this book, we kept in mind that iOS devices have significant international appeal.
We have tried to make this book as accommodating as possible for as wide an audience as
possible. We have kept colloquialisms to a minimum, for instance. But more important than
avoiding colloquialisms, this book relies upon discrete, numbered steps that illustrate each
major concept. Rather than a lot of prose describing the iOS SDK, we show you the SDK in
action.
xix
xx iOS SDK Programming: A Beginner’s Guide
this tool, building a graphical user interface (GUI) using Interface Builder is quicker and more
intuitive than using code.
The second goal of this book is to brush up your C language programming skills and
introduce you to Objective-C. Most likely you haven’t used C since college, and chances are
good you have never used Objective-C. However, because Objective-C is the language used
for Cocoa and Cocoa Touch programming, you must understand Objective-C if you wish
to create iPhone and iPad apps. After refreshing your memory on C, this book moves on to
Objective-C with a two-chapter tutorial that will give you a foundation for getting started with
the iOS SDK.
The third goal of this book is to cover all of the most useful functionality of the iOS SDK
so that you’re ready to create your own iOS apps for the App Store. We cover using the latest
version of Apple’s development environment, XCode 4, and most of the features introduced in
the latest versions of the SDK for the iPad and the iPhone 4.
NOTE
This book’s code examples can be downloaded at:
www.mhprofessional.com/computingdownloads.
Finally, Chapter 19 discusses the new SDK functionality available for the iPad and shows
you how to create a universal application that will run on the iPhone or iPod touch but also
take full advantage of the larger display on the iPad when available. All of the framework
functionality described in the earlier chapters applies to the iPad and the new iPhone 4, so
this chapter focuses on how to layer new iOS 4 functionality on top of the skills that you’ve
already learned.
This book doesn’t require any prior knowledge of C, Objective-C, or Cocoa Touch and
the iOS frameworks, so provided you have some prior programming experience and you
work through all of the exercises in the book, you should be ready to start working on your
own iPhone applications when you’ve finished the book. However, even if you eventually
decide to hire an independent developer to help build your application (via a web site like
www.iphoneappquotes.com), everything you’ve learned working through the exercises will
be invaluable when it comes time to turn your ideas into a design and work with others to
implement them.
This page intentionally left blank
Chapter 1
The iOS Software
Development Kit (SDK)
1
2 iOS SDK Programming: A Beginner’s Guide
S o why do people pay over $100 a month for an iPhone? Or more than $500 for an iPad?
Simple—they’re useful tools and fun toys. If you get lost, just start the Maps application,
and within seconds, it has located your position and provided you with a map. You can check
your e-mail anywhere, listen to music, and every once in a while even answer a phone call.
The built-in functionality of the iPhone, iPod Touch, and iPad is undeniably useful, but the real
magic of these devices is the App Store. There you can find more than a quarter of a million
applications that turn your iPhone from a useful general device to a tool specialized for exactly
what you want to do.
Apple’s App Store has created a new phenomenon—millions of people think of buying
cheap apps the same way they think about picking up a latte on the way to work; it’s an impulse
buy they do several times a week. Unlike other smartphone users, iPhone users buy apps, lots of
them! There may already be a staggering number of apps in the App Store, but the opportunities
are still endless for turning your ideas into profitable apps.
NOTE
Apple reviews every app before publication in the App Store, and you should read
their current guidelines for acceptance before starting on your app. Obvious categories
like gambling and pornography aren’t allowed, but even apps that show scantily clad
models risk rejection from the App Store. But don’t worry too much; if your app is bug
free and follows the guidelines, it will probably be approved within a week.
John Dryden, famous alike for his verse, prose and drama, shows
his wit in biting, stinging satire.
Equally caustic are his epigrams, save one—the immortal lines on
Milton.
ON SHADWELL
All human things are subject to decay,
And, when Fate summons, monarchs must obey.
This Flecknoe found, who, like Augustus, young
Was called to empire, and had governed long.
In prose and verse was owned, without dispute,
Through all the realms of Nonsense absolute.
This aged prince, now flourishing in peace,
And blest with issue of a large increase,
Worn out with business, did at length debate
To settle the succession of the state;
And pondering which of all his sons was fit
To reign, and wage immortal war with Wit,
Cried: “’Tis resolved; for Nature pleads that he
Should only rule who most resembles me.
Shadwell alone my perfect image bears,
Mature in dulness from his tender years;
Shadwell alone of all my sons is he
Who stands confirmed in full stupidity.
The rest to some faint meaning make pretence,
But Shadwell never deviates into sense.
Some beams of wit on other souls may fall,
Strike through, and make a lucid interval,
But Shadwell’s genuine night admits no ray;
His rising fogs prevail upon the day.
Besides, his goodly fabric fills the eye,
And seems designed for thoughtless majesty—
Thoughtless as monarch oaks that shade the plain,
And, spread in solemn state, supinely reign.”
The original of these fine lines was probably a Latin distich written
by Selvaggi at Rome, which has been thus translated:
Greece boasts her Homer, Rome her Virgil’s name,
But England’s Milton vies with both in fame.
PHILLIS’ AGE
How old may Phillis be, you ask,
Whose beauty thus all hearts engages?
To answer is no easy task:
For she has really two ages.
FRENCH HUMOR
The first French humorist of note in the seventeenth century was
Cyrano de Bergerac. His History of the Moon and History of the Sun
are of the nature of Gulliver’s Travels.
We laid ourselves along upon very soft quilts, covered with large
carpets; and a young man that waited on us, taking the oldest of our
philosophers led him into a little parlor apart, where my Spirit called
to him to come back to us as soon as he had supped.
This humor of eating separately gave me the curiosity of asking
the cause of it. “He’ll not relish,” said he, “the steam of meat, nor yet
of herbs, unless they die of themselves, because he thinks they are
sensible of pain.” “I wonder not so much,” replied I, “that he abstains
from flesh, and all things that have had a sensitive life. For in our
world the Pythagoreans, and even some holy Anchorites, have
followed that rule; but not to dare, for instance, cut a cabbage, for
fear of hurting it—that seems to me altogether ridiculous.” “And for
my part,” answered my Spirit, “I find a great deal of reason in his
opinion.
“For, tell me is not that cabbage you speak of a being existent in
Nature as well as you? Is not she the common mother of you both?
Yet the opinion that Nature is kinder to mankind than to cabbage-
kind, tickles and makes us laugh. But, seeing she is incapable of
passion, she can neither love nor hate anything; and were she
susceptible of love, she would rather bestow her affection upon this
cabbage, which you grant cannot offend her, than upon that man
who would destroy her if it lay in his power.
“And, moreover, man cannot be born innocent, being a part of the
first offender. But we know very well that the first cabbage did not
offend its Creator. If it be said that we are made after the image of
the Supreme Being, and the cabbage is not—grant that to be true;
yet by polluting our soul, wherein we resembled Him, we have
effaced that likeness, seeing nothing is more contrary to God than
sin. If, then, our soul be no longer His image, we resemble Him no
more in our feet, hands, mouth, forehead, and ears, than a cabbage
in its leaves, flowers, stalk, pith, and head—do not you really think
that if this poor plant could speak when one cuts it, it would not say,
‘Dear brother man, what have I done to thee that deserves death? I
never grow but in gardens, and am never to be found in desert
places, where I might live in security; I disdain all other company but
thine, and scarcely am I sowed in thy garden when, to show thee my
good-will, I blossom, stretch out my arms to thee, offer thee my
children in grain; and, as a requital for my civility, thou causest my
head to be chopped off.’ Thus would a cabbage discourse if it could
speak.
“To massacre a man is not so great sin as to cut and kill a
cabbage, because one day the man will rise again, but the cabbage
has no other life to hope for. By putting to death a cabbage, you
annihilate it; but in killing a man, you make him only change his
habitation. Nay, I’ll go farther with you still: since God doth equally
cherish all His works, and hath equally, divided the benefits betwixt
us and plants, it is but just we should have an equal esteem for them
as for ourselves. It is true we were born first, but in the family of God
there is no birthright. If, then, the cabbage share not with us in the
inheritance of immortality, without doubt that want was made up by
some other advantage, that may make amends for the shortness of
its being—maybe by an universal intellect, or a perfect knowledge of
all things in their causes. And it is for that reason that the wise Mover
of all things hath not shaped for it organs like ours, which are proper
only for simple reasoning, not only weak, but often fallacious too; but
others, more ingeniously framed, stronger, and more numerous,
which serve to conduct its speculative exercises. You’ll ask me,
perhaps, whenever any cabbage imparted those lofty conceptions to
us? But tell me, again, who ever discovered to us certain beings,
which we allow to be above us, to whom we bear no analogy nor
proportion, and whose existence it is as hard for us to comprehend
as the understanding and ways whereby a cabbage expresses itself
to its like, though not to us, because our senses are too dull to
penetrate so far?
“Moses, the greatest of philosophers, who drew the knowledge of
nature from the fountain-head, Nature herself, hinted this truth to us
when he spoke of the Tree of Knowledge; and without doubt he
intended to intimate to us under that figure that plants, in exclusion of
mankind, possess perfect philosophy. Remember, then, oh, thou
proudest of animals, that though a cabbage which thou cuttest
sayeth not a word, yet it pays in thinking. But the poor vegetable has
no fit organs to howl as you do, nor yet to frisk about and weep. Yet
it hath those that are proper to complain of the wrong you do it, and
to draw a judgment from Heaven upon you for the injustice. But if
you still demand of me how I come to know that cabbages and
coleworts conceive such pretty thoughts, then will I ask you, how
come you to know that they do not; and how that some among them,
when they shut up at night, may not compliment one another as you
do, saying, ‘Good-night, Master Cole-Curled-Pate! Your most humble
servant, good Master Cabbage-Round-Head!’”