Visit https://ebookultra.com to download the full version and
explore more ebooks
Cocoa and Objective C Up and Running Foundations
of Mac iPhone and iPod touch programming 1st
Edition Scott Stevenson
_____ Click the link below to download _____
https://ebookultra.com/download/cocoa-and-objective-c-
up-and-running-foundations-of-mac-iphone-and-ipod-
touch-programming-1st-edition-scott-stevenson/
Explore and download more ebooks at ebookultra.com
Here are some suggested products you might be interested in.
Click the link to download
Programming iOS 6 3rd Edition Fundamentals of iPhone iPad
and iPod touch Development Matt Neuburg
https://ebookultra.com/download/programming-ios-6-3rd-edition-
fundamentals-of-iphone-ipad-and-ipod-touch-development-matt-neuburg/
Programming the Iphone User Experience Developing and
Designing Cocoa Touch Applications 1st Edition Toby
Boudreaux
https://ebookultra.com/download/programming-the-iphone-user-
experience-developing-and-designing-cocoa-touch-applications-1st-
edition-toby-boudreaux/
iOS 4 Programming Cookbook Solutions Examples for iPhone
iPad and iPod touch Apps 1st Edition Vandad Nahavandipoor
https://ebookultra.com/download/ios-4-programming-cookbook-solutions-
examples-for-iphone-ipad-and-ipod-touch-apps-1st-edition-vandad-
nahavandipoor/
Take Control of Mail on the iPad iPhone and iPod touch
Third Edition Joe Kissell
https://ebookultra.com/download/take-control-of-mail-on-the-ipad-
iphone-and-ipod-touch-third-edition-joe-kissell/
Pro iOS Table Views for iPhone iPad and iPod Touch 1st
Edition Tim Duckett (Auth.)
https://ebookultra.com/download/pro-ios-table-views-for-iphone-ipad-
and-ipod-touch-1st-edition-tim-duckett-auth/
The Business of iOS App Development 3rd Edition For iPhone
iPad and iPod touch Taylor Pierce
https://ebookultra.com/download/the-business-of-ios-app-
development-3rd-edition-for-iphone-ipad-and-ipod-touch-taylor-pierce/
Building iphone apps with html css and javascript Making
App Store Apps Without Objective C or Cocoa 1st Edition
Stark
https://ebookultra.com/download/building-iphone-apps-with-html-css-
and-javascript-making-app-store-apps-without-objective-c-or-cocoa-1st-
edition-stark/
Cocoa programming for Mac OS X 2nd Edition Aaron Hillegass
https://ebookultra.com/download/cocoa-programming-for-mac-os-x-2nd-
edition-aaron-hillegass/
Pro Core Data for iOS Data Access and Persistence Engine
for iPhone iPad and iPod touch 2nd Edition Michael Privat
https://ebookultra.com/download/pro-core-data-for-ios-data-access-and-
persistence-engine-for-iphone-ipad-and-ipod-touch-2nd-edition-michael-
privat/
Cocoa and Objective C Up and Running Foundations of
Mac iPhone and iPod touch programming 1st Edition
Scott Stevenson Digital Instant Download
Author(s): Scott Stevenson
ISBN(s): 9780596804794, 0596804792
Edition: 1
File Details: PDF, 10.07 MB
Year: 2010
Language: english
Cocoa and Objective-C: Up and Running
Cocoa and Objective-C:
Up and Running
Scott Stevenson
Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo
Cocoa and Objective-C: Up and Running
by Scott Stevenson
Copyright © 2010 Scott Stevenson. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.
Editor: Brian Jepson
Production Editor: Adam Zaremba
Copyeditor: Nancy Kotary
Proofreader: Sada Preisch
Indexer: Ellen Troutman Zaig
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrator: Robert Romano
Printing History:
April 2010: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Cocoa and Objective-C: Up and Running, the image of a Pampas cat, and related
trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
TM
This book uses RepKover™, a durable and flexible lay-flat binding.
ISBN: 978-0-596-80479-4
[M]
1271342831
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1. Setup and First Run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Download and Install Xcode 1
Your First Application 4
Create the Interface 7
Run the Finished Application 11
2. Thinking in Code: Basic C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
How Code Works 15
How to Format Code 17
Variables 20
Types 21
Constants 23
Enumerated Types 24
Typedefs 24
Functions 24
Declaring Functions 28
Example: FirstProgram 28
Displaying Values on the Command Line 29
Compile and Run the Example 32
Scope 34
Static Variables 35
Conditionals 36
Example: ShoppingTrip 39
Compile and Run 41
Wrap Up 42
3. Memory and Pointers: Advanced C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Arrays 43
Loops 45
v
Text Strings 47
Multidimensional Arrays 48
Pointers 49
The Purpose of Pointers 50
Using Pointers 50
Pointers and the const Keyword 52
Dynamic Memory 53
Strings and Dynamic Memory 56
Returning Strings from Functions 57
Arrays of Strings 58
Example: AddressBook 59
Compile and Run the AddressBook Example 61
Structs 62
Header Files 64
Compile and Run the HeaderFileTest Example 66
Create Files for the Song Struct 66
Final Example 68
4. Thinking in Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Structs and Classes 74
Designing Classes 76
Accessors 77
Inheritance 78
Composition 80
Object Lifetime 81
Built-in Classes 81
5. Basic Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
NSString Basics 84
Using Methods 84
Nested Method Calls 86
Multi-Input Methods 86
Accessors 86
Dot Syntax 87
Creating Objects 88
Basic Memory Management 88
Using Autorelease Directly 90
Declaring a Class 90
Add Methods 91
Implementing a Class 92
init 94
dealloc 95
Example: PhotoInfo 96
vi | Table of Contents
6. More Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
More on Memory Management 103
The Life of an Instance Variable 105
Copying Objects 106
Class Name Prefixes 107
Properties 107
Property Options 109
64-Bit Objective-C 111
Enabling 64-Bit 112
Should I Use 64-Bit? 113
All Further Examples Assume 64-Bit 114
Categories 114
Categories for Private Methods 116
Introspection 118
Protocols 120
Dynamic Messaging 124
Using Selectors to Call Methods 125
Forwarding Messages 126
Exceptions 127
Example: DataCollector 129
Some New Classes and Methods 129
Create the Files 130
Build and Run 136
7. Foundation Value Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
NSString 138
Ranges and Substrings 140
Using NSString with C Types 141
Comparing Strings for Equality 141
Strings As File Paths 142
Reading and Writing Files with Strings 144
Mutability 148
Advantages of Mutability 149
Advantages of Immutability 150
Core Foundation 150
Memory Management 152
Core Foundation Mutability 153
Toll-Free Bridging 154
Core Foundation Types As Properties 155
Drawbacks of Core Foundation Types 156
Open Source 156
NSNumber 156
CFNumberRef 159
Table of Contents | vii
Cocoa Primitive Types 160
NSDecimalNumber 161
NSNumberFormatter 163
When to Use Which Number Type 165
NSData 166
NSMutableData 168
NSArray 169
Fast Enumeration 171
Blocks 171
NSMutableArray 173
CFArrayRef 174
NSIndexSet 175
NSDictionary 177
NSMutableDictionary 178
CFDictionaryRef 179
NSSet 181
NSMutableSet 182
NSValue 183
NSDate 184
CFDateRef 186
8. Basic Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
How to Use This Chapter 189
Windows and Views 190
Targets and Actions 193
Buttons 194
Declaring Action Methods 195
Connecting Actions 198
Menus 203
Responder Chain 206
Pop-up Buttons 211
Sliders 214
Text Fields 216
Outlets 218
Datasources 222
Table View Datasource Methods 226
Implementing Datasource Methods 227
Bindings 230
Key-Value Protocols 234
Bindings for Simple Controls 236
Bindings for Complex Controls 242
Tips for Debugging Bindings 244
viii | Table of Contents
9. Designing Applications Using MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
About This Project 248
Window Controllers 249
View Controllers 250
Core Data 253
Create the Project Files 254
Create the Entities 254
Add Attributes and Relationships 255
Update the App Delegate 261
Add the Quartz Framework 264
Create the Window Controller 264
Create the View Controllers 268
Create the Managed Object Classes 280
Create the User Interface 286
Remove the Default Window 287
Create the Main Window Interface 289
Create the Browser Interface 293
Create the Editor View Interface 297
Create the List View Interface 298
Run the Application 301
Preparing for Release 303
10. Custom Views and Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Basic Geometry 308
Geometry Structs As Strings 310
Geometry Structs As NSValues 311
Cocoa View Coordinates 312
Derived Rects 313
Comparison Functions 314
Basic Drawing 315
NSColor 316
Subclassing NSView 316
Instantiate the View 320
The Graphics Context 323
Bezier Paths 324
Drawing Polygons 324
Drawing Curved Paths 325
Images 329
Loading Image Data 329
Drawing Images in a View 331
Shadows 338
Add a Shadow to StyledImageView 338
Gradients 341
Table of Contents | ix
Drawing a Gradient Background 342
Drawing an Image Sheen 344
Refactoring View Code 349
Why You Should Refactor 350
Goals for Refactoring 350
Refactored Header 352
Refactored Implementation 354
Test the Refactored Version 359
Text 359
Fonts 359
Attributed Strings 360
Add a Title to StyledImageView 365
Handling Mouse and Keyboard Events 370
Keyboard Events 371
Mouse Events 372
Add Event Support to StyledImageView 372
11. The Final Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
The List 377
Websites 378
Last Thought 380
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
x | Table of Contents
Preface
I’m not sure if this is the first book you’ve picked up to learn Cocoa, but I think it’s the
one that will get you started writing apps. I started teaching Cocoa and Objective-C in
2004, and I have worked with a lot of people who wanted to learn how to write software
so that they could get their ideas onto the screen. But there’s a problem.
There are two kinds of people who want to learn programming. Those in the first group
are wired for the algorithmic mindset; they’re interested in data and the inner workings
of things for their own sake. When they see a dog catch a Frisbee, they think of the
calculations the dog does to catch it. Programming is a natural extension of this mind-
set. My guess is around five percent of the population is actually built this way.
The second (much larger) group has ideas for software that they desperately want to
make real. They’re often graphic or interaction designers. You probably have ideas
about a fantastic Mac, iPhone, or iPad app that you want to create, but you don’t have
a million dollars to hire an engineering staff. It’s very likely that you even like pro-
gramming and data in addition to several other interests, but you don’t see everything
in terms of algorithms.
The problem is that most technical books are written by and for people in the first
group. That means most of the material is being created for those who need the least
help. As a result, a lot of books on programming go unread. In fact, there’s this un-
spoken honor given to anyone who actually finishes reading one: “Wow, he must be
really motivated.”
My problem with this is that there are a lot of people with great ideas in the second
group. Many of my favorite Mac and iPhone apps today come from developers without
a formal computer science background, most likely because they bring different expe-
riences into the mix. I want to encourage more of this. Fortunately, the good folks at
O’Reilly agree with me.
So here’s the deal. I wanted to write this book because I want to help you learn how to
write Mac, iPhone, and iPad apps. I want you to read it so that I get to use whatever
software you end up creating.
xi
This book is made to be accessible to new programmers, but it’s not watered down.
You’re learning to use the same things the professionals use. My job is to make sure
that each page says something useful. For each paragraph, I’ve asked myself, “Does
this help you write your app?” Anything that didn’t meet that standard got cut. But I
haven’t sold you short; if there’s something you need to know to be a good Mac pro-
grammer, I’ve at least told you about it. However, I haven’t spent time on minutiae that
don’t matter for Cocoa.
The content of this book is based on Cocoa tutorials I wrote between 2003 and 2009.
Many of these were published at my personal site, Theocacao, and some of the longer
ones were published at Cocoa Dev Central, a site I didn’t originally create but have run
since 2004. I’ve refined the tutorials based on a one-on-one mentoring program that I
ran over the same period of time. You get the benefit of all those efforts in a single
condensed book.
Your job is to go write world-class Mac, iPhone, and iPad apps, and to tell everyone
else how great Cocoa is. Let’s get started.
Who This Book Is For
This book is for people who want to learn to make great Cocoa apps. I don’t assume
that you already know how to program, or anything about Objective-C or C. You do
need to own an Intel-based Mac running Mac OS X 10.6 Snow Leopard, and you must
know how to install software, launch apps, edit and save files, and so on. Essentially,
you have to know how to use a Mac.
If you know any computer languages at all (even HTML), things will make more sense
from the start. If not, you’ll still be able to make it through this book, but you may find
some parts challenging. Even though Cocoa makes many common tasks easy, your
brain has to adjust to the basic concepts of programming.
To be clear, though, this book is not exclusively for novice programmers. Depending
on your experience level, you can skip a few of the chapters that are designed for
beginners and jump right to the parts that are relevant to your experience.
If you already know C but haven’t done object-oriented programming, start with
Chapter 1, which will walk you through creating a basic Cocoa application. Then move
onto Chapter 4, which introduces object-oriented concepts.
If you know C and at least one object-oriented language (such as Java, Ruby, or C++),
you can start with Chapter 1 for the basic orientation, and then jump ahead to Chapter
5, which introduces Objective-C.
How This Book Is Organized
The chapters in this book are organized as follows:
xii | Preface
Chapter 1
To build Cocoa apps, you’ll need to know your way around Xcode. Although we’ll
get into Xcode more deeply later, this chapter gives you a quick tour.
Chapter 2
Before you can start programming in Objective-C (the native programming lan-
guage used with Cocoa), you’ll need a background in programming as well as in
the C language. This chapter gets you started with the basics of programming in C.
Chapter 3
A programming language spends all its time moving things around in memory.
This chapter explains how C manages memory and also explains pointers, which
let you work directly with memory locations. Although you won’t need all the low-
level memory manipulation that C is capable of, an understanding of it will help
you better understand Objective-C.
Chapter 4
Here’s where we take a detour from the C language and get into the object-oriented
world. In this chapter, you’ll learn about classes, inheritance, objects, and more.
Chapter 5
Now that you have a basic understanding of object-oriented concepts, it’s time to
move on to Objective-C. This chapter explains Objective-C’s syntax for calling
methods, defining classes, and creating objects.
Chapter 6
Before you can get into Cocoa, there are a few more things you need to learn about
Objective-C. This chapter introduces some intermediate Objective-C concepts,
including memory management, categories, selectors, and more.
Chapter 7
Although you can (and sometimes will) use standard C types in your Cocoa apps,
Objective-C offers a rich set of classes for working with primitive values, such as
integers, floating-point numbers, and strings. This chapter shows you how to use
these value classes.
Chapter 8
Cocoa’s AppKit user interface layer allows you to create applications with rich user
interfaces.Thischapterpreparesyoutoworkwiththebuilt-incontrolsandconnect
them with actions you define in your code.
Chapter 9
Model-View-Controller is the mindset that guides the way you’ll put your Cocoa
apps together. In this chapter, you’ll learn how to write code that coordinates your
data and user interfaces.
Chapter 10
Cocoa includes a rich set of classes for displaying graphics in your apps. In this
chapter, you’ll learn how to work with shapes, images, gradients, and more.
Preface | xiii
Chapter 11
Now that you’ve read through the book, you’re ready to write some apps. This
short chapter gives you a few last pointers to help you on your way.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements
such as variable or function names, databases, data types, environment variables,
statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values deter-
mined by context.
This icon signifies a tip, suggestion, or general note.
This icon indicates a warning or caution.
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in
this book in your programs and documentation. You do not need to contact us for
permission unless you’re reproducing a significant portion of the code. For example,
writing a program that uses several chunks of code from this book does not require
permission. Selling or distributing a CD-ROM of examples from O’Reilly books does
require permission. Answering a question by citing this book and quoting example
code does not require permission. Incorporating a significant amount of example code
from this book into your product’s documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title,
author, publisher, and ISBN. For example: “Cocoa and Objective-C: Up and Running
by Scott Stevenson. Copyright 2010 Scott Stevenson, 978-0-596-80479-4.”
xiv | Preface
If you feel your use of code examples falls outside fair use or the permission given above,
feel free to contact us at permissions@oreilly.com.
Safari® Books Online
Safari Books Online is an on-demand digital library that lets you easily
search over 7,500 technology and creative reference books and videos to
find the answers you need quickly.
Withasubscription,youcanreadanypageandwatchanyvideofromourlibraryonline.
Read books on your cell phone and mobile devices. Access new titles before they are
available for print, and get exclusive access to manuscripts in development and post
feedback for the authors. Copy and paste code samples, organize your favorites,
download chapters, bookmark key sections, create notes, print out pages, and benefit
from tons of other time-saving features.
O’Reilly Media has uploaded this book to the Safari Books Online service. To have full
digital access to this book and others on similar topics from O’Reilly and other pub-
lishers, sign up for free at http://my.safaribooksonline.com.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at:
http://www.oreilly.com/catalog/9780596804794/
A full site dedicated to the book is available from the author, and may include additional
examples and announcements about Cocoa user groups and other information you
may find useful as a developer. This book site is at:
http://cocoabook.com
To comment or ask technical questions about this book, send email to:
bookquestions@oreilly.com
You can email the author directly at:
cocoahelp@me.com
Preface | xv
For more information about our books, conferences, Resource Centers, and the
O’Reilly Network, see our website at:
http://www.oreilly.com
Acknowledgments
My education didn’t follow the normal path. I taught myself how to program and
learned how to run a business mostly by trial and error. In the end, I think this is the
only option that would have worked for me, but it was possible only because of my
extremely patient and understanding family: my mom, Peggy; my dad, Alan; and my
sister, Jamie. You would not be reading this now if it was not for their support.
There are so many people that have helped me in my work life, but there are a few that
have had a direct impact on this book.
Michael Lopp and Angela Muller were ongoing sources of encouragement and inspi-
ration. This book first came into being over lunch when Michael mentioned something
along the lines of “everyone wants an animal on the cover of their book,” referring to
the iconic O’Reilly covers. By incredible coincidence, Brian from O’Reilly emailed me
about two weeks later. Had Michael not made that comment, this might not have
happened.
I had world-class tech reviewers for this project: Joar Wingfors, Michael Jurewitz, Rob
Rhyne, and Tim Triemstra. Joar, who I originally met through the tutorials I posted
online, tirelessly reviewed an ever-changing book, provided a wealth of essential com-
ments and suggestions, and even helped me fix some bugs in the code. He’s one of the
most talented engineers I know, and I am thrilled to have been able to get his help on
this.
Though he wasn’t involved in this project, I owe a lot to John Mora. He has an ability
to look an impossibly large task in the face and just do it, despite the usual doubts about
whether you know enough or have enough time. It is one of the most impressive traits
I know of, and John has it in spades. Thankfully, I think some of that rubbed off on
me over the 15 years I’ve known him.
Thanks to Kip Krueger for patiently helping me figure out the low-level details of mem-
ory and offering pointers when I was learning C. His mentoring is the reason I’m able
to teach these topics to you now.
When I first started learning Cocoa, there were only two books out on the topic. I chose
Aaron Hillegass’s book Cocoa Programming for Mac OS X (Addison-Wesley). Not only
was it the first Mac programming book I read, it was the first technical book I actually
enjoyed. His book proved to me that you could write in a direct and personal style and
still be taken seriously. Having spent time with him in person, I can also add that he’s
a great guy. There’s no doubt that his influence is weaved into the tutorials I’ve written.
xvi | Preface
Brian Jepson is simply a superhero among editors. I’m not sure there’s enough space
to list all of the things he did to make sure this project was a success, but I certainly
could not have done it without him. For any part of the book that you really like, there’s
a good chance he had a hand in it. Follow him on Twitter: @bjepson.
Finally, to the thousands of people who have emailed me over the years with questions
or suggestions about tutorials, I owe a lot to you as well. You helped me refine every-
thing that ended up in this book, and by extension, helped a new generation of Cocoa
developers learn how to program.
This book is dedicated to Gina and Ilya, who both taught me that life’s too short to not
be spent with the people you want to be with.
Thank you.
Preface | xvii
CHAPTER 1
Setup and First Run
I know you want to start writing apps as soon as possible, but there are three things
you need to know first:
I don’t assume you already know how to program.
You don’t need to have existing experience with Objective-C, Cocoa, Xcode, or
even C. If you have some familiarity with a computer language (even HTML), it
will help you. You do need to be a reasonably proficient Mac user. If you show up
with the desire to learn Mac programming, I’ll walk you through what you need
to know.
The chapters are modular.
If you know C and object-oriented concepts, but not Objective-C specifically, you
can skip to Chapter 5 after learning about Xcode in this chapter. If you’ve already
dabbled in Mac or iPhone programming, and know your way around Objective-C
and some basic Cocoa topics, you can probably jump to Chapter 7. Otherwise,
start right here.
You need a Mac running Snow Leopard.
All of the chapters assume that you’re running Mac OS X 10.6 Snow Leopard,
which runs only on Intel-based Macs.
All set? Good, let’s get Xcode running.
Download and Install Xcode
You can either get Xcode from the Mac OS X install DVD or download it from the
official Mac Dev Center website. The version on the website will always be the newest
one, but the download may take several hours. If you want to get started right away,
you can install from the DVD.
1
If you’re running Snow Leopard and already have the iPhone SDK in-
stalled, you have everything you need to write Mac apps. You can skip
ahead to “Your First Application” on page 4.
To download the newest version of Xcode, go to http://developer.apple.com and click
on Mac Dev Center. The layout of the site changes regularly, but you should look for
a link that says “Register” to create an account. There is a paid membership that offers
access to prerelease software and training videos, but you can start with the free mem-
bership,whichrequiresyouonlytofilloutsomebasiccontactinformation.Afteryou’ve
registered, return to http://developer.apple.com and log in. Once you’re logged in, look
for a link for downloading Xcode.
If you have a slow Internet connection and want to save yourself a few hours, put the
Snow Leopard Install DVD in the drive and open the folder called Optional Installs as
shown in Figure 1-1.
Figure 1-1. The Optional Installs folder on the Snow Leopard Install DVD
Inside the Optional Installs folder is a package called Xcode.mpkg. Double-click it to
open the installer (see Figure 1-2).
2 | Chapter 1: Setup and First Run
The version of Xcode on the DVD is usually older than what is available
on the developer site, so you should upgrade Xcode as soon as you have
the time to download it. The Xcode download at the Mac Dev Center
willshowyoutheversionnumberthat’savailable.WhenyourunXcode,
the version number is displayed on the Welcome window below “Wel-
come to Xcode.”
Once the installer is running, you can just accept all of the default options. You will
likely need several gigabytes free for installation. Figure 1-3 shows the installer running.
Figure 1-3. An Xcode install in progress
Figure 1-2. The Xcode.mpkg package inside the Optional Installs folder
Download and Install Xcode | 3
Once the window says installation is complete (see Figure 1-4), go ahead and close the
window.
Figure 1-4. The installer window confirming that Xcode was installed
Your First Application
Launch Xcode. You can find it by clicking on your hard drive icon in the Finder sidebar
and navigating to Developer → Applications. This is separate from the general
Applications folder that holds things like Safari and iTunes. You can also search for it
using Spotlight.
It’s probably a good idea to add Xcode to your Dock since it’s a few
levels down. In theory, this is for easy access, but it’s also a good con-
versation starter if someone sees it on your Mac.
If Xcode asks you for any initial configuration preferences, simply accept the defaults.
Each time Xcode runs you will see a Welcome window that looks something like
Figure 1-5.
4 | Chapter 1: Setup and First Run
The left side of the window has a few items to help you get started, and the right side
lists projects that you’ve used recently. The list will be empty the first time you run
Xcode. Click on “Create a new Xcode project” to get started.
If you closed the Welcome window, you can start a new project by
choosing File → New Project from the menu. You can open the Welcome
window again by choosing Help → Welcome to Xcode.
In the New Project window, click on Application under the Mac OS X section and select
the Cocoa Application icon as shown in Figure 1-6.
Click the Choose button, and you’ll be asked to select a location for the project. Go to
your home folder and create a folder called CocoaBook (you can do this within the Save
dialog). Select the CocoaBook folder as the save location and enter “TextEditNano” as
the project name (see Figure 1-7).
The layout of the New Project window has changed significantly in the
3.x releases of Xcode. If your window doesn’t look similar to the screen-
shot in Figure 1-6, download a newer version of Xcode from http://de
veloper.apple.com.
Figure 1-5. The Xcode Welcome window after the first launch
Your First Application | 5
After you click Save, you’ll see the main Xcode window come up, which looks like
Figure 1-8.
Go ahead and click the Build and Run icon in the toolbar to try the app out. You should
see a blank window come up, as shown in Figure 1-9.
This obviously isn’t a useful window, but if it shows up, you know Xcode is working
and you’re ready to start writing Mac apps. Close the application and return to the
main Xcode window.
To close an app that’s running inside of Xcode, you can either choose Quit from the
application’s menu, or just click the Tasks stop sign toolbar icon in Xcode, which is
shown in Figure 1-10.
It’s called Tasks because you may have several things going on in Xcode, and if you
click and hold on this icon, you can select which task you want to stop.
If your application crashes or stops responding, you won’t be able to
use Quit from the application menu. If that happens, just use the Tasks
toolbar item. This is equivalent to a Force Quit, so the application won’t
have a chance to save any data or preferences before closing.
Figure 1-6. The New Project window in Xcode
6 | Chapter 1: Setup and First Run
Create the Interface
At the heart of every great Mac app is a great user interface. You might design the
interface in an image editing program, on a napkin, or just in your head, but eventually
you’ll want to make it real. In Cocoa, there are two ways to create a user interface.
You can manually enter configuration details for controls in your application code
(you’ll learn more about writing code in the next chapter), or you can visually arrange
controls in Interface Builder. In my experience, novice programmers usually jump at
the chance to work visually, but experienced developers sometimes take a bit more
convincing.
Some new programmers think that writing software the hard way makes you a better
programmer, but expert Mac developers measure success by how quickly they can
deliver great results. Interface Builder is not training wheels for Cocoa; it’s a tool to
reduce the amount of “busy work” you have to do when setting up your user interface
(UI), which means you can work more quickly and avoid trivial errors. That leaves you
free to focus on the real work.
Figure 1-7. Create a CocoaBook folder for your projects, and name the project “TextEditNano”
Your First Application | 7
Eliminating busy work is the most important idea in Cocoa. A pro-
grammer who doesn’t need to waste time on tedious tasks is free to focus
on creating features that make her app unique.
Xcode includes an Interface Builder document with each new project, but as you’ve
seen from the blank window, there’s not much to it. In the main Xcode window, click
the disclosure triangle to the left of the blue TextEditNano project icon in the sidebar
to display its contents. Now open the Resources group and double-click the
MainMenu.xib file to open it in Interface Builder. You’ll see a window that looks some-
thing like Figure 1-11.
Double-click the Window icon (circled) to open the main window for the TextEdit-
Nano application. It should look exactly like the blank window you saw when you first
ran the application. This window is your canvas. You can add any UI elements here
that you want to use in your application.
Interface Builder works differently than some other visual development tools. It doesn’t
generate Objective-C code. Instead, it takes snapshots of the state of the objects. The
configuration of all of the controls, including all of their positioning information, is
saved in the MainMenu.xib file and loaded by Cocoa when your app is launched.
Figure 1-8. The Xcode main window showing the TextEditNano project
8 | Chapter 1: Setup and First Run
The .xib file format is an XML version of the standard .nib format that
was Interface Builder’s native format in earlier versions of Mac OS X.
The XML version is easier to use in version control systems, but when
Xcode builds your app, it actually converts XIB files into NIB files. The
original XIB file is preserved, though.
Open Interface Builder’s Library window by choosing Tools → Library from the menu.
The Library window contains ready-to-use UI elements that are built into Cocoa. You
can also download third-party plug-ins or create your own. Type “text view” into the
search field at the bottom of the window to bring up the Text View item, as shown in
Figure 1-12.
Figure 1-9. The blank window you see the first time you run TextEditNano
Figure 1-10. The Tasks button in the Xcode toolbar
Your First Application | 9
If nothing shows up when you search for the text view, make sure that
the Objects tab is selected at the top of the window, and the Library
item is selected in the drop-down menu below it.
Drag the Text View item from the Library window into the application window. This
might be obvious, but you need to drag it to your “prototype” application window that
appeared when you double-clicked on Window in Interface Builder (Figure 1-13), not
the real one from the running application (which you hopefully already closed).
Move the text view so that it’s near the top-left edge of the window. Use the handles
around the outside to resize it so it nearly fills the window, but leave a little bit of space
at the bottom. The exact size isn’t important—just do whatever you think looks right.
Select File → Simulate Interface from the menu, or press Command-R. This will display
the window in Interface Builder’s simulator test mode. The application isn’t actually
running, but you can see a preview of what it will look like and can even type in the
text field. If you try to resize the window, though, you can see that the text view doesn’t
resize with it. Press Command-Q to close the simulator, and we’ll fix this.
Set sizing properties
Select the text view by clicking on it in the prototype window, and choose Tools → Size
Inspector from the menu, or press Command-3. The Inspector window’s title is “Scroll
View Size,” but that’s OK (you may have expected it to be named “Text View Size”).
The scroll view is wrapped around the text view to provide scrolling support for long
runs of text.
Figure 1-11. The MainMenu.xib file for TextEditNano
10 | Chapter 1: Setup and First Run
The Autosizing section of the Inspector controls resizing. The outer anchors control
which edges the view moves with, and the inner arrows control which edges the view
resizes with. That may not make sense when you read it, but fortunately the Inspector
window shows you a live preview as you make changes. You can turn each anchor on
or off by clicking it. Click both sets of internal arrows so the view resizes with the
window. It should look Figure 1-14 when you’re done.
Run the test mode again by pressing Command-R. If you resize the window, the text
view should now resize with it. Press Command-Q to close the simulator, then Com-
mand-S to save the MainMenu.xib file. Switch back to Xcode.
Run the Finished Application
Back in Xcode, click the Build and Run icon in the toolbar (or just press Command-R)
to build the application and run it. This time when the window comes up, you should
see the text view you added. Choose Format → Font → Show Fonts to choose a font,
then type something in the text field (see Figure 1-15).
Figure 1-12. Search for “text view” in the Library window
Your First Application | 11
Even though you haven’t written a single line of code yet, you already have a real Cocoa
application. It can’t save files, but it uses Cocoa’s built-in text view so you can use fonts,
colors (Shift-Command-C), international text, and spellchecking. It also supports drag-
and-drop, text search (try Command-F), and many other features.
Figure 1-13. Drag the text view icon into the prototype window
Figure 1-14. Click both sets of arrows to enable resizing
12 | Chapter 1: Setup and First Run
Figure 1-15. Cocoa has built-in support for advanced text effects
You can also create PDFs from the text and even print. Choose File → Print to bring up
the standard print dialog, and click Preview to convert the text into a PDF as shown in
Figure 1-16.
The document can use features like any other PDF, including text selection, searching,
and annotation. Remember, this is your application that you just made from scratch.
Your First Application | 13
Figure 1-16. Basic PDF generation and printing is built in
14 | Chapter 1: Setup and First Run
CHAPTER 2
Thinking in Code: Basic C
As a Cocoa programmer, your job is to get your ideas onto the screen. When you write
an essay, you use sentences and paragraphs. Writing software works the same way,
though you write lines of code instead. Each line performs a task, such as opening a file
or displaying an image. When you put enough of these lines of code together, you
eventually have an application.
You write these instructions using a programming language. Most Mac and iPhone
apps are written in Objective-C, so that’s what you’ll use in this book. The process of
converting your ideas into code is called, literally, writing code, and the result is source
code. For example, to make your application play the alert sound, you write this line
of code:
NSBeep();
There’s one important detail, though. Objective-C is based on a simpler language,
called C. In fact, Objective-C isn’t just based on C; it’s all of C plus some other stuff.
Programmers like to say it’s a strict superset of C.
So before you start writing Cocoa apps, it helps to learn some C. I’m not going to lead
you into the outer limits of the language; you’ll see just enough to get started. If you
already know C, you can safely skim this chapter.
If this seems confusing, just remember that Objective-C is the language
that defines how you format your code—the grammar. Cocoa defines
what you can make your code do—the overall vocabulary. You create
a Cocoa app by writing code in the Objective-C language.
How Code Works
Mac OS X contains special folders for programmers called frameworks. A framework
helps you do things like animate graphics, display web pages, and create PDFs. These
15
aren’t just for third-party developers; the built-in applications use them too. Applica-
tions can also include their own custom frameworks that aren’t provided by Mac OS X.
You might be used to thinking of Cocoa as a single tool for building Mac apps. In reality,
it’s the foundation for many different frameworks—an entire ecosystem. In fact,
there are more than 90 frameworks in Snow Leopard, and some of those contain
subframeworks.
Each one is designed to help you do something different. For example, the Core
Video framework helps you write an application that can apply real-time special effects
to video. A single Mac application may use many different frameworks, though almost
all inherit basic infrastructure from Cocoa.
The frameworks built into Mac OS X are in /System/Library/
Frameworks (Figure 2-1). Developers can also create their own frame-
works and install them in /Library/Frameworks. Feel free to look around
in there, even if you don’t know what the frameworks do yet.
Figure 2-1. The contents of /System/Library/Frameworks on Snow Leopard
16 | Chapter 2: Thinking in Code: Basic C
When you write a line of Objective-C code, you are usually asking a framework to do
something for you. For example, these lines of code download an image from a website
and save it as a TIFF file on my desktop:
id url = [NSURL URLWithString:@"http://cocoabook.com/test.png"];
id image = [[NSImage alloc] initWithContentsOfURL:url];
id tiff = [image TIFFRepresentation];
[tiff writeToFile:@"/Users/scott/test.tiff" atomically:YES];
If you’ve never written code before, this probably all looks pretty strange. It’s a lot like
when you see algebra or a foreign language for the first time. Even though it’s new,
there is a consistent structure that you can learn. Here’s what Cocoa does for you when
you write and run the example lines of code:
1. Finds the IP address for the host cocoabook.com
2. Establishes an HTTP connection to the server at that IP address
3. Creates an image to hold the data
4. Downloads the data, bit by bit, and places it in memory
5. Saves the image data to a TIFF image file on the local disk
Incredibly, you don’t need to know the HTTP protocol, how to resolve IP addresses,
or how to create a TCP connection. Frameworks are designed to abstract these kinds
of details from you so that you can focus on what makes your app unique. As Cocoa
and other frameworks are improved with each new version of Mac OS X and iPhone
OS, your app will often pick up new features without any additional work.
So making Mac apps is really about writing code that uses frameworks. You type spe-
cific instructions into a file in Xcode, then click Build and Run to try them out. When
you do this, Xcode compiles your code into an application, which can be double-clicked
on a Mac, tapped on an iPhone’s home screen, or even run from the command line in
Mac OS X’s Terminal application.
In a sense, the lines of code you write are the “raw materials” of your application. Xcode
then acts as an assembly line, compiling your code into the final product. Compilation
is a fairly complex process, but Xcode handles the basic cases with very little effort on
your part.
How to Format Code
Xcode and Cocoa do a lot of work for you, but you have to do your part by writing
accurate code. If we stay with the theme of you supplying raw materials and Xcode
assembling them, you have to be sure the materials are “built to spec.” In other words,
you need to write code that Xcode can understand.
How to Format Code | 17
Appropriately, when Xcode processes your code it generates something
called assembly code. This is harder for humans to read, but perfect for
computers. You can see this by opening a source code file and choosing
Build → Show Assembly from the menu.
Some programming languages have very complex formatting rules, but C and
Objective-C are pretty simple. That doesn’t mean they’re always easy to use, just that
they have fewer grammar rules than many other languages. We’ll start with something
basic. Let’s say you have some driving instructions:
1. Enter I-280 South.
2. Exit at the De Anza ramp.
3. Make a U-turn at Mariani Avenue.
4. Turn right into Infinite Loop.
Anybody who knows English can read these steps, but I can’t compile them. I’ll convert
them to code:
enterFreeway ( "I-280 South" );
exitFreewayAtRamp ( "De Anza" );
performUTurnAtStreet ( "Mariani Ave" );
turnRightAtStreet ( "1 Infinite Loop" );
This program won’t actually run, because it assumes four hypothetical
actions that aren’t supported by any framework you’re likely to find on
a Mac or iPhone.
Written languages are flexible. Even if you misspell a word or structure a sentence
strangely, the reader usually knows what you mean. For example, a person knows that
“Mariani Ave” and “Mariani Avenue” are the same, but programming languages are
usually more strict. When Xcode compiles your code, it can’t make conceptual leaps
about what your intentions are.
Word spacing is another key difference. In English, each word is separated by a space
or hyphen, but many programming languages combine several words into one big noun
or verb, such as mailboxSearchField. There’s a consistent pattern to the code: an action,
sometimes followed by additional details. Here’s the first line of that code again:
enterFreeway ( "I-280 South" );
The line starts with enterFreeway, which is the name of an action. These actions are
called functions. The second part of the line describes which freeway to enter: I-280
South. The technical term for this is an argument or parameter, but I think those are
pretty awkward terms. You can just think of it as an input value.
18 | Chapter 2: Thinking in Code: Basic C
Each instruction ends with a semicolon. In C, a semicolon is like a period at the end of
a sentence. Just like sentences, a single instruction can span multiple lines, but almost
all instructions end with a semicolon.
The compiler converts source code into working programs. When you
click Build in the toolbar, Xcode uses the compiler to do a lot of the low-
level work. Besides abstracting a lot of these tedious details, Xcode also
packages up the program as a proper Mac app.
If you write a line of Xcode that isn’t correct, Xcode will display an error when you try
to build. You won’t be able to run your app until you fix the error. These kinds of
mistakes are known as build errors (Figure 2-2).
Figure 2-2. A build error in Xcode
Even the best programmers make mistakes like this every day, but many are easy to fix.
You’ll learn more about this as you use Xcode to build applications.
One thing that C is flexible about is how you use whitespace. All of the lines in the
following example will produce exactly the same result:
enterFreeway ( "I-280 South" );
enterFreeway ( "I-280 South" );
enterFreeway("I-280 South");
How to Format Code | 19
Programmers use whitespace to make the intentions of their code more clear, though
there are a lot of different opinions on what “clear code” is. You can usually use what-
ever style works best for you. Teams of programmers usually try to agree on a style that
everyone in the group uses, though there is always room for flexibility in how you
format your code.
Instead of listing every single C formatting rule here, I’m going to move on to more
practical concepts and show you these rules by example. If you ever have trouble typing
in a sample correctly, you can download a working version from the book’s companion
website (see the Preface for information on obtaining the sample code).
Variables
A variable is a container for a piece of data, such as a block of text, an image, or a web
page. You give each variable a name so you can refer to it in code. Like formatting,
there are different conventions for naming variables. When writing Mac software, you
should try to use the same conventions that Cocoa itself uses.
Cocoa is designed to make very large projects manageable, and encour-
ages you to write code that’s easy to understand. Some applications are
made up of hundreds of thousands or millions of lines of code. Using
consistent, clear naming conventions makes it easier for many pro-
grammers to collaborate on a project.
Giving names to things with varying definitions makes them easier to refer to: you see
a movie, eat a meal, drive down a street. It’s just easier to say “breakfast” than “that
thing we did yesterday where we ate bacon and eggs.” You can share information be-
tween different parts of an application using variable names instead of the data they
contain. Let’s start with a simple line of code:
emailMessageToFriend ( "Hi there!", "test@example.com" );
This seems reasonable. I call the function emailMessageToFriend(), with one input item
for the message and another for the email address. But what if I want to send a different
message, or send the message to a different person? I’d need to change the code, re-
compile it, and rerun it. Clearly, this won’t work.
Variables make it possible to write one piece of code for many different situations by
using a name as a placeholder for the real data. Here’s what the previous line of code
looks like if I use variables instead:
message = "Hi there";
address = "test@example.com";
emailMessageToFriend ( message, address );
20 | Chapter 2: Thinking in Code: Basic C
I can use the variables message and address to refer to the email contents and recipient
without having to know what they will be ahead of time. I can also make the code more
useful by reusing the message variable as-is, but changing the address variable to send
the same email to other people:
message = "Welcome to Cupertino!";
address = "gina@example.com";
emailMessageToFriend ( message, address );
address = "fred@example.com";
emailMessageToFriend ( message, address );
address = "sarah@example.com";
emailMessageToFriend ( message, address );
If I ever want to change the welcome message, I have to update it in only one place
instead of three.
In a real program, I would make a window that allows the user to select
whom they want to send messages to, ideally using the Mac OS X Ad-
dress Book database to choose from a list of existing contacts.
Types
In C, variables have a type, which describes what kind of data the variable contains. C
has a handful of built-in types for common things like numbers and text, but you can
also create your own.
There are two steps to using a variable in C: declare it, then assign a value to it. You
can change the value of a variable as many times as you want, which is actually what
the term “variable” means. Here’s an example of declaring a variable and assigning it
a value in one step:
int milesPerGallon = 35;
This code creates a new int variable with the name milesPerGallon, and assigns it an
initial value of 35. On a Mac running Snow Leopard, this variable can store any whole
integer up to 2,147,483,647.* No, you don’t need to memorize this.
For floating-point numbers (numbers with decimal points), C has a float type. Here’s
an example:
float exchangeRate = 1.618;
The milesPerGallon and exchangeRate variables have different types, but they do the
same thing: store a value. You can also declare a variable and assign it a value in separate
steps:
* You can see the actual definition for the maximum value in /usr/include/i386/limits.h. Just look for INT_MAX.
Variables | 21
int milesPerGallon;
float exchangeRate;
milesPerGallon = 35;
exchangeRate = 1.618;
Here’s an example of declaring a variable once, assigning it a value, then reassigning it
a new value several times:
int milesPerGallon;
milesPerGallon = 35;
milesPerGallon = 27;
milesPerGallon = 81;
float exchangeRate;
exchangeRate = 1.120;
exchangeRate = 1.114;
exchangeRate = 1.618;
If you try to assign the wrong type of data to a variable, C will usually try to do some
conversion, but you may lose information in the process. For example, if you try to
assign the value 24.5 to milesPerGallon, it will be stored as 24 because int variables
only store whole numbers. Some conversions are not possible, and Xcode will warn you
about these when you compile your application (when Xcode wants to show you
warningsorerrormessages,itcallsyourattentiontotheminthestatusbaratthebottom
of the window).
Some successful conversions will give a different result than you expect. Most of the
time, assigning an int value to a float variable does what you expect. However, if you
divide one integer value by another integer value, you’ll always get a integer result, even
if you assign the result to a float:
int miles = 366;
int gallons = 8;
float milesPerGallon = miles / gallons;
The milesPerGallon variable will contain the value 45 instead of 45.75. You can use the
cast operation (specify the name of the desired type in parentheses) to force a specific
type conversion. This example converts both miles and gallons to float values before
it performs the division:
float milesPerGallon = (float) miles / (float) gallons;
Technically, you don’t need to cast both values, because the compiler is smart enough
to treat both as float values if you cast at least one of them:
float milesPerGallon = (float) miles / gallons;
Table 2-1 contains a list of some of the most common “primitive” types used in C.
22 | Chapter 2: Thinking in Code: Basic C
Table 2-1. Basic C data types
Type Description Examples
int Integer numbers, including negatives 0, 78, –1400
unsigned int Integer numbers (no negatives) 0, 46, 900
float Floating-point decimal numbers, including negatives 0.0, 1.618, –1.4
char Single text character or symbol a, D, ?
In addition to the types listed in the table, there’s also a type called double, which is a
version of float that can hold larger decimal point numbers, and long, which is a larger
version of int. Cocoa has special variable types that automatically adapt to different
sizes as necessary, which you’ll learn about in Chapter 7. I’ll also show you how to
make your own types in Chapter 3.
Constants
In computer programming, constants are variables that can’t be modified once you’ve
assigned a value to them. C has a keyword const that behaves like a constant most of
the time. For example, the compiler won’t let you change the value of an int that you’ve
declared as const:
int currentSpeed = 55;
currentSpeed = 65;
const int maximumSpeed = 75;
maximumSpeed = 80;
If you try to compile this, you’ll get the error: assignment of read-only variable.
Changing currentSpeed is fine, but trying to change the constant maximumSpeed won’t
work. Constants are a way to prevent your code from accidentally changing important
variables. Another way to define a constant in C and Objective-C is to use #define,
which is a preprocessor directive. By convention, these are usually in all capital letters:
#define MAX_MPG 120
if (milesPerGallon > MAX_MPG) {
errorMessage = "You appear to have a nuclear-powered car.";
}
The preprocessor is a tool that runs behind the scenes when you compile an application.
It does a number of different things, such as handling #include statements, but also
does a search and replace on placeholders you’ve specified with #define. So the
#define directive doesn’t create real variables; it just replaces one string of text with
another before the compiler gets its hands on the code. Here’s what the preceding
example looks like by the time it’s handed off to the compiler:
if (milesPerGallon > 120) {
errorMessage = "You appear to have a nuclear-powered car.";
}
Variables | 23
In general, #define is common in pure C programs, but it’s not considered such great
style in Cocoa apps. It’s not outright wrong, just considered a bit clumsy or inelegant.
Myexperienceisthatconst isgenerallybetter forObjective-C, especially becauseXcode
can do a better job with helping you write code if you use real variables.
Enumerated Types
If you have a group of related values (such as days of the week), you can use C’s enum
keyword to create a group of constant values that you can use in your programs. These
enumerations are integer types, and the values can be used wherever you would use an
integer:
enum { monday, tuesday, wednesday, thursday,
friday, saturday, sunday };
int day = saturday;
Typedefs
C lets you define your own types with the typedef statement. You can use this to create
aliases to some of the basic types in C, which lets you write code that’s somewhat
self-documenting:
typedef int Distance;
Distance home_to_office = 30;
Distance office_to_cafe = 3;
What’s more, you can combine typedef and enum to create your own type that can only
be assigned one of the values listed in the enum. Doing so eliminates the need to define
the day variable shown earlier as an int, and makes for a more self-documenting
program:
typedef enum {
monday, tuesday, wednesday, thursday,
friday, saturday, sunday
} DayOfWeek;
DayOfWeek day = saturday;
Functions
The previous example programs were just flat lists of instructions. That’s fine for very
simple cases, but you need some sort of structure to manage all of the code in a real
application. A function is a way to group multiple instructions together so they can be
used with a single line of code.
When someone asks you what you did today, you might say something like “I went to
the grocery.” You probably don’t say “I opened the door, walked outside, closed the
door, locked it, walked to the car, opened the car door...” because that level of detail
24 | Chapter 2: Thinking in Code: Basic C
isn’t relevant to the conversation. Once somebody understands what the phrase “I went
to the grocery store” means, they know that it contains a sensible series of steps. Let’s
see how that might look as a list of steps first:
Buy Groceries
Open front door
Walk out front door
Close front door
Lock front door
Walk to car
Open car door
Enter car
Close car door
I know this seems like a ridiculous level of detail, but this is how a computer program-
mer thinks. In general, software cannot make conceptual leaps. You need to spell out
exactly how the application should work. For example, if I wrote out the exact steps
to display a PNG image on screen, they would probably look like this:
Display Image
Save file path as a variable
Make sure the path to the file is valid
Make sure the file at the path is a PNG image
Reserve memory for an image
Read data from the file, one byte at a time
When all data is read in, close the file
Open a new window to display the image
Draw the contents of the image into the window
ThegoodnewsisthatframeworkslikeCocoahavealreadydonealotofthegroundwork
for you. Cocoa has defined what many of these “lists of tasks” are, and they’re ready
for you to use. That’s what allows you to place an image in a window without knowing
details like the refresh rate of the user’s display.
Now let’s go back and translate the “Buy Groceries” steps into something that looks
more like C code. I’ll create a function called buyGroceries() that itself calls a series of
other functions:
void buyGroceries() {
openFrontDoor();
walkOutFrontDoor();
closeFrontDoor();
lockFrontDoor();
walkToCar();
openCarDoor();
enterCar();
Functions | 25
closeCarDoor();
}
There are a few things that may look new here, but you can probably still get the gist
of what’s going on. My buyGroceries() function is calling other functions like
openFrontDoor() and walkOutFrontDoor(). This pattern of functions calling other func-
tions is the essence of structured programming. Let’s take a look at the first line again:
void buyGroceries() {
There are three things to notice here:
The word void is the return type for the function. The return type could also be int,
float, char, or any other C type. The value a function returns is called a result. When
a function doesn’t return anything, the return type is void. Yes, it’s a slightly strange
convention, but this is just one of the delightful quirks of C.
The function name is followed by a pair of parentheses: buyGroceries().
Programmers usually call the { symbol a “curly brace.” All of the instructions in a
function must be inside of a pair of curly braces. It’s easy to forget to add a curly
brace to the end of the function. So check this first if Xcode shows you an error when
compiling your app.
Let’s look at a few actual functions with return values:
int numberOfPeople () {
return 3;
}
float dollarsAndCents () {
return 10.33;
}
We’re using all of the same conventions here as in the previous example. In fact, the
only difference is now we’re using the return statement, which sends a result back to
the caller and ends the function.
There’s a subtle point here. The return statement returns a result to the
caller, but it will also immediately end the function. If you have any code
after the return statement, that code will not run.
When you call a function, you can capture the result in variable of the same type. Here
are some examples:
int count;
count = numberOfPeople();
float totalCost;
totalCost = dollarsAndCents();
26 | Chapter 2: Thinking in Code: Basic C
Another Random Scribd Document
with Unrelated Content
ST. BOTOLPH, BISHOPSGATE
This church escaped the Great Fire of 1666, but was rebuilt in 1725-29 by
James Gold. In 1615 the City gave the parishioners additional ground on the west
for burial purposes. The earliest date of an incumbent is 1323.
The patronage of the church has always been in the hands of the bishops of
London since 1323.
Houseling people in 1548 were 650.
The building includes two aisles, separated from the main body by composite
columns. There are galleries on the north, south, and west. The steeple rises at the
east end, and the chancel, therefore, is formed beneath the tower. It is built of
stone and consists of three stories, the third of which is completed by a small
composite temple surrounded by a balustrade and surmounted by an urn. The
remainder of the exterior is of red brick with stone dressings.
Pictorial Agency.
ST. BOTOLPH, BISHOPSGATE
Sir Paul Pindar, a great benefactor to the church, who acted as James I.’s
Turkish Ambassador in 1611, was buried in this church, and a monument was
erected to his memory. Close to this, also in the chancel, is a brass plate in memory
of Sir William Blizard, President of the Royal College of Surgeons, who died in
1835. John Keats was baptized here in 1795, and Edward Alleyn, founder of
Dulwich College, in 1566. Here also Archibald Campbell, 7th Earl of Argyll and
father of the celebrated first marquis, was married in 1609.
There were a considerable number of small charitable gifts belonging to this
parish. Of the larger, Ralph Pindar was a donor of £60; Nicholas Reive, of £406 :
5s. in 1626; William, Earl of Devonshire, of £100.
There was one charity school for twenty-five boys and twenty-five girls, who
were taught and made apprentices by subscription and legacies. Also almshouses
in Lamb’s Court for the poor of the parish, maintained by Dulwich College, and
three almshouses by the pesthouse for three poor widows, the gift of Lady Lumley.
Some of the notable rectors were: Alfred Earle, Bishop of Marlborough, in
1888; Charles James Blomfield (1786-1857), Bishop of Chester; John Lake (1624-
89), Bishop of Chichester.
On the site of Spital Square, Bishopsgate Street Without, stood the ancient
house called St. Mary Spital, for an account of which see Mediæval London, vol. ii.
p. 322.
Bishopsgate Street Without is a curious mixture of old houses, some with
grotesque features, and modern buildings presenting only a strip of much-
ornamented stone or brick frontage. After the Great Eastern Hotel on the west, the
frontage of the station presents a very long row of uniform buildings in new red
brick with stone dressings and ornamental gable ends. The famous old house
named Paul Pindar’s was pulled down to make way for these.
Paul Pindar (b. 1565) was the son of Ralph Pindar, alderman’s deputy for the
ward of Bishopsgate. At sixteen he was apprenticed to one Parvish, an Italian
merchant who sent him to Venice as his factor, and he stayed there many years. In
1615 he was sent to Turkey as Ambassador by request of the Turkey Company, and
he remained there for nine years. He returned in 1623, and was knighted. The King
offered him also the Lieutenancy of the Tower, which he declined. Charles
thereupon made him Farmer of Customs.
In 1639 he possessed £236,000, out of which he gave large sums to the King.
He died August 22, 1650. The row of houses that now stand on the site of his house
have fairly good shops on the ground-floors, and there are one or two archway
entrances into the station premises near the north end. The Black Raven public-
house is one of these. Acorn Street, Skinner Street, and Primrose Street need very
little comment. They are chiefly composed of the sides of houses fronting
Bishopsgate, and some ordinary modern brick buildings.
Nos. 131-2-3 are old plaster houses, and No. 120, beyond Acorn Street, has a
projecting bay window carried up two stories. This is also an old house. These are
all on the west side. On the east, beginning again from the south end, the first
building to attract attention is the Metropolitan Fire Brigade Station, erected 1885.
It is an improvement on the monstrosities continually perpetrated in the name of
the Fire Brigade. The Bishopsgate Institute is near Brushfield Street. It fronts
Bishopsgate with an elaborate yellow terra-cotta façade, and has an open entry.
The entrance to the Bishopsgate Chapel is under an old stuccoed house, and the
chapel itself is a large stuccoed building. Beyond this, after a Great Northern
Receiving Office, are some very old houses, plastered with rough stucco in
imitation of stone. These are Nos. 82 to 84. One of them has wooden rusticated
work from above the first story to the top of the gable end. The date 1590 is stated
to have been visible on one of them within the memory of man. On the corner
house of Spital Street is a tablet noting the point of the City Bounds. This was
placed here in 1846.
GROUP V
We come next to those streets which run north and south of Thames Street.
The area is bounded on the north by Ludgate Hill, St. Paul’s Churchyard, Cannon
Street, and Fenchurch Street; on the south by the Thames; on the east by Tower
Hill and the site of London Wall; and on the west by the bed of the Fleet River, now
New Bridge Street. For the sake of convenience we will begin at the west end.
The wall of the City originally crossed Ludgate Hill at the gate, and ran down
nearly in a straight line to the river. The Castle or Tower of Montfichet was in the
middle of this piece of wall, and Baynard’s Castle was at the south end of it. The
Tower of Montfichet passed into the Fitzwalter family, who also owned the soke
beside it. Now, when the first enmity broke out between John and Fitzwalter, all
the castles and houses of the latter were dismantled and destroyed by the King’s
command. In 1276 the Dominicans begged permission to occupy a piece of ground
lying between the wall and the river Fleet. Lord Fitzwalter gave the Friars the site
of Castle Baynard and of Montfichet. They also obtained permission to pull down
the town wall at this place, and to rebuild it farther west, so as to include their
ground. Here the Black Friars settled and built great buildings, and claimed the
right of sanctuary. Westward of the Black Friars was the house of the Carmelites,
called the White Friars. They claimed right of sanctuary also, a right which
descended to a haunt of rogues, called Alsatia, an account of which may be read in
The Fortunes of Nigel:
“The ancient sanctuary at Whitefriars lay considerably lower than the elevated
terraces and gardens of the Temple, and was therefore generally involved in the
fogs and damps of the Thames. The brick buildings by which it was occupied
crowded closely on each other.... The wailing of children, the scolding of their
mothers, the miserable exhibition of ragged linens hung from the windows to dry,
spoke the wants and distresses of the wretched inhabitants; while the sounds of
complaint were mocked and overwhelmed in the riotous shouts, oaths, profane
songs, and boisterous laughter that issued from the alehouses and taverns, which,
as the signs indicated, were equal in number to all the other houses.”
Where is now Bridge Street was formerly the Fleet River, and on its western
bank was Bridewell Palace, a palace where the Norman kings held Court.
The old palace, burnt down in the Great Fire, was built round two courtyards;
in its later days rebuilt, it followed the frequent fate of such ancient monuments,
and became partly a “hospital” for poor boys, partly a prison for vagrants and other
unwanted persons. It was also a hospital for lunatics, and was put under the same
management as Bethlehem in 1557. Bridewell is also fully described in London in
the Eighteenth Century. The part of London bounded north and south by Fleet
Street and the River, east and west by New Bridge Street and the Temple, is now
almost entirely occupied by mammoth printing-offices; yet on the Embankment
are one or two buildings of note: Sion College, opened here in 1886 to supersede
the old building on London Wall; the Guildhall School of Music; the City of London
School for Girls (all modern).
After Blackfriars Bridge, running behind the line of wharves and warehouses,
begins Thames Street, Upper and Lower, once one of the principal thoroughfares
in London, a London that knew nothing of what is now called the “West End.” It is
now a noisy street “pestered” with drays and vans, with cranes and their
accompaniments, so that to walk therein in work-hours is a perilous proceeding.
Yet this ancient street, Thames Street, is, not even excepting West Chepe, the
most interesting and the most venerable of all the streets of London. It is the seat
of the export and the import trade. From Thames Street the City sent abroad the
products of the country—the iron, the wool, the skins and hides; from Thames
Street the City distributed the imports to the various parts of the country.
Off the wharves of Thames Street lay the shops of all the nations of Western
Europe. In the narrow lanes leading down to the stairs between the quays lived the
seafaring folk and those who worked for them, and those who worked for the
merchants.
London at one time was roughly divided into belts of population. The first belt
is that of the Service. It consists of the foreshore between Thames Street and the
river, with the lanes and houses upon it. The second is that of the Merchants,
between Thames Street and the Markets of West and East Chepe. The third is that
of the Markets. The fourth that of the Industries between the Markets and the
Wall.
As to the first: The Wall of London, when it was first erected, was carried
along the river from the south-west angle to the Walbrook. Beyond the Walbrook
the south wall of the Roman fortress formed a river-wall, which was continued as
far as the south-east angle.
Beyond that stream the south wall of the Roman fort was allowed to remain as
the river-side wall of the City, when all the rest of the Roman buildings, temples,
public edifices, tombs, and villas were ruthlessly pulled down to build the wall
towards the end of the fourth century.
Now, the wall between the south-west angle and the Walbrook ran along the
middle of Thames Street. At the time of its construction there were, therefore, no
buildings between the wall and the river. It was built about the middle of the bank,
which sloped to the river below, with a narrow stretch of mud at low tide; and
above it rose on the hill which still exists, to the higher ground on which the City
stood. The breadth of the foreshore varied, but, of course, it was not very great. The
first break in the wall was that which allowed for the waters of the Walbrook. Here
there was the first port—the Roman port. It may have been the only port, unless, in
their haste to complete the wall, which was undoubtedly built under the pressure
of panic, the builders deliberately excluded other ports. In that case there may have
been many, for nothing was easier than to make a small port, such as the two
which still remain of Billingsgate and Queenhithe. A small square space was dug in
the mud and shingle of the foreshore. It was maintained by piles placed close
together along the three sides of the square, leaving the fourth side open for the
ships. Other piles furnished support for wharves and quays.
It is therefore quite possible that there may have been other such ports.
Puddle Dock may have been one. In the absence of any evidence which might lead
one even to form a conjecture, we may believe that Queenhithe, originally Edred’s
hithe, was of later, or Saxon, construction; while Billingsgate, close to London
Bridge and Bridge Gate, was probably still earlier.
What happened, therefore, was this: On the increase of trade, when London
was again settled in the sixth century, wharves and quays began to be pushed out
on piles upon the foreshore of Billingsgate and Walbrook, or afterwards at other
places, when a break in the wall allowed access to the City. When Queenhithe was
constructed as an additional port, another break was needed in the wall, and
wharves and quays were built along this part of the foreshore as well. The erection
of the wharf on piles was speedily followed by the erection of tenements for the
people between the wharf and the wall on the bank. The wharf extended laterally;
the houses grew up laterally with the wharf; the wharf was pushed out farther upon
the mud of the low tide; the wall was broken into here and there at intervals,
continually growing less in length. These breaks are marked, possibly, by the
ancient stairs, such as those of Paul’s Wharf and Trig Stairs.
In a word, the whole of the first belt, that of the Service, is later than the
Roman wall. It belongs, therefore, to the Saxon period, and in great part, perhaps,
to the early Norman times. It seems likely that, if the riverside wall had been
pierced or broken in parts, the Danish and Norwegian besiegers would have
attacked the City at those vulnerable points. A narrow stream, such as Walbrook,
with wharves on either side, could be easily defended by chains drawn across; but a
dozen places where the wall was broken—and there was nothing to defend it except
wooden wharves and wooden huts—would have been difficult to defend.
BLACKFRIARS BRIDGE, 1796
Thames Street in later times, when the wall had disappeared, became the most
crowded, the most busy part of the City. Its south side was wholly occupied by
wharves, warehouses, and the dwellings of the working people, the Service of the
port. On the north side and in the streets rising up the hill were the houses of the
merchants and the better class—the second belt of the City. Here stood the
townhouses of the nobles among the equally stately houses of the merchants. Here
kings were entertained by the mayors and aldermen. The great number of churches
shows not only the crowded condition of this part, but also the wealth of the
merchants by whom the churches were founded, rebuilt, adorned, and endowed.
The breadth of the foreshore as at present built upon varies from 150 feet at its
narrowest, which is at the western end, to 450 feet at its broadest, which is on
either side of the Walbrook. The modern breadth, however, must not be taken to
represent the breadth in the twelfth century. The excavations for London Bridge in
1831 disclosed three distinct lines of piles, representing three several occasions
when the foreshore was built upon. And the oldest plan of London, called after one
Agas, clearly represents the erection by the riverside built upon piles. There are no
churches on this belt of reclaimed land. As it was gradually added to the City, so it
was gradually added to the riverside parishes. Four churches are built on the south
side of Thames Street, viz. Allhallows the Great, Allhallows the Less, St. Botolph,
and St. Magnus. The dedication of the last two proclaims their late origin. The last,
for instance, must belong to the late eleventh or the twelfth century. The very small
size to which the parishes would be reduced if we took away the reclaimed
foreshore seems to indicate that much was reclaimed before the Norman Conquest.
The dedication of the churches along Thames Street—St. Peter, St. James, St.
Michael, St. Mary, St. Andrew—has been supposed to indicate the site of Roman
churches. Perhaps the parish boundaries may have been adjusted from time to
time.
“Roomland” was the name given to the quays and the adjacent plots of land of
Queenhithe, Dowgate, Billingsgate, etc., whereon goods might be discharged out of
vessels arriving there.
In 1311 and in 1349 we find mention of houses built upon “la Romeland” by St.
Michael, Queenhithe. In 1338, and again in 1349, we read of a tenement near the
King’s garden upon le Romelonde, near the Tower. In 1339 we learn that there was
a Roomland in the parish of Allhallows Barking. After 1374 we find no more
mention of any Roomland. Perhaps the limits of the quays were by this time
contracted and defined; perhaps the foreshore had been enlarged and the “land”
behind had been built upon.
Thames Street was the Exchange, the place of meeting for the merchants. One
supposes, however, that the lesser sort transacted business at the taverns. Here
walked in great dignity Aylwin of London Stone, the first mayor; Whittington,
Philpott, Rokesley, and the Beckets, Faringdons, Walworths, Sevenokes, and all the
great men of the City, each in his generation, not only building up their own
fortunes, but fighting against disorder and crime in their wards, and against
encroachments from the sovereign.
The Fire swept through the street, raging among the stores of the warehouses,
laying low churches, destroying monuments, and burning up old memories and
associations.
The warehouses were at once rebuilt, but, according to Malcolm (1803), many
of the buildings had in his time become ruinous or decayed. There is very little left
of the building immediately after the Fire: hardly a single warehouse, and on the
north side only one or two of the mansions built by the merchants. The two ports,
Billingsgate and Queenhithe, still remain, though the trade of the City is no longer
carried on upon the quays. The Custom House still stands very nearly on its old
site; the bridge has been moved farther west; there are other City bridges—
Blackfriars and Southwark; one can still walk down lanes as narrow as when they
were first reclaimed from the foreshore; and there are still one or two of these
narrow lanes where, as of old, the people of the Service live.
The following is a list of the old signs in Thames Street:
“The White Bear” inn; “The White Lion” inn near London Bridge; “The White
Lion” inn at the White Lion Wharf; “The Blew Ancor” inn; “The Old Swan” inn;
“The Bull Head” inn; “The Naggs Head Tavern” inn; “The Princes Arms” inn; “The
Fling Hors” inn; “The Lion and Key” inn; “The Black Bell inn; “The Woodmongers
Arms” inn; “The Crose Bulets” inn; “The Suggar Lofe” inn; “The Lobster” inn; “The
Bear and Ragged Staff” inn; “The Two Fighting Cocks” inn; “The Blue Boar and
Three Horse Shoes” inn; “The Horse Shoe” inn; “The Royal Arms on Shield” inn;
“The Cross against Barkin Church” inn.
Thames Street itself is the subject of a great many references in the Calendar
of Wills dated from 1275 to 1688. The earliest is in 1275, after which they occur
repeatedly. In 1280 a tenement is mentioned as that of Ernald Thedmar; in 1282
Henry de Coventre bequeathed to his wife his mansion in the Vintry from Thames
Street to the waterside.
So far, we have spoken of Thames Street and the riverside generally; let us
now take our section in detail.
Only a short way to the north lay Ludgate, one of the principal entrances to
the City.
Ludgate can hardly have been so named later than the Norman Conquest.
Stow, in his explanation of the ancient street leading from Aldgate to Ludgate,
clearly conveys the belief that it was an ancient gate. Perhaps the necessity of land
communications from the City to Westminster caused the piercing of this gate and
the construction of the causeway and the bridge over the valley and stream of the
Fleet. In that case, one would naturally think of King Knut and his palace at
Westminster. The name is said to mean a postern.
Ludgate was either repaired or rebuilt in 1215, when the barons, in arms
against King John, entered London and destroyed the houses of the Jews, using
the stones in the restoration of the City walls and of Ludgate more especially. Stow
records a curious confirmation of this circumstance, the discovery, when the gate
was rebuilt in the reign of Queen Elizabeth, of a stone with a Hebrew inscription,
signifying the sign or note of Rabbi Moses, the son of Rabbi Isaac. On the east side,
in a niche, on this renewal, were placed the statues of Lud and his two sons in
Roman costumes; and on the west side the statue of Queen Elizabeth. When the
gates were taken down (1761-62), Lud and his sons were given by the City to Sir
Francis Gosling, who intended to set them up at the east end of St. Dunstan’s
Church, in Fleet Street. This, however, he did not carry into effect, and the king
and his two sons were deposited in the parish bone-house. The statue of Elizabeth
met with a better fate, having a niche assigned it in the outer wall of old St.
Dunstan’s, Fleet Street. The Lud gate of 1586 was gutted in the Great Fire, and the
stonework seriously injured.
Ludgate was first erected into a prison in the reign of Richard II., and was
anciently appropriated to the freemen of the City and to clergymen. The place soon
became too small for the growing occasions of the City, and it was enlarged at the
expense of Dame Agnes Forster, widow of Stephen Forster, mayor in 1454.
“Formerly Debtors that were not able to satisfy their debts, put themselves
into this prison of Ludgate for shelter from their creditors. And these were
merchants and tradesmen who had been driven to want by losses at sea. When
King Philip, in the month of August, 1554, came first through London, these
prisoners were thirty in number, and owed 10,000 pounds, but compounded for
2000 pounds, who represented a well-penned Latin speech to that Prince to
redress their miseries, and by his royal generosity to free them. ‘And the rather for
that place was not Sceleratorum Carcer, sed Miserorum Custodia, i.e. a gaol for
villains, but a place of restraint for poor unfortunate men; And that they were put
in there, not by others, but themselves fled thither; and that not out of fear of
punishment, but in hope of better fortune.’ The whole letter was drawn by the
curious pen of Roger Ascham, and is extant among his epistles, Lib. III.”
(Cunningham).
The rules and customs of Ludgate are given by Strype:
“If a freeman or freewoman of London be committed to Ludgate, they are to
be excused from the Ignominy of irons, if they can find sureties to be true
prisoners, and if the sum be not above £100. There is another custom for the
liberal and mild imprisonment of the citizens in Ludgate; whereby they have
indulgence and favour to go abroad into any place, under the guard and
superintendency of their keeper; with whom they must return again to the prison
at night.
“This custom is not to hinder and delay Justice nor to defraud men of their
debts and executions, as it is quarrelled against by some, but serves for a
mitigation of their punishment; and tends rather for the expedition of their
discharge, and speedy satisfaction of their creditors. While they may go and inform
themselves, upon their mutual reckonings, both what they owe, and what is due
unto them.” For further account of this prison see London in the Eighteenth
Century, pp. 581-87.
In the year 1659, one Marmaduke Johnson, a prisoner in Ludgate, presented a
memorandum on the prison and its Government to the Lord Mayor. In this
document he sets forth the history of the prison, its constitution and laws, its
officers, its charities, and the grievances of the prisoners.
A great many benefactors have left money to the prison, amounting in all to
about £60 a year. In addition, the Lord Mayor allowed the prisoners a basket of
broken meat every day; and provisions of some kind were every day, to some small
extent, bestowed upon them by the markets. Besides which there were two grates,
one in Ludgate, and the other on the Blackfriars side, where all day long a man
stood crying, “Pity the poor prisoners.” There were about fifty of the prisoners “on
the Charity,” as it was called. But the warders and turnkeys, by their exactions, got
most of the money.
Ludgate Hill was formerly Bowyer Lane. On the south, until a few years ago,
were to be seen some fragments of London Wall, now vanished.
On the top of Ludgate Hill, and on the west side of St. Paul’s, Digby, Grant,
Winter, and Bates were executed, January 30, 1606, for their participation in the
Gunpowder Plot.
The houses on the south side of the hill were set back when the street was
widened in modern times. On the north side there are several old ones.
ST. MARTIN, LUDGATE
This church was rebuilt in 1437 for Sir John Michael, then mayor, but was
destroyed by the Great Fire, and rebuilt from the designs of Wren in 1684. The
benefice was united with the united benefices of St. Mary Magdalene, Old Fish
Street, and St. Gregory by St Paul’s, by Order in Council, 1890. The earliest date of
an incumbent is 1322.
The patronage of the church, long before 1322, was in the hands of: The Abbot
and Convent of Westminster; Henry VIII., who seized it and granted it to the
Bishop of Westminster, January 20, 1540-41; the Bishop of London, by grant of
Edward VI., 1550, confirmed by Queen Mary, March 3, 1553-54, in whose
successors it continued.
Houseling people in 1548 were 476.
The interior of the church is noticeable as being broader and higher than it is
long, its width being 66 feet, height 59 feet, and length 51 feet. The appearance is
rendered cruciform by four composite columns, which, with pilasters on the walls,
support entablatures at the angles of the church. The ceiling is lowered in the
quadrangular corners thus formed. The tower rises at the centre of the south front,
and contains three stories; this is concluded by a cornice, above which there is a
narrow stone stage surmounted by an octagonal cupola, with a lantern and
balcony. The steeple is completed by a tapering spire, with ball, finial, and vane; its
height is 158 feet. It is said to have been especially built by Wren to form a
foreground to the towering dome of St. Paul’s.
Chantries were founded here by: William Sevenoke, whose endowment
fetched £3 : 6 : 8 in 1548; Michael de London and John le Hatte, augmented by
Roger Payn, William Pows, Simon Newell, and Thomas Froddashame, to which
John de Derby was admitted as chaplain, January 11, 1392-93, on being vacated by
Roger Shirrene; William Alsone, who also founded chantries in Northants and
Derbys.
William Sevenoke, grocer, who founded a free school and almshouses in the
town of Sevenoaks, Kent, Mayor of London, 1419, was buried here and
commemorated by a monument. The other monuments recorded by Stow are of
little note. No benefactors are recorded by Stow.
Sixty boys and fifty girls, belonging to the charity school of the ward, were
clothed and disposed of (when fit) by subscriptions from the inhabitants.
William Glyn (d. 1558), Bishop of Bangor, was rector here; also Richard
Rawlins (d. 1536), Bishop of St. David’s.
Photochrom Co., Ltd.
LUDGATE CIRCUS AND LUDGATE HILL
On Ludgate Hill we find also Stationers’ Court, where is the Stationers’ Hall.
THE STATIONERS COMPANY
The Company was incorporated in 1557, but it is believed that a brotherhood
or society existed upwards of a century and a half previously, called the
Brotherhood or Society of Text-writers.
There was a Gild of Stationers as early as the beginning of the fifteenth
century. It appears to have been a branch of the Scriveners, and to have left them
to carry on the preparation of legal documents while they themselves took over the
production of books. The charter of the Company shows that it was regarded as a
company of printers, and that Queen Mary intended it to be especially a guard
against the issue of heretical doctrines.
Drawn by Thos. H Shepherd.
STATIONERS’ HALL IN 1830
The original charter was destroyed in the Fire of London, but the Company
have a copy of it; also of the charter granted by William and Mary, confirming the
privileges granted by the charter of 1556.
The Company has continued ever since its incorporation, and still is, a trade
guild consisting exclusively of members of the trade of a stationer, printer,
publisher, or bookmaker, and their children, and descendants born free. The
greater number of printers’ apprentices in the City of London are bound at
Stationers’ Hall, and the Company’s pensioners, and the recipients of the charities
under their control, are principally journeymen printers, compositors, and
pressmen.
The Company was originally established for the purpose of fostering and
encouraging the trade of a printer, publisher, and stationer, and from the time of
its original foundation to this date a limited number of liverymen of the Company
have carried on at Stationers’ Hall the trade of a publisher for their own benefit,
and a division of profits has been annually made amongst the partners. Other
portion of the profits has been distributed annually amongst poor freemen of the
Company, applied towards the necessary expenses of the Company, and invested
in the purchase of the hall and premises adjoining. The capital for this trade was
originally subscribed by the members of the Company in certain proportions or
shares, and these shares have been regularly transmitted from time to time since
1605, as in the case of shares of trade companies.
The copyright registry was first established by the Company at the
commencement of the sixteenth century or even earlier. It would appear from the
ancient records that a register of copies had existed previous to the incorporation.
In 1565 rules were made by the Company regulating the transmission of copies
upon the decease of the owner, and requiring them to be entered in the books of
the Company. In 1584 the Privy Council (through the Lord Mayor) ordered that all
copies should be entered in the Company’s register, and copyrights were from time
to time transferred by entries in these registers. Between 1580 and 1615, there are
letters from the Lords of the Council and the Lord Mayor calling attention to the
publication of certain books of a traitorous or mischievous tendency. There is no
mention of any power or authority belonging to the Stationers Company for the
suppression of these books. On one occasion the Wardens of that Company are
ordered to produce the printer of a certain pamphlet with the person who was
circulating it. Various orders were from time to time issued by the Lords of the
Privy Council and High Commissioners, regulating printing. In 1660 a committee
of the House of Commons was appointed to prepare a Bill regulating printing, and
in 1662 the Bill was passed, and was known as the Licensing Act. It required all
printed works to be registered at Stationers’ Hall. This Act expired in 1681, and in
1710 the first copyright Act was passed, which has been superseded by the Act of
1842. The Act of 1710 required copies to be entered at Stationers’ Hall before
publication, and the Act of 1842 makes entry at Stationers’ Hall a condition
precedent to the title to sue for protection against infringements. As a printer, not
as a novelist, Samuel Richardson was a member.
The most ancient hall stood in Milk Street, Cheapside, but in 1553 the
Company moved to St. Peter’s College, near the Deanery of St. Paul’s, and in 1611
they purchased Abergavenny House in Stationers’ Court. This was burnt in the
Great Fire. The present building was erected in 1670, and in 1805 the exterior was
cased in Portland stone, according to a design by the Company’s architect, Robert
Mylne, F.R.S.
The present livery is 284; the Corporate Income is but small, and the Trust
Income £1200.
The Company formerly published almanacks, primers, “A.B.C.’s,” psalters, and
school books, in which they maintained a valuable monopoly until the middle of
the eighteenth century, when it was declared illegal.
The Company established a school at Bolt Court, Fleet Street, in 1861; this is
now at Ridge Road, Hornsey. The school has accommodation for more than three
hundred boys.
This corner of London to the south of Ludgate Hill was covered with narrow
lanes and courts into which light was admitted by the construction of Queen
Victoria Street. It is the site of the Blackfriars’ Precinct. This house was in the
hands of the Dominicans. See Mediæval London, vol. ii. p. 354.
Church Entry marks the site of
St. Anne, Blackfriars, standing adjacent to the walls of Blackfriars’
Monastery; it was consecrated in 1597 by Edmund Stanhope, Doctor of Laws, by
virtue of a commission from the Bishop of London. It was enlarged on the south
side in 1613, which was consecrated by the Bishop of London in 1617. The church
was burnt down in the Great Fire and not rebuilt, but the parish was annexed to St.
Andrew by the Wardrobe. The earliest date of an incumbent is 1597.
The patronage was in the hands of the Crown and parishioners alternately,
since the Great Fire when it was burnt down, and the parish was annexed to St.
Andrew by the Wardrobe; before this the parishioners presented.
Isaac Oliver, miniature painter, was buried here.
STATIONERS’ HALL (INTERIOR)
The charities and reliefs recorded in this parish were few. John Bobhurst was
a donor of £2 per annum, also Edward Corbet and Mrs. Miller. The greatest
benefactor was Peter Jorge, who founded a free school, appointing Sion College
trustees.
Forty boys and thirty girls were to be taught reading and writing, and some
useful work besides. All were to be given clothing once a year and two to be put out
as apprentices. The school was endowed with £150 a year, and salaries for
teachers. As there were many tailors among the foundation, the children of such
were to have preference of admission (Stow and Strype).
St. Anne’s had some notable vicars, among them William Gouge (or Goughe),
D.D., forty-six years minister of the parish. In November 1633 “Mr. William
Goughe, Doctor of Divinity, prayed to be admitted freeman of the Society of
Apothecaries, and was so.”
On the west is an open space fairly wide, with asphalt centre and scrubby
bushes round. This is jealously guarded by iron rails and wall from all intruders. It
was sacred ground, the churchyard, though there are no monuments or stones left
to bear testimony. Close beside the churchyard in a carpenter’s shop are certain old
arches belonging to the Dominicans’ Buildings.
Westward there is a small court, called Fleur-de-Lys, on the west side of St.
Anne’s churchyard, which escaped the Fire, though here the Fire had raged most
hotly. A little consideration will show the reason. An open space called Church
Entry lay between the backs of the Fleur-de-Lys Houses and St. Anne’s Church and
churchyard. Now the church stood high, and during the continuance of the Fire the
wind blew steadily from the east. The view of the City after the Fire shows that the
walls of the churches and of many houses were still standing. Therefore, even
though the roof was burned, the flames blew over this court, while, when the roof
had fallen, the walls of the church sheltered the little court on the other side. I dare
say that, had we a more exact account of the Fire, it would be found that many
houses or courts escaped in the same way.
“Eminent inhabitants—(of Blackfriars), Isaac Oliver, the miniature-painter.
He died here in 1617, and was buried in St. Anne’s, Blackfriars. Lady Ayres, wishing
to have a copy of Lord Herbert of Cherbury’s picture to wear in her bosom, went ‘to
Mr. Isaac the painter in Blackfriars, and desired him to draw it in little after his
manner.’—Cornelius Jansen, the painter (d. 1665). He lived in the Blackfriars for
several years, and had much business, but left it a little before Van Dyck’s arrival.
Sir Anthony Van Dyck, from his settlement in England in 1632, to his death in
1641. The rent of his house, ‘at a moderate value,’ was estimated, in 1638, at £20,
and the tithe paid £1 : 6 : 8. His daughter Justina was born here December 1, 1641,
and baptised in St. Anne’s, Blackfriars, December 9, 1641, the day of her father’s
death. Ben Jonson, who dates his dedication of Volpone or The Fox ‘from my
house in the Blackfriars, this 11th day of February, 1607.’ Here he has laid the
scene of The Alchemist. The Earl and Countess of Somerset were living in the
Blackfriars when Overbury was murdered. The precinct no longer exists, but is
now a part of the ward of Farringdon Within. I have not been able to trace any
attempt to assert its privileges later than 1735, when in the July of that year the
Court of Common Council brought an action against Daniel Watson, for opening a
shop and vending shoes in the Blackfriars without being free of the City. The court
of King’s Bench gave it in favour of the City. The sheriffs could arrest here many
years before” (Cunningham).
Note that the Earl of Northumberland had a town house in 1612 in the
unfashionable precinct of Blackfriars.
FLEUR-DE-LYS COURT
Within the precinct were—and are—several places of interest. The Blackfriars
Theatre was built in 1576. It was rebuilt or extensively repaired in 1596 when
Shakespeare and Richard Burbage were sharers. In 1633 it was let by Cuthbert and
William Burbage for a rent of £50. The building was pulled down in 1655 and
tenements put up in its place. Playhouse Yard preserves the memory of the theatre.
Standing at the western end of Queen Victoria Street and taking a general view
we see St. Paul’s Station of the L.B. and S.C. Railway. Water Lane runs by the
railway. Here is the Apothecaries’ Hall.
THE APOTHECARIES COMPANY
Two opposite forces acted upon the City Companies: one separating them and
multiplying Companies for different parts of the same trade or craft; the other
uniting in one Company crafts which were related chiefly by using the same
material. Thus the Barbers divided into Barbers and Surgeons; the Grocers into
Grocers and Apothecaries; while at one time the Weavers included in their body all
those trades which had to do with woven stuffs, and were so powerful that they
threatened to rule the whole City. It happened sometimes that some trades were
injured by the inability of the Company to look after them. Thus it was quite
natural that the Grocers who imported drugs and spices and oils used by
Apothecaries should include these persons in their own livery. But, the wardens
not being skilled in the use of medical prescriptions and preparations, could not
look after their own people. Consequently complaints became general of the
ignorance and incompetence of Apothecaries for want of proper supervision.
Towards the end of the sixteenth century these complaints were brought forward
categorically. It took time for the matter to be understood, and it was not until 1617
that James bestowed a separate charter upon the Apothecaries in spite of the
remonstrances of the Grocers.
The objects of this charter, concisely stated, are to restrain the Grocers (the
former associates of the Apothecaries) or any other City Company from keeping an
apothecary’s shop or exercising the “art, faculty, or mystery of an apothecary
within the City of London or a radius of seven miles.” To allow no one to do so
unless apprenticed to an apothecary for seven years at least, and at the expiration
of such apprenticeship such apprentice to be approved and allowed by the master
and wardens and representatives of the College of Physicians, before being
permitted to keep an apothecary’s shop, or prepare, dispense, commix, or
compound medicines. To give the right of search within the City of London or a
radius of seven miles of the shops of apothecaries or others, and “prove” the drugs,
and to examine within the same radius all persons “professing, using, or exercising
the art or mystery of apothecaries.”
It also confers the power to burn “before the offender’s doors” any
unwholesome drugs, and to summon the offenders before the magistrates.
And to buy, sell, or make drugs. Up to the passing of the Apothecaries Act,
1815, so far as the prescribed radius extended, the three first-stated objects of the
charter and the existence of the society in relation to its members were identical. A
member of the Society of Apothecaries and an apothecary of the City of London or
within seven miles were convertible terms.
As regards the fourth object prescribed by the charter, the Society, doubtless
from its want of means, has never itself until the present time bought, sold, or
made drugs, but owing to the great difficulty of its members obtaining pure drugs
it allowed them to raise money themselves and create stock or shares for that
purpose, and to carry on such trade in the name of the Society for their own
personal profit as a private Company or partnership under various titles. Owing to
such trade having ended in a loss, this private partnership was dissolved in 1880,
and the Society is now itself carrying on the trade at its own risk.
As regards the three first-stated powers of the charter, the Society (by means
of the Apothecaries Act of 1815) extended them so greatly as to effect not only a
revolution in their own sphere of operations, but also in the medical profession
and in the relations subsisting between the latter and the general public.
This Act (after placing the right of search referred to in the third-stated power
of the charter on a more precise and practical basis, but to which it is unnecessary
to allude as having fallen into necessary desuetude by the various Pharmacy and
Poisons Acts) created a court of 12 examiners to be appointed by the master,
wardens, and court of assistants, who were to examine all persons in England and
Wales as to their skill and ability in the science and practice of medicine, and five
examiners to examine assistants for the compounding and dispensing of medicine.
It authorised the Society to receive fees for granting the respective licences, and
(saving the rights of the Colleges of Physicians and Surgeons) it empowered the
Society to recover penalties for practising or compounding without such licences.
The Apothecaries Act, 1815, contained, however, two restrictions which were
removed by the Apothecaries Act Amendment Act, 1874, namely, (a) the obligation
of the 12 examiners being members of the Society of Apothecaries, and being of at
least 10 years’ standing, and (b) of candidates for examination having served an
apprenticeship of five years to an apothecary.
The Act of 1874 also contains other provisions which relate more to questions
of medical legislation than this present inquiry. Shortly the effect of the Act of 1815
was to make the Society of Apothecaries one of the three great medical licensing
bodies for England and Wales [the number of its present licentiates is between
8000 and 9000], and of the Act of 1874 was to throw open the Society’s
examinerships, and to confer on it a freedom in reference to future medical reform
to an extent not exceeded by any other body.
The Company consists of about 400 members including the court, the livery,
and the yeomanry or freemen.
The hall, which stands on the eastern side of Water Lane, formerly consisted
of the town house of Lady Howard of Effingham. It was, of course, destroyed by the
Fire, but the buildings which were erected after the Fire have a delightful air of
quiet and peace, such as belongs very fitly to a scientific society. The hall stands
behind a small paved court; on the left hand is the shop, at the north end of the hall
are the offices, the library and the court rooms. The Physic Gardens at Chelsea also
belong to the Apothecaries on certain conditions, especially that the Company
should every year present to the Royal Society fifty dried specimens of plants
growing in these gardens, till the number of 2000 was reached. As this was in 1731,
that number has long since passed and the Company’s debt is paid.
Among the more eminent members of this Company have been William and
John Hunter, Jenner, Smollett, Humphry Davy, Dr. Sydenham, Erasmus Wilson,
and Sir Spencer Wells. Oliver Goldsmith and Keats were also members.
Printing House Square contained the King’s Printing House.
“The first I have discovered was John Bill, who, ‘at the King’s Printing House
in Black Friars,’ printed the proclamations of the reign of Charles II., and the first
London Gazette, established in that reign. Charles Eyre and William Strahan were
the last King’s printers who resided here, and in February, 1770, the King’s
Printing House was removed to New Street, near Gough Square, in Fleet Street,
where it now is. The place still continues to deserve its name of Printing House
Square, for here every day in the week (Sunday excepted) The Times newspaper is
printed and published, and from hence distributed over the whole civilized world.
This celebrated paper, finding daily employment on the premises for between 200
and 300 people, was established in 1788,—the first number appearing on the 1st of
January in that year.” (Cunningham.) The Times office is a very notable feature in
Queen Victoria Street by reason of its great height and conspicuous clock. Queen
Victoria Street and Upper Thames Street gradually diverge at a very acute angle.
The former is on a lower level than the latter, and is divided from it for about
seventy yards by a low wall only, with an open space crossed by steps. In Queen
Victoria Street on the left is the square tower of St. Andrew by the Wardrobe,
outlined in white stone, and thrown into relief by a rather ornamental red-brick
building which stands in front.
St. Andrew’s Hill was sometimes called Puddle Dock Hill. In Ireland Yard
stood the house bought by Shakespeare in 1612, and bequeathed by him to his
daughter Susanne Hall. In Green Dragon Court there stood, until a year or two ago,
one of the oldest of the London taverns from which the court took its name.
The Wardrobe.—On the north side of St. Andrew’s church stands a small
square which, with its trees and the absence of vehicles or shops, is one of the most
quiet spots in the whole City. This square was formerly the court of the town house
built by Sir John Beauchamp (d. 1359), whose tomb in St. Paul’s Cathedral was
commonly called Duke Humphrey’s tomb. Before his death the house became the
property of King Edward III. who made it a Royal Wardrobe House, and so it
remained until the Great Fire. James I. gave the collection of dresses—called by
Fuller a “Library of antiquaries wherein to read the fashion and mode of garments
in all ages”—to the Earl of Dunbar, by whom they were all sold and dispersed. The
wardrobe was taken after the Fire to the Savoy and then to Buckingham Street,
Strand. The last keeper was Ralph, Duke of Montagu (d. 1709).
When Charles V. came to England in 1522, among the lodgings assigned to his
suite was the house of Margaret Hanley, “under the Wardrobe side, having two
chambers and two beds.”
Wardrobe Place is a delightful spot with an air of brooding quietness. The
houses are nearly all old “post fire,” dating from about 200 years ago. That on the
east side of the entry is black with age, and the lines in the brickwork waver as they
cross its front. Next to it on the east side of the court is a plaster-fronted one, and
then a row of three dark-brick houses with the so-called “flat arch” of brighter red
bricks glowing above the rectangular windows. Nearly a dozen twisted plane trees,
all young, and measured by inches only in circumference, straggle irregularly from
the cobblestones of the courtyard. On the west side there are charming houses in
the same style as the above-mentioned. The largest of these, No. 2, is wainscotted
from floor to ceiling, and has in many rooms great projecting fireplaces forming
recesses on either side half the width of the rooms. From the south-east corner
there is a covered-in passage leading to the back of the Old Bell Hotel, and with
Wardrobe Chambers opening into them.
ST. ANDREW BY THE WARDROBE
The church derived its title from its proximity to the King’s Wardrobe above
described. It was formerly called St. Andrew-juxta-Baynard’s Castle. After the
Great Fire, the church was rebuilt by Wren and completed in 1692, and the parish
of St. Anne, Blackfriars, was united with it. The earliest date of an incumbent is
1261.
The patronage of this church was in the hands of: The family of Fitzwalter,
Lords of Woodham, 1361, which becoming extinct, it passed to Thomas, Lord
Berkeley, then to Richard, Earl Warwick, who married Berkeley’s daughter; the
three daughters of the Countess of Warwick, viz. Lady Talbot, afterwards Countess
of Shrewsbury; Lady Ross; and Lady Latimer, afterwards Countess of Dorset in
1439; and the Crown, since St. Anne’s, Blackfriars, was annexed to it.
Houseling people in 1548 were 450.
Pictorial Agency.
BRITISH AND FOREIGN BIBLE SOCIETY
HOUSE
This church measures 75 feet in length, 59 in breadth, and 38 feet in height,
and contains two side aisles divided from the nave by square pillars, encased in
wood to the height of the top of the galleries. The ceiling is exceptionally fine, with
beautifully moulded wreaths. The exterior is of red brick with stone dressings. The
tower, which is square and of four stories, rises at the south-west; the two lower
ones contain windows, the third a clock, and the highest has square-headed
openings with louvres. A cornice and balustrade complete the tower, which is
about 86 feet in height.
Chantries were founded here by: John Parraunt, armiger, for himself and
Clemencia his late wife, and for John Loc, alias Foxton, citizen and fishmonger,
and Margaret, his wife (licence was granted December 3, 1409; the endowment
fetched £12 : 3 : 4 in 1518 when Thomas Mores was priest, “aged 54, meanly
learned”); Humphrey Talbot, whose endowment fetched £7 : 6 : 8 in 1548.
There are three pyramidal monuments of white marble to three successive
rectors—the Rev. William Romaine, a celebrated preacher; the Rev. William
Goode, rector in 1795; and the Rev. Isaac Saunders, who held the living for nearly
twenty years.
Some of the donors of charities were: John Lee, of a house and wharf, leased
for £30 per annum; Mrs. Paradine, £3 per annum; Mrs. Cleve, thirteen penny
loaves to be dealt out every Sunday.
There was a free school founded by a private person for the benefit of the
children of poor tailors, where forty boys and thirty girls were taught and clothed.
Also three almshouses maintained by the rent of an adjoining house, built partly by
charity of the Lady Elizabeth, Viscountess Chomondeley, and partly at the expense
of the inhabitants, in 1679.
Among the most notable of the rectors were: Philip Baker (d. 1601), Vice-
Chancellor Cambridge University; William Savage (d. 1736), Master of Emmanuel
College, Cambridge; William Romaine (1714-1795), Professor of Astronomy at
Gresham College, London; William Goode (1762-1816), President of Sion College;
John Harding (1805-74), Bishop of Bombay.
A little passage, right-of-way to the public, goes round the north and east sides
of the church, and at the corner where this joins St. Andrew’s Hill stands the old
Rectory House. This is a charming old building, dating from soon after the Fire.
There is, curiously enough, no oak in the woodwork, excepting only in the cross-
pieces of the window-frames. The fireplace in the study is of interest, fashioned of
marble and tiles set in polished wood; and on the overmantel there is a little slab
bearing the words, all in capital letters:
Laus Deo per Jesum Christum. Church Missionary Society, Instituted April 12,
1799, in this room; the committee meetings of the Society were held from June 17,
1799, to January 3, 1812: and here on January 2, 1804, its first missionaries were
appointed to preach among the Gentiles the unsearchable riches of Christ.
The house betrays its age in all its lines, and though there is no other special
feature worthy of comment in it, the tiny garden behind is well worth a visit; it
contains a plane-tree, and is a curious little oasis in a wilderness of bricks and
mortar.
Queen Victoria Street was only begun in 1867-68 as a direct thoroughfare
from the embankment to the Mansion House. It was formally opened November 4,
1871.
The headquarters of the British and Foreign Bible Society is solidly designed,
with pilasters running up the front between the windows. Over the great door,
supported by blocks of polished granite, is a heavy stone balcony, and three smaller
balconies project from the windows above. An ornamental cornice runs round the
roof. The architect was Mr. Edward l’Anson.
The library contains the Fry collection of English Bibles, the most complete
ever made. This was purchased by the Society for £6000. It includes a copy of the
earliest edition of Coverdale printed abroad 1535, and one of the earliest editions
printed in England two years later. In the cases about the room are many objects of
interest—a German Bible printed 1473; Codex Zacynthus, a palimpsest, of which
the earlier writing is supposed to date from the fifth or sixth century, the later from
the twelfth. The Society was founded in 1804. Its object is simply to “circulate the
Bible without note or comment, in all languages and in all lands.”
Since its foundation over 140 million copies of the Bible, whole or in parts,
have been issued. The Society now produces the Bible in about 330 languages and
dialects. The University Press monopolises the printing of English Bibles, and
much of the printing of the Society in foreign languages is done abroad. The only
actual printing carried on in Queen Victoria Street is that done by one man, who
works with two hand-presses for the blind. But the issue of fresh copies by the
Society comes to an average of 13,000 for every working day.
The General Post Office Savings Bank offices, with a frontage of about 250
feet, are next door. The garden belonging to the old Doctors Commons stretched
across the roadway at this point, and was only finally cleared away in 1867 at the
making of the new street.
The Heralds’ College or College of Arms is a fine old building in deep-coloured
brick. The front stands back from the street, and is supported by two wings. The
small courtyard resulting is separated from the street front by high iron railings
and gates. There are two brick and stone piers at each gateway, with that favourite
ornament of the Stuart period—stone balls—on their summits. The back of the
eastern wing abuts on Peter’s Hill, and the wide, outside flap shutters of an old-
world style give the little hill a quaint aspect. The College was rebuilt after the Fire,
and restored at the opening of Queen Victoria Street. It was originally Derby
House, built by the first Earl of Derby and presented in 1555 by Queen Mary to the
then Garter King-of-Arms; so it has long been devoted to its present use. Returning
to Queen Victoria Street we see opposite in enormous gilt letters, each four or five
feet long, “Salvation Army International Headquarters” right across the front of a
great building.
Addle Hill, like Addle Street, is supposed to be derived from the Saxon Adel,
noble. It has been found written Adling Hill. The whole space between Addle Hill
and Bell Yard, and between Queen Victoria Street and Carter Lane, with the
exception of Knightrider Street, is now occupied by General Post Office Savings
Bank Department. Northward, on the south side of St. Paul’s Churchyard, near the
west end, was the church of St. Gregory mentioned elsewhere.
Carter Lane was formerly divided into Great and Little Carter Lane. From
the Bell Inn, Bell Yard, in Carter Lane, the only letter addressed to Shakespeare
that is known to exist was sent to him by Richard Quiney—“To my loveing good
friend and country man, Mr. William Shakespeare, deliver these.” Bell Yard led to
the Prerogative Will Office, Doctors’ Commons.
Carter Lane, also called Shoemakers’ Row, is mentioned in the Calendar of
Wills in the year 1295. The west end still retains that name in Ogilby’s map of 1677.
In 1424 the exchequer paid to John Kyllyngham, master of a house called The Bell
in Carter Lane, the sum of £17 : 14 : 8 for costs and expenses of Sir Gilbyn de
Lauvoy, knight, and John de la Roe, Esq., and their servants and horses for twenty-
eight days. The said Sir Gilbyn and John de la Roe had been sent to the Holy Land
by Henry V. “upon certain important causes.” Deeds of the fourteenth century
speak of tenements in Carter Lane. In this street were several taverns of note such
as the White Horse, the Sun, the Bell, and the Saracen’s Head. Here was a famous
meeting-house in which many of the most distinguished of Nonconformist
ministers preached.
Pictorial Agency.
THE COLLEGE OF ARMS
Here is the school for St. Paul’s choir-boys, with a stencilled frieze. The
playground is on the roof.
Creed Lane was formerly called Sporier Row. An inn in Sporier Row is
assigned in the fifteenth century by the Dean and Chapter of St. Paul’s to their
canons. After the Fire there were differences as to the sites and boundaries of
houses destroyed in Creed Lane. The Lane was widened in 1750 as one of the
improvements made at that time.
Dean’s Court has now warehouses erected on the north and east sides. The
house over the archway was said to have been occupied by Sir Christopher Wren as
his office during the building of St. Paul’s. Within this court were also the vicar
general’s, the commissary and the consistory courts, and offices for procuring
marriage licences.
St. Peter’s College adjoined Dean’s Court on the west side in St. Paul’s
Churchyard (see under the Stationers Company, p. 199).
When Charles V. came to London in 1522, Doctors’ Commons among other
places furnished for his suite a hall, a parlour, and three chambers with feather
beds. Mention is made of the dining-hall of Doctors’ Commons and of the “entre
going into the great canonicale House now naymed the Doctors’ Commons with a
chamber over the said entre,” and of other parts of the building.
This ancient College or House of Doctors of Law was swept away in 1861-67 in
consequence of alterations in legal procedure. The courts were removed, and the
business of the proctors was merged in the ordinary work of the High Courts of
Justice and the Bar.
The Deanery itself is on the west side standing back behind a high brick wall,
painted yellow. It is attributed to Sir Christopher Wren, and was built soon after
the Great Fire. The stone piers of the gates are surmounted by cones. The building
itself is tiled with three dormer windows standing out from the roof and heavy
projecting eaves. In the interior there is no carving or anything of antiquarian
interest calling for remark, but the front door has some rich wood-carving in the
style of Grinling Gibbons.
Paul’s Chain and the greater part of St. Bennet’s Hill are now Godliman Street.
The origin of the name “Godliman” is unknown. Cunningham says that the earliest
mention of the name is 1732. It is not found in Ogilby nor in Strype. It has been
spelt “Godalmin.”
A little court named Paul’s Bakehouse seems to have been asleep while the rest
of the world passed it by. It is true the house immediately fronting the entry is
covered with ugly yellow plaster, but it is by no means obtrusively modern, and if
we except an iron railing in the corner over an area in the north-east, and the
house above it, the remainder of the court has been touched by time alone since it
left the builders’ hands in the seventeenth century. The houses on the north and
south sides are of brick; the northern ones bulge forward out of the perpendicular,
and they have low wooden doorways. That in the south-west corner is supported by
grooved pilasters. The northern building claims a better staircase in the interior—a
staircase with spiral balusters and carved woodwork, low and substantial.
Knightrider Street.—Why this street should be named, as Stow says, “after
knights riding” more than any other street, it is impossible to explain. One may,
however, suppose that it was named after some branch of the Armourers’ or
Loriners’ Craft. Dr. Linacre lived here. Knightrider Street now extends to Queen
Victoria Street, but formerly the eastern part from Old Change was called Old Fish
Street. Do Little Lane, between Carter Lane and Knightrider Street, now
Knightrider Court, is found in many ancient documents called “Dolite,” “Do
Lyttle,” “Doelittle” in deeds of Edwards I., II., and III.
DOCTORS’ COMMONS, 1808
From a drawing by Rowlandson and Pugin.
ST. NICHOLAS COLE ABBEY
The church stands in Knightrider Street; it has been known by several other
names, Coldenabbey, Coldbey, etc. It was burnt down in the Great Fire, and rebuilt
from the designs of Sir Christopher Wren in 1677, when the parish of St. Nicholas
Olave was annexed. In 1873 it was thoroughly repaired. Four other parishes were
subsequently united. The earliest date of an incumbent is 1319.
The patronage of the church was in the hands of: The Dean of St. Martin’s-le-
Grand, then the Abbot and Convent of Westminster, 1532. Henry VIII., who seized
it, and so continued in the Crown till Queen Elizabeth granted it in 1559 to Thomas
Reeve and George Evelyn, from whom it passed to several private persons and at
length came to the Hacker family in 1575, one of whom, Colonel Francis Hacker,
was involved in the beheading of Charles I.; he was finally executed as a traitor, his
estate including this advowson being forfeited and thus it came to the Crown, and
so continued until St. Nicholas Olave was annexed after the Great Fire, when the
patronage was shared alternately with the Dean and Chapter of St. Paul’s.
Houseling people in 1548 were 180.
The interior of the church, which contains no aisles, measures 63 feet in
length, 43 feet in breadth, and 36 feet in height. The steeple, which rises at the
north-west, consists of a tower of four stories concluded by a cornice with urns at
each angle; above this a spire rises, completed by a balcony, and supporting a
square pedestal with a finial, ball, and vane. The total height is about 135 feet.
Chantries were founded here: By John Sywarde and Thomas Blode, who
endowed it with lands which fetched £6 in 1548, when Anthony Little was priest
“of 50 years and of mean learning”; by John Tupley, who left lands and tenements
valued at £12 : 8 : 4 in 1548, when Ralph Jackson was priest “of 30 years of age and
very well learned”; Thomas Barnard, John Saunderash, and William Cogshale, who
gave their lands in Distaff Lane to endow the same, which yielded £7 : 6 : 8 in
1548, when William Benson was priest, “46 years of age, and a very poor and sickly
man.”
The church contained no monuments of any special note. Walter Turke, mayor
in 1349, was interred here.
Barnard Randolph bequeathed £900 to this parish and St. Mary Magdalene
for charities; he died in 1583. No other names are recorded by Stow.
Herbert Kynaston (1809-1878), High Master of St. Paul’s School, was rector
here. But the most notable among the rectors is the most recent, Prebendary
Shuttleworth, whose death in 1900 left a gap difficult to fill. Among the most
notable of his social schemes was the foundation of a social club for young men
and women who work in the City (see p. 219).
Old Fish Street, partly wiped out by Knightrider Street, was a row of narrow
houses built along the middle of the street like the old houses at Holborn Bars, or
like Butchers’ Row behind St. Clement Danes; or like Holywell Street, Strand. Stow
says:
“These houses, now possessed by fishmongers, were at the first but moveable
boards or stalls, set out on market-days to show their fish sold; but procuring
license to set up sheds, they grew to shops, and by little and little to tall houses of
three or four stories in height, and now are called Fish Street.”
St. Mary Magdalene, Old Fish Street, was situated on the north side of
Knightrider Street at the west corner of the Old Change. It was destroyed by the
Great Fire, and subsequently rebuilt and made the parish church for this and the
parish of St. Gregory; but it was again burnt down in 1886, and has not been
rebuilt.
In 1890 these two parishes were united to St. Martin, Ludgate. The earliest
date of an incumbent is 1162.
The patronage of the church was in the hands of the Dean and Chapter of St.
Paul’s, as a vicarage, about 1162, but about 1319 it was a rectory in the same
patronage and has so continued.
Houseling people in 1548 were 360.
The church formerly contained a considerable number of monuments, but the
individuals commemorated were of comparatively little note. Among them was
one, Barnard Randolph, common sergeant of the City of London, and benefactor of
the parish. He died in 1583.
Some of the charitable gifts recorded by Stow are: A messuage, leased at £28
per annum, the gift of Thomas Berry; 40s. per annum, the gift of Justice Randall;
£3 : 18s. per annum, the gift of the Company of Wax Chandlers.
In St. Gregory’s Parish, in the Ward of Castle Baynard, there was a school
purchased at the cost of Alderman Barber, where thirty boys and twenty girls were
educated. There was one almshouse upon Lambeth Hill.
John Hewitt was rector here; he was tried by Cromwell’s High Court of Justice
in 1658 and beheaded. Also William Crowe (d. 1743), Chaplain in Ordinary to
George II.
Sermon Lane.—According to Stow this was originally Sheremonier’s Lane.
The name is found as “Sarmoneres,” “Sarmoners,” “Sarmouneris,” and
“Seremoneres” Lane. The most interesting mention of the Street is contained in the
Hist. MSS. Comm. Rept. IX., Part I. 26b. (A.D. 1315):
“Whereas a house belonging to the Chapter of St. Paul’s, at the north-east
corner of ‘Sarmouneris’ Lane, has been assigned to Sir Nicholas Housebonde,
minor canon of St. Paul’s, for his residence, the said Sir Nicholas has complained
that it is inconvenient for the purpose on account of the grievous perils which are
to be feared by reason of its distance from the cathedral and the crossing of
dangerous roads by night, and the attacks of robbers, and other ill-disposed
persons, which he had already suffered, and also on account of the ruinous
condition of the building and the crowd of loose women who live around it. The
Chapter, therefore, assigns to him a piece of ground at the end of the schools upon
which to make a house.”
In Sermon Lane is the charity school. It was built in the beginning of the
eighteenth century. Two quaint figures of charity children, each perhaps a couple
of feet high, project from the first floor. The boy dressed in the long lapelled coat,
the girl in panniers, apron, and cap. The house is of brick. The two lower floors
have ordinary wide arched windows, but the two upper ones have each a unique
display of no less than nine narrow, circular headed windows in a row extending
across all the front. These give a curious cloistral aspect to the place. Over the
doorway and two ground-floor windows are scrolls fixed up, but on one only is
there an inscription, which is clearly readable, as follows:
To the Glory of God and for the benefit of the poor children of this parish of
Castle Baynard Ward this house was purchased at the sole cost of John Barber,
Esq., Alderman of this ward, in the year of our Lord 1722.
And on an immense plaster slab running all across the story above is “Castle
Baynard Ward School, supported by voluntary contributions.”
St. Bennet’s Hill.—Strype: “Upon Paul’s Wharf Hill, within a great Gate,
and belonging to that gate next to the Doctors’ Commons are many fair
Tenements, which in their Leases made from the Dean and Chapter go by the name
of Camera Dianæ, or Diana’s Chamber. So denominated from a spacious building
that in the time of Henry II. stood where they now are standing. In this Camera, an
arched and vaulted structure, this Henry II. kept, or was supposed to have kept,
that jewel of his heart, fair Rosamund, whom there he called Rosa Mundi; and
hereby the name of Diana. To this day are remains and some evident testifications
of turnings tedious and windings as also of a passage underground from this
House to Castle Baynard, which was, no doubt, the king’s way from thence to his
Camera Dianæ.”
In 1452 (Hist. Comm. IX.) the “Inn called Camera Dianæ,” alias Segrave, in
the parish of St. Benet is assigned by the Dean and Chapter of St. Paul’s to a Canon
Residentiary of the Cathedral. And in 1480 we find the Camera described as a
messuage with a garden let at eight marks a year to Sir John Clay; it was formerly
occupied by Lord Berners, “but probably belonging to Richard Lichefield, Canon
Residentiary, who pays to the Chapter 26s. a year for the obit of Richard Juvenis.
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!
ebookultra.com

Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch programming 1st Edition Scott Stevenson

  • 1.
    Visit https://ebookultra.com todownload the full version and explore more ebooks Cocoa and Objective C Up and Running Foundations of Mac iPhone and iPod touch programming 1st Edition Scott Stevenson _____ Click the link below to download _____ https://ebookultra.com/download/cocoa-and-objective-c- up-and-running-foundations-of-mac-iphone-and-ipod- touch-programming-1st-edition-scott-stevenson/ Explore and download more ebooks at ebookultra.com
  • 2.
    Here are somesuggested products you might be interested in. Click the link to download Programming iOS 6 3rd Edition Fundamentals of iPhone iPad and iPod touch Development Matt Neuburg https://ebookultra.com/download/programming-ios-6-3rd-edition- fundamentals-of-iphone-ipad-and-ipod-touch-development-matt-neuburg/ Programming the Iphone User Experience Developing and Designing Cocoa Touch Applications 1st Edition Toby Boudreaux https://ebookultra.com/download/programming-the-iphone-user- experience-developing-and-designing-cocoa-touch-applications-1st- edition-toby-boudreaux/ iOS 4 Programming Cookbook Solutions Examples for iPhone iPad and iPod touch Apps 1st Edition Vandad Nahavandipoor https://ebookultra.com/download/ios-4-programming-cookbook-solutions- examples-for-iphone-ipad-and-ipod-touch-apps-1st-edition-vandad- nahavandipoor/ Take Control of Mail on the iPad iPhone and iPod touch Third Edition Joe Kissell https://ebookultra.com/download/take-control-of-mail-on-the-ipad- iphone-and-ipod-touch-third-edition-joe-kissell/
  • 3.
    Pro iOS TableViews for iPhone iPad and iPod Touch 1st Edition Tim Duckett (Auth.) https://ebookultra.com/download/pro-ios-table-views-for-iphone-ipad- and-ipod-touch-1st-edition-tim-duckett-auth/ The Business of iOS App Development 3rd Edition For iPhone iPad and iPod touch Taylor Pierce https://ebookultra.com/download/the-business-of-ios-app- development-3rd-edition-for-iphone-ipad-and-ipod-touch-taylor-pierce/ Building iphone apps with html css and javascript Making App Store Apps Without Objective C or Cocoa 1st Edition Stark https://ebookultra.com/download/building-iphone-apps-with-html-css- and-javascript-making-app-store-apps-without-objective-c-or-cocoa-1st- edition-stark/ Cocoa programming for Mac OS X 2nd Edition Aaron Hillegass https://ebookultra.com/download/cocoa-programming-for-mac-os-x-2nd- edition-aaron-hillegass/ Pro Core Data for iOS Data Access and Persistence Engine for iPhone iPad and iPod touch 2nd Edition Michael Privat https://ebookultra.com/download/pro-core-data-for-ios-data-access-and- persistence-engine-for-iphone-ipad-and-ipod-touch-2nd-edition-michael- privat/
  • 5.
    Cocoa and ObjectiveC Up and Running Foundations of Mac iPhone and iPod touch programming 1st Edition Scott Stevenson Digital Instant Download Author(s): Scott Stevenson ISBN(s): 9780596804794, 0596804792 Edition: 1 File Details: PDF, 10.07 MB Year: 2010 Language: english
  • 8.
    Cocoa and Objective-C:Up and Running
  • 9.
    Cocoa and Objective-C: Upand Running Scott Stevenson Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo
  • 10.
    Cocoa and Objective-C:Up and Running by Scott Stevenson Copyright © 2010 Scott Stevenson. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com. Editor: Brian Jepson Production Editor: Adam Zaremba Copyeditor: Nancy Kotary Proofreader: Sada Preisch Indexer: Ellen Troutman Zaig Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano Printing History: April 2010: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Cocoa and Objective-C: Up and Running, the image of a Pampas cat, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein. TM This book uses RepKover™, a durable and flexible lay-flat binding. ISBN: 978-0-596-80479-4 [M] 1271342831
  • 11.
    Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. Setup and First Run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Download and Install Xcode 1 Your First Application 4 Create the Interface 7 Run the Finished Application 11 2. Thinking in Code: Basic C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 How Code Works 15 How to Format Code 17 Variables 20 Types 21 Constants 23 Enumerated Types 24 Typedefs 24 Functions 24 Declaring Functions 28 Example: FirstProgram 28 Displaying Values on the Command Line 29 Compile and Run the Example 32 Scope 34 Static Variables 35 Conditionals 36 Example: ShoppingTrip 39 Compile and Run 41 Wrap Up 42 3. Memory and Pointers: Advanced C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Arrays 43 Loops 45 v
  • 12.
    Text Strings 47 MultidimensionalArrays 48 Pointers 49 The Purpose of Pointers 50 Using Pointers 50 Pointers and the const Keyword 52 Dynamic Memory 53 Strings and Dynamic Memory 56 Returning Strings from Functions 57 Arrays of Strings 58 Example: AddressBook 59 Compile and Run the AddressBook Example 61 Structs 62 Header Files 64 Compile and Run the HeaderFileTest Example 66 Create Files for the Song Struct 66 Final Example 68 4. Thinking in Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Structs and Classes 74 Designing Classes 76 Accessors 77 Inheritance 78 Composition 80 Object Lifetime 81 Built-in Classes 81 5. Basic Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 NSString Basics 84 Using Methods 84 Nested Method Calls 86 Multi-Input Methods 86 Accessors 86 Dot Syntax 87 Creating Objects 88 Basic Memory Management 88 Using Autorelease Directly 90 Declaring a Class 90 Add Methods 91 Implementing a Class 92 init 94 dealloc 95 Example: PhotoInfo 96 vi | Table of Contents
  • 13.
    6. More Objective-C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 More on Memory Management 103 The Life of an Instance Variable 105 Copying Objects 106 Class Name Prefixes 107 Properties 107 Property Options 109 64-Bit Objective-C 111 Enabling 64-Bit 112 Should I Use 64-Bit? 113 All Further Examples Assume 64-Bit 114 Categories 114 Categories for Private Methods 116 Introspection 118 Protocols 120 Dynamic Messaging 124 Using Selectors to Call Methods 125 Forwarding Messages 126 Exceptions 127 Example: DataCollector 129 Some New Classes and Methods 129 Create the Files 130 Build and Run 136 7. Foundation Value Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 NSString 138 Ranges and Substrings 140 Using NSString with C Types 141 Comparing Strings for Equality 141 Strings As File Paths 142 Reading and Writing Files with Strings 144 Mutability 148 Advantages of Mutability 149 Advantages of Immutability 150 Core Foundation 150 Memory Management 152 Core Foundation Mutability 153 Toll-Free Bridging 154 Core Foundation Types As Properties 155 Drawbacks of Core Foundation Types 156 Open Source 156 NSNumber 156 CFNumberRef 159 Table of Contents | vii
  • 14.
    Cocoa Primitive Types160 NSDecimalNumber 161 NSNumberFormatter 163 When to Use Which Number Type 165 NSData 166 NSMutableData 168 NSArray 169 Fast Enumeration 171 Blocks 171 NSMutableArray 173 CFArrayRef 174 NSIndexSet 175 NSDictionary 177 NSMutableDictionary 178 CFDictionaryRef 179 NSSet 181 NSMutableSet 182 NSValue 183 NSDate 184 CFDateRef 186 8. Basic Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 How to Use This Chapter 189 Windows and Views 190 Targets and Actions 193 Buttons 194 Declaring Action Methods 195 Connecting Actions 198 Menus 203 Responder Chain 206 Pop-up Buttons 211 Sliders 214 Text Fields 216 Outlets 218 Datasources 222 Table View Datasource Methods 226 Implementing Datasource Methods 227 Bindings 230 Key-Value Protocols 234 Bindings for Simple Controls 236 Bindings for Complex Controls 242 Tips for Debugging Bindings 244 viii | Table of Contents
  • 15.
    9. Designing ApplicationsUsing MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 About This Project 248 Window Controllers 249 View Controllers 250 Core Data 253 Create the Project Files 254 Create the Entities 254 Add Attributes and Relationships 255 Update the App Delegate 261 Add the Quartz Framework 264 Create the Window Controller 264 Create the View Controllers 268 Create the Managed Object Classes 280 Create the User Interface 286 Remove the Default Window 287 Create the Main Window Interface 289 Create the Browser Interface 293 Create the Editor View Interface 297 Create the List View Interface 298 Run the Application 301 Preparing for Release 303 10. Custom Views and Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 Basic Geometry 308 Geometry Structs As Strings 310 Geometry Structs As NSValues 311 Cocoa View Coordinates 312 Derived Rects 313 Comparison Functions 314 Basic Drawing 315 NSColor 316 Subclassing NSView 316 Instantiate the View 320 The Graphics Context 323 Bezier Paths 324 Drawing Polygons 324 Drawing Curved Paths 325 Images 329 Loading Image Data 329 Drawing Images in a View 331 Shadows 338 Add a Shadow to StyledImageView 338 Gradients 341 Table of Contents | ix
  • 16.
    Drawing a GradientBackground 342 Drawing an Image Sheen 344 Refactoring View Code 349 Why You Should Refactor 350 Goals for Refactoring 350 Refactored Header 352 Refactored Implementation 354 Test the Refactored Version 359 Text 359 Fonts 359 Attributed Strings 360 Add a Title to StyledImageView 365 Handling Mouse and Keyboard Events 370 Keyboard Events 371 Mouse Events 372 Add Event Support to StyledImageView 372 11. The Final Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 The List 377 Websites 378 Last Thought 380 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 x | Table of Contents
  • 17.
    Preface I’m not sureif this is the first book you’ve picked up to learn Cocoa, but I think it’s the one that will get you started writing apps. I started teaching Cocoa and Objective-C in 2004, and I have worked with a lot of people who wanted to learn how to write software so that they could get their ideas onto the screen. But there’s a problem. There are two kinds of people who want to learn programming. Those in the first group are wired for the algorithmic mindset; they’re interested in data and the inner workings of things for their own sake. When they see a dog catch a Frisbee, they think of the calculations the dog does to catch it. Programming is a natural extension of this mind- set. My guess is around five percent of the population is actually built this way. The second (much larger) group has ideas for software that they desperately want to make real. They’re often graphic or interaction designers. You probably have ideas about a fantastic Mac, iPhone, or iPad app that you want to create, but you don’t have a million dollars to hire an engineering staff. It’s very likely that you even like pro- gramming and data in addition to several other interests, but you don’t see everything in terms of algorithms. The problem is that most technical books are written by and for people in the first group. That means most of the material is being created for those who need the least help. As a result, a lot of books on programming go unread. In fact, there’s this un- spoken honor given to anyone who actually finishes reading one: “Wow, he must be really motivated.” My problem with this is that there are a lot of people with great ideas in the second group. Many of my favorite Mac and iPhone apps today come from developers without a formal computer science background, most likely because they bring different expe- riences into the mix. I want to encourage more of this. Fortunately, the good folks at O’Reilly agree with me. So here’s the deal. I wanted to write this book because I want to help you learn how to write Mac, iPhone, and iPad apps. I want you to read it so that I get to use whatever software you end up creating. xi
  • 18.
    This book ismade to be accessible to new programmers, but it’s not watered down. You’re learning to use the same things the professionals use. My job is to make sure that each page says something useful. For each paragraph, I’ve asked myself, “Does this help you write your app?” Anything that didn’t meet that standard got cut. But I haven’t sold you short; if there’s something you need to know to be a good Mac pro- grammer, I’ve at least told you about it. However, I haven’t spent time on minutiae that don’t matter for Cocoa. The content of this book is based on Cocoa tutorials I wrote between 2003 and 2009. Many of these were published at my personal site, Theocacao, and some of the longer ones were published at Cocoa Dev Central, a site I didn’t originally create but have run since 2004. I’ve refined the tutorials based on a one-on-one mentoring program that I ran over the same period of time. You get the benefit of all those efforts in a single condensed book. Your job is to go write world-class Mac, iPhone, and iPad apps, and to tell everyone else how great Cocoa is. Let’s get started. Who This Book Is For This book is for people who want to learn to make great Cocoa apps. I don’t assume that you already know how to program, or anything about Objective-C or C. You do need to own an Intel-based Mac running Mac OS X 10.6 Snow Leopard, and you must know how to install software, launch apps, edit and save files, and so on. Essentially, you have to know how to use a Mac. If you know any computer languages at all (even HTML), things will make more sense from the start. If not, you’ll still be able to make it through this book, but you may find some parts challenging. Even though Cocoa makes many common tasks easy, your brain has to adjust to the basic concepts of programming. To be clear, though, this book is not exclusively for novice programmers. Depending on your experience level, you can skip a few of the chapters that are designed for beginners and jump right to the parts that are relevant to your experience. If you already know C but haven’t done object-oriented programming, start with Chapter 1, which will walk you through creating a basic Cocoa application. Then move onto Chapter 4, which introduces object-oriented concepts. If you know C and at least one object-oriented language (such as Java, Ruby, or C++), you can start with Chapter 1 for the basic orientation, and then jump ahead to Chapter 5, which introduces Objective-C. How This Book Is Organized The chapters in this book are organized as follows: xii | Preface
  • 19.
    Chapter 1 To buildCocoa apps, you’ll need to know your way around Xcode. Although we’ll get into Xcode more deeply later, this chapter gives you a quick tour. Chapter 2 Before you can start programming in Objective-C (the native programming lan- guage used with Cocoa), you’ll need a background in programming as well as in the C language. This chapter gets you started with the basics of programming in C. Chapter 3 A programming language spends all its time moving things around in memory. This chapter explains how C manages memory and also explains pointers, which let you work directly with memory locations. Although you won’t need all the low- level memory manipulation that C is capable of, an understanding of it will help you better understand Objective-C. Chapter 4 Here’s where we take a detour from the C language and get into the object-oriented world. In this chapter, you’ll learn about classes, inheritance, objects, and more. Chapter 5 Now that you have a basic understanding of object-oriented concepts, it’s time to move on to Objective-C. This chapter explains Objective-C’s syntax for calling methods, defining classes, and creating objects. Chapter 6 Before you can get into Cocoa, there are a few more things you need to learn about Objective-C. This chapter introduces some intermediate Objective-C concepts, including memory management, categories, selectors, and more. Chapter 7 Although you can (and sometimes will) use standard C types in your Cocoa apps, Objective-C offers a rich set of classes for working with primitive values, such as integers, floating-point numbers, and strings. This chapter shows you how to use these value classes. Chapter 8 Cocoa’s AppKit user interface layer allows you to create applications with rich user interfaces.Thischapterpreparesyoutoworkwiththebuilt-incontrolsandconnect them with actions you define in your code. Chapter 9 Model-View-Controller is the mindset that guides the way you’ll put your Cocoa apps together. In this chapter, you’ll learn how to write code that coordinates your data and user interfaces. Chapter 10 Cocoa includes a rich set of classes for displaying graphics in your apps. In this chapter, you’ll learn how to work with shapes, images, gradients, and more. Preface | xiii
  • 20.
    Chapter 11 Now thatyou’ve read through the book, you’re ready to write some apps. This short chapter gives you a few last pointers to help you on your way. Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter- mined by context. This icon signifies a tip, suggestion, or general note. This icon indicates a warning or caution. Using Code Examples This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Cocoa and Objective-C: Up and Running by Scott Stevenson. Copyright 2010 Scott Stevenson, 978-0-596-80479-4.” xiv | Preface
  • 21.
    If you feelyour use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. Safari® Books Online Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly. Withasubscription,youcanreadanypageandwatchanyvideofromourlibraryonline. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features. O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other pub- lishers, sign up for free at http://my.safaribooksonline.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at: http://www.oreilly.com/catalog/9780596804794/ A full site dedicated to the book is available from the author, and may include additional examples and announcements about Cocoa user groups and other information you may find useful as a developer. This book site is at: http://cocoabook.com To comment or ask technical questions about this book, send email to: bookquestions@oreilly.com You can email the author directly at: cocoahelp@me.com Preface | xv
  • 22.
    For more informationabout our books, conferences, Resource Centers, and the O’Reilly Network, see our website at: http://www.oreilly.com Acknowledgments My education didn’t follow the normal path. I taught myself how to program and learned how to run a business mostly by trial and error. In the end, I think this is the only option that would have worked for me, but it was possible only because of my extremely patient and understanding family: my mom, Peggy; my dad, Alan; and my sister, Jamie. You would not be reading this now if it was not for their support. There are so many people that have helped me in my work life, but there are a few that have had a direct impact on this book. Michael Lopp and Angela Muller were ongoing sources of encouragement and inspi- ration. This book first came into being over lunch when Michael mentioned something along the lines of “everyone wants an animal on the cover of their book,” referring to the iconic O’Reilly covers. By incredible coincidence, Brian from O’Reilly emailed me about two weeks later. Had Michael not made that comment, this might not have happened. I had world-class tech reviewers for this project: Joar Wingfors, Michael Jurewitz, Rob Rhyne, and Tim Triemstra. Joar, who I originally met through the tutorials I posted online, tirelessly reviewed an ever-changing book, provided a wealth of essential com- ments and suggestions, and even helped me fix some bugs in the code. He’s one of the most talented engineers I know, and I am thrilled to have been able to get his help on this. Though he wasn’t involved in this project, I owe a lot to John Mora. He has an ability to look an impossibly large task in the face and just do it, despite the usual doubts about whether you know enough or have enough time. It is one of the most impressive traits I know of, and John has it in spades. Thankfully, I think some of that rubbed off on me over the 15 years I’ve known him. Thanks to Kip Krueger for patiently helping me figure out the low-level details of mem- ory and offering pointers when I was learning C. His mentoring is the reason I’m able to teach these topics to you now. When I first started learning Cocoa, there were only two books out on the topic. I chose Aaron Hillegass’s book Cocoa Programming for Mac OS X (Addison-Wesley). Not only was it the first Mac programming book I read, it was the first technical book I actually enjoyed. His book proved to me that you could write in a direct and personal style and still be taken seriously. Having spent time with him in person, I can also add that he’s a great guy. There’s no doubt that his influence is weaved into the tutorials I’ve written. xvi | Preface
  • 23.
    Brian Jepson issimply a superhero among editors. I’m not sure there’s enough space to list all of the things he did to make sure this project was a success, but I certainly could not have done it without him. For any part of the book that you really like, there’s a good chance he had a hand in it. Follow him on Twitter: @bjepson. Finally, to the thousands of people who have emailed me over the years with questions or suggestions about tutorials, I owe a lot to you as well. You helped me refine every- thing that ended up in this book, and by extension, helped a new generation of Cocoa developers learn how to program. This book is dedicated to Gina and Ilya, who both taught me that life’s too short to not be spent with the people you want to be with. Thank you. Preface | xvii
  • 25.
    CHAPTER 1 Setup andFirst Run I know you want to start writing apps as soon as possible, but there are three things you need to know first: I don’t assume you already know how to program. You don’t need to have existing experience with Objective-C, Cocoa, Xcode, or even C. If you have some familiarity with a computer language (even HTML), it will help you. You do need to be a reasonably proficient Mac user. If you show up with the desire to learn Mac programming, I’ll walk you through what you need to know. The chapters are modular. If you know C and object-oriented concepts, but not Objective-C specifically, you can skip to Chapter 5 after learning about Xcode in this chapter. If you’ve already dabbled in Mac or iPhone programming, and know your way around Objective-C and some basic Cocoa topics, you can probably jump to Chapter 7. Otherwise, start right here. You need a Mac running Snow Leopard. All of the chapters assume that you’re running Mac OS X 10.6 Snow Leopard, which runs only on Intel-based Macs. All set? Good, let’s get Xcode running. Download and Install Xcode You can either get Xcode from the Mac OS X install DVD or download it from the official Mac Dev Center website. The version on the website will always be the newest one, but the download may take several hours. If you want to get started right away, you can install from the DVD. 1
  • 26.
    If you’re runningSnow Leopard and already have the iPhone SDK in- stalled, you have everything you need to write Mac apps. You can skip ahead to “Your First Application” on page 4. To download the newest version of Xcode, go to http://developer.apple.com and click on Mac Dev Center. The layout of the site changes regularly, but you should look for a link that says “Register” to create an account. There is a paid membership that offers access to prerelease software and training videos, but you can start with the free mem- bership,whichrequiresyouonlytofilloutsomebasiccontactinformation.Afteryou’ve registered, return to http://developer.apple.com and log in. Once you’re logged in, look for a link for downloading Xcode. If you have a slow Internet connection and want to save yourself a few hours, put the Snow Leopard Install DVD in the drive and open the folder called Optional Installs as shown in Figure 1-1. Figure 1-1. The Optional Installs folder on the Snow Leopard Install DVD Inside the Optional Installs folder is a package called Xcode.mpkg. Double-click it to open the installer (see Figure 1-2). 2 | Chapter 1: Setup and First Run
  • 27.
    The version ofXcode on the DVD is usually older than what is available on the developer site, so you should upgrade Xcode as soon as you have the time to download it. The Xcode download at the Mac Dev Center willshowyoutheversionnumberthat’savailable.WhenyourunXcode, the version number is displayed on the Welcome window below “Wel- come to Xcode.” Once the installer is running, you can just accept all of the default options. You will likely need several gigabytes free for installation. Figure 1-3 shows the installer running. Figure 1-3. An Xcode install in progress Figure 1-2. The Xcode.mpkg package inside the Optional Installs folder Download and Install Xcode | 3
  • 28.
    Once the windowsays installation is complete (see Figure 1-4), go ahead and close the window. Figure 1-4. The installer window confirming that Xcode was installed Your First Application Launch Xcode. You can find it by clicking on your hard drive icon in the Finder sidebar and navigating to Developer → Applications. This is separate from the general Applications folder that holds things like Safari and iTunes. You can also search for it using Spotlight. It’s probably a good idea to add Xcode to your Dock since it’s a few levels down. In theory, this is for easy access, but it’s also a good con- versation starter if someone sees it on your Mac. If Xcode asks you for any initial configuration preferences, simply accept the defaults. Each time Xcode runs you will see a Welcome window that looks something like Figure 1-5. 4 | Chapter 1: Setup and First Run
  • 29.
    The left sideof the window has a few items to help you get started, and the right side lists projects that you’ve used recently. The list will be empty the first time you run Xcode. Click on “Create a new Xcode project” to get started. If you closed the Welcome window, you can start a new project by choosing File → New Project from the menu. You can open the Welcome window again by choosing Help → Welcome to Xcode. In the New Project window, click on Application under the Mac OS X section and select the Cocoa Application icon as shown in Figure 1-6. Click the Choose button, and you’ll be asked to select a location for the project. Go to your home folder and create a folder called CocoaBook (you can do this within the Save dialog). Select the CocoaBook folder as the save location and enter “TextEditNano” as the project name (see Figure 1-7). The layout of the New Project window has changed significantly in the 3.x releases of Xcode. If your window doesn’t look similar to the screen- shot in Figure 1-6, download a newer version of Xcode from http://de veloper.apple.com. Figure 1-5. The Xcode Welcome window after the first launch Your First Application | 5
  • 30.
    After you clickSave, you’ll see the main Xcode window come up, which looks like Figure 1-8. Go ahead and click the Build and Run icon in the toolbar to try the app out. You should see a blank window come up, as shown in Figure 1-9. This obviously isn’t a useful window, but if it shows up, you know Xcode is working and you’re ready to start writing Mac apps. Close the application and return to the main Xcode window. To close an app that’s running inside of Xcode, you can either choose Quit from the application’s menu, or just click the Tasks stop sign toolbar icon in Xcode, which is shown in Figure 1-10. It’s called Tasks because you may have several things going on in Xcode, and if you click and hold on this icon, you can select which task you want to stop. If your application crashes or stops responding, you won’t be able to use Quit from the application menu. If that happens, just use the Tasks toolbar item. This is equivalent to a Force Quit, so the application won’t have a chance to save any data or preferences before closing. Figure 1-6. The New Project window in Xcode 6 | Chapter 1: Setup and First Run
  • 31.
    Create the Interface Atthe heart of every great Mac app is a great user interface. You might design the interface in an image editing program, on a napkin, or just in your head, but eventually you’ll want to make it real. In Cocoa, there are two ways to create a user interface. You can manually enter configuration details for controls in your application code (you’ll learn more about writing code in the next chapter), or you can visually arrange controls in Interface Builder. In my experience, novice programmers usually jump at the chance to work visually, but experienced developers sometimes take a bit more convincing. Some new programmers think that writing software the hard way makes you a better programmer, but expert Mac developers measure success by how quickly they can deliver great results. Interface Builder is not training wheels for Cocoa; it’s a tool to reduce the amount of “busy work” you have to do when setting up your user interface (UI), which means you can work more quickly and avoid trivial errors. That leaves you free to focus on the real work. Figure 1-7. Create a CocoaBook folder for your projects, and name the project “TextEditNano” Your First Application | 7
  • 32.
    Eliminating busy workis the most important idea in Cocoa. A pro- grammer who doesn’t need to waste time on tedious tasks is free to focus on creating features that make her app unique. Xcode includes an Interface Builder document with each new project, but as you’ve seen from the blank window, there’s not much to it. In the main Xcode window, click the disclosure triangle to the left of the blue TextEditNano project icon in the sidebar to display its contents. Now open the Resources group and double-click the MainMenu.xib file to open it in Interface Builder. You’ll see a window that looks some- thing like Figure 1-11. Double-click the Window icon (circled) to open the main window for the TextEdit- Nano application. It should look exactly like the blank window you saw when you first ran the application. This window is your canvas. You can add any UI elements here that you want to use in your application. Interface Builder works differently than some other visual development tools. It doesn’t generate Objective-C code. Instead, it takes snapshots of the state of the objects. The configuration of all of the controls, including all of their positioning information, is saved in the MainMenu.xib file and loaded by Cocoa when your app is launched. Figure 1-8. The Xcode main window showing the TextEditNano project 8 | Chapter 1: Setup and First Run
  • 33.
    The .xib fileformat is an XML version of the standard .nib format that was Interface Builder’s native format in earlier versions of Mac OS X. The XML version is easier to use in version control systems, but when Xcode builds your app, it actually converts XIB files into NIB files. The original XIB file is preserved, though. Open Interface Builder’s Library window by choosing Tools → Library from the menu. The Library window contains ready-to-use UI elements that are built into Cocoa. You can also download third-party plug-ins or create your own. Type “text view” into the search field at the bottom of the window to bring up the Text View item, as shown in Figure 1-12. Figure 1-9. The blank window you see the first time you run TextEditNano Figure 1-10. The Tasks button in the Xcode toolbar Your First Application | 9
  • 34.
    If nothing showsup when you search for the text view, make sure that the Objects tab is selected at the top of the window, and the Library item is selected in the drop-down menu below it. Drag the Text View item from the Library window into the application window. This might be obvious, but you need to drag it to your “prototype” application window that appeared when you double-clicked on Window in Interface Builder (Figure 1-13), not the real one from the running application (which you hopefully already closed). Move the text view so that it’s near the top-left edge of the window. Use the handles around the outside to resize it so it nearly fills the window, but leave a little bit of space at the bottom. The exact size isn’t important—just do whatever you think looks right. Select File → Simulate Interface from the menu, or press Command-R. This will display the window in Interface Builder’s simulator test mode. The application isn’t actually running, but you can see a preview of what it will look like and can even type in the text field. If you try to resize the window, though, you can see that the text view doesn’t resize with it. Press Command-Q to close the simulator, and we’ll fix this. Set sizing properties Select the text view by clicking on it in the prototype window, and choose Tools → Size Inspector from the menu, or press Command-3. The Inspector window’s title is “Scroll View Size,” but that’s OK (you may have expected it to be named “Text View Size”). The scroll view is wrapped around the text view to provide scrolling support for long runs of text. Figure 1-11. The MainMenu.xib file for TextEditNano 10 | Chapter 1: Setup and First Run
  • 35.
    The Autosizing sectionof the Inspector controls resizing. The outer anchors control which edges the view moves with, and the inner arrows control which edges the view resizes with. That may not make sense when you read it, but fortunately the Inspector window shows you a live preview as you make changes. You can turn each anchor on or off by clicking it. Click both sets of internal arrows so the view resizes with the window. It should look Figure 1-14 when you’re done. Run the test mode again by pressing Command-R. If you resize the window, the text view should now resize with it. Press Command-Q to close the simulator, then Com- mand-S to save the MainMenu.xib file. Switch back to Xcode. Run the Finished Application Back in Xcode, click the Build and Run icon in the toolbar (or just press Command-R) to build the application and run it. This time when the window comes up, you should see the text view you added. Choose Format → Font → Show Fonts to choose a font, then type something in the text field (see Figure 1-15). Figure 1-12. Search for “text view” in the Library window Your First Application | 11
  • 36.
    Even though youhaven’t written a single line of code yet, you already have a real Cocoa application. It can’t save files, but it uses Cocoa’s built-in text view so you can use fonts, colors (Shift-Command-C), international text, and spellchecking. It also supports drag- and-drop, text search (try Command-F), and many other features. Figure 1-13. Drag the text view icon into the prototype window Figure 1-14. Click both sets of arrows to enable resizing 12 | Chapter 1: Setup and First Run
  • 37.
    Figure 1-15. Cocoahas built-in support for advanced text effects You can also create PDFs from the text and even print. Choose File → Print to bring up the standard print dialog, and click Preview to convert the text into a PDF as shown in Figure 1-16. The document can use features like any other PDF, including text selection, searching, and annotation. Remember, this is your application that you just made from scratch. Your First Application | 13
  • 38.
    Figure 1-16. BasicPDF generation and printing is built in 14 | Chapter 1: Setup and First Run
  • 39.
    CHAPTER 2 Thinking inCode: Basic C As a Cocoa programmer, your job is to get your ideas onto the screen. When you write an essay, you use sentences and paragraphs. Writing software works the same way, though you write lines of code instead. Each line performs a task, such as opening a file or displaying an image. When you put enough of these lines of code together, you eventually have an application. You write these instructions using a programming language. Most Mac and iPhone apps are written in Objective-C, so that’s what you’ll use in this book. The process of converting your ideas into code is called, literally, writing code, and the result is source code. For example, to make your application play the alert sound, you write this line of code: NSBeep(); There’s one important detail, though. Objective-C is based on a simpler language, called C. In fact, Objective-C isn’t just based on C; it’s all of C plus some other stuff. Programmers like to say it’s a strict superset of C. So before you start writing Cocoa apps, it helps to learn some C. I’m not going to lead you into the outer limits of the language; you’ll see just enough to get started. If you already know C, you can safely skim this chapter. If this seems confusing, just remember that Objective-C is the language that defines how you format your code—the grammar. Cocoa defines what you can make your code do—the overall vocabulary. You create a Cocoa app by writing code in the Objective-C language. How Code Works Mac OS X contains special folders for programmers called frameworks. A framework helps you do things like animate graphics, display web pages, and create PDFs. These 15
  • 40.
    aren’t just forthird-party developers; the built-in applications use them too. Applica- tions can also include their own custom frameworks that aren’t provided by Mac OS X. You might be used to thinking of Cocoa as a single tool for building Mac apps. In reality, it’s the foundation for many different frameworks—an entire ecosystem. In fact, there are more than 90 frameworks in Snow Leopard, and some of those contain subframeworks. Each one is designed to help you do something different. For example, the Core Video framework helps you write an application that can apply real-time special effects to video. A single Mac application may use many different frameworks, though almost all inherit basic infrastructure from Cocoa. The frameworks built into Mac OS X are in /System/Library/ Frameworks (Figure 2-1). Developers can also create their own frame- works and install them in /Library/Frameworks. Feel free to look around in there, even if you don’t know what the frameworks do yet. Figure 2-1. The contents of /System/Library/Frameworks on Snow Leopard 16 | Chapter 2: Thinking in Code: Basic C
  • 41.
    When you writea line of Objective-C code, you are usually asking a framework to do something for you. For example, these lines of code download an image from a website and save it as a TIFF file on my desktop: id url = [NSURL URLWithString:@"http://cocoabook.com/test.png"]; id image = [[NSImage alloc] initWithContentsOfURL:url]; id tiff = [image TIFFRepresentation]; [tiff writeToFile:@"/Users/scott/test.tiff" atomically:YES]; If you’ve never written code before, this probably all looks pretty strange. It’s a lot like when you see algebra or a foreign language for the first time. Even though it’s new, there is a consistent structure that you can learn. Here’s what Cocoa does for you when you write and run the example lines of code: 1. Finds the IP address for the host cocoabook.com 2. Establishes an HTTP connection to the server at that IP address 3. Creates an image to hold the data 4. Downloads the data, bit by bit, and places it in memory 5. Saves the image data to a TIFF image file on the local disk Incredibly, you don’t need to know the HTTP protocol, how to resolve IP addresses, or how to create a TCP connection. Frameworks are designed to abstract these kinds of details from you so that you can focus on what makes your app unique. As Cocoa and other frameworks are improved with each new version of Mac OS X and iPhone OS, your app will often pick up new features without any additional work. So making Mac apps is really about writing code that uses frameworks. You type spe- cific instructions into a file in Xcode, then click Build and Run to try them out. When you do this, Xcode compiles your code into an application, which can be double-clicked on a Mac, tapped on an iPhone’s home screen, or even run from the command line in Mac OS X’s Terminal application. In a sense, the lines of code you write are the “raw materials” of your application. Xcode then acts as an assembly line, compiling your code into the final product. Compilation is a fairly complex process, but Xcode handles the basic cases with very little effort on your part. How to Format Code Xcode and Cocoa do a lot of work for you, but you have to do your part by writing accurate code. If we stay with the theme of you supplying raw materials and Xcode assembling them, you have to be sure the materials are “built to spec.” In other words, you need to write code that Xcode can understand. How to Format Code | 17
  • 42.
    Appropriately, when Xcodeprocesses your code it generates something called assembly code. This is harder for humans to read, but perfect for computers. You can see this by opening a source code file and choosing Build → Show Assembly from the menu. Some programming languages have very complex formatting rules, but C and Objective-C are pretty simple. That doesn’t mean they’re always easy to use, just that they have fewer grammar rules than many other languages. We’ll start with something basic. Let’s say you have some driving instructions: 1. Enter I-280 South. 2. Exit at the De Anza ramp. 3. Make a U-turn at Mariani Avenue. 4. Turn right into Infinite Loop. Anybody who knows English can read these steps, but I can’t compile them. I’ll convert them to code: enterFreeway ( "I-280 South" ); exitFreewayAtRamp ( "De Anza" ); performUTurnAtStreet ( "Mariani Ave" ); turnRightAtStreet ( "1 Infinite Loop" ); This program won’t actually run, because it assumes four hypothetical actions that aren’t supported by any framework you’re likely to find on a Mac or iPhone. Written languages are flexible. Even if you misspell a word or structure a sentence strangely, the reader usually knows what you mean. For example, a person knows that “Mariani Ave” and “Mariani Avenue” are the same, but programming languages are usually more strict. When Xcode compiles your code, it can’t make conceptual leaps about what your intentions are. Word spacing is another key difference. In English, each word is separated by a space or hyphen, but many programming languages combine several words into one big noun or verb, such as mailboxSearchField. There’s a consistent pattern to the code: an action, sometimes followed by additional details. Here’s the first line of that code again: enterFreeway ( "I-280 South" ); The line starts with enterFreeway, which is the name of an action. These actions are called functions. The second part of the line describes which freeway to enter: I-280 South. The technical term for this is an argument or parameter, but I think those are pretty awkward terms. You can just think of it as an input value. 18 | Chapter 2: Thinking in Code: Basic C
  • 43.
    Each instruction endswith a semicolon. In C, a semicolon is like a period at the end of a sentence. Just like sentences, a single instruction can span multiple lines, but almost all instructions end with a semicolon. The compiler converts source code into working programs. When you click Build in the toolbar, Xcode uses the compiler to do a lot of the low- level work. Besides abstracting a lot of these tedious details, Xcode also packages up the program as a proper Mac app. If you write a line of Xcode that isn’t correct, Xcode will display an error when you try to build. You won’t be able to run your app until you fix the error. These kinds of mistakes are known as build errors (Figure 2-2). Figure 2-2. A build error in Xcode Even the best programmers make mistakes like this every day, but many are easy to fix. You’ll learn more about this as you use Xcode to build applications. One thing that C is flexible about is how you use whitespace. All of the lines in the following example will produce exactly the same result: enterFreeway ( "I-280 South" ); enterFreeway ( "I-280 South" ); enterFreeway("I-280 South"); How to Format Code | 19
  • 44.
    Programmers use whitespaceto make the intentions of their code more clear, though there are a lot of different opinions on what “clear code” is. You can usually use what- ever style works best for you. Teams of programmers usually try to agree on a style that everyone in the group uses, though there is always room for flexibility in how you format your code. Instead of listing every single C formatting rule here, I’m going to move on to more practical concepts and show you these rules by example. If you ever have trouble typing in a sample correctly, you can download a working version from the book’s companion website (see the Preface for information on obtaining the sample code). Variables A variable is a container for a piece of data, such as a block of text, an image, or a web page. You give each variable a name so you can refer to it in code. Like formatting, there are different conventions for naming variables. When writing Mac software, you should try to use the same conventions that Cocoa itself uses. Cocoa is designed to make very large projects manageable, and encour- ages you to write code that’s easy to understand. Some applications are made up of hundreds of thousands or millions of lines of code. Using consistent, clear naming conventions makes it easier for many pro- grammers to collaborate on a project. Giving names to things with varying definitions makes them easier to refer to: you see a movie, eat a meal, drive down a street. It’s just easier to say “breakfast” than “that thing we did yesterday where we ate bacon and eggs.” You can share information be- tween different parts of an application using variable names instead of the data they contain. Let’s start with a simple line of code: emailMessageToFriend ( "Hi there!", "test@example.com" ); This seems reasonable. I call the function emailMessageToFriend(), with one input item for the message and another for the email address. But what if I want to send a different message, or send the message to a different person? I’d need to change the code, re- compile it, and rerun it. Clearly, this won’t work. Variables make it possible to write one piece of code for many different situations by using a name as a placeholder for the real data. Here’s what the previous line of code looks like if I use variables instead: message = "Hi there"; address = "test@example.com"; emailMessageToFriend ( message, address ); 20 | Chapter 2: Thinking in Code: Basic C
  • 45.
    I can usethe variables message and address to refer to the email contents and recipient without having to know what they will be ahead of time. I can also make the code more useful by reusing the message variable as-is, but changing the address variable to send the same email to other people: message = "Welcome to Cupertino!"; address = "gina@example.com"; emailMessageToFriend ( message, address ); address = "fred@example.com"; emailMessageToFriend ( message, address ); address = "sarah@example.com"; emailMessageToFriend ( message, address ); If I ever want to change the welcome message, I have to update it in only one place instead of three. In a real program, I would make a window that allows the user to select whom they want to send messages to, ideally using the Mac OS X Ad- dress Book database to choose from a list of existing contacts. Types In C, variables have a type, which describes what kind of data the variable contains. C has a handful of built-in types for common things like numbers and text, but you can also create your own. There are two steps to using a variable in C: declare it, then assign a value to it. You can change the value of a variable as many times as you want, which is actually what the term “variable” means. Here’s an example of declaring a variable and assigning it a value in one step: int milesPerGallon = 35; This code creates a new int variable with the name milesPerGallon, and assigns it an initial value of 35. On a Mac running Snow Leopard, this variable can store any whole integer up to 2,147,483,647.* No, you don’t need to memorize this. For floating-point numbers (numbers with decimal points), C has a float type. Here’s an example: float exchangeRate = 1.618; The milesPerGallon and exchangeRate variables have different types, but they do the same thing: store a value. You can also declare a variable and assign it a value in separate steps: * You can see the actual definition for the maximum value in /usr/include/i386/limits.h. Just look for INT_MAX. Variables | 21
  • 46.
    int milesPerGallon; float exchangeRate; milesPerGallon= 35; exchangeRate = 1.618; Here’s an example of declaring a variable once, assigning it a value, then reassigning it a new value several times: int milesPerGallon; milesPerGallon = 35; milesPerGallon = 27; milesPerGallon = 81; float exchangeRate; exchangeRate = 1.120; exchangeRate = 1.114; exchangeRate = 1.618; If you try to assign the wrong type of data to a variable, C will usually try to do some conversion, but you may lose information in the process. For example, if you try to assign the value 24.5 to milesPerGallon, it will be stored as 24 because int variables only store whole numbers. Some conversions are not possible, and Xcode will warn you about these when you compile your application (when Xcode wants to show you warningsorerrormessages,itcallsyourattentiontotheminthestatusbaratthebottom of the window). Some successful conversions will give a different result than you expect. Most of the time, assigning an int value to a float variable does what you expect. However, if you divide one integer value by another integer value, you’ll always get a integer result, even if you assign the result to a float: int miles = 366; int gallons = 8; float milesPerGallon = miles / gallons; The milesPerGallon variable will contain the value 45 instead of 45.75. You can use the cast operation (specify the name of the desired type in parentheses) to force a specific type conversion. This example converts both miles and gallons to float values before it performs the division: float milesPerGallon = (float) miles / (float) gallons; Technically, you don’t need to cast both values, because the compiler is smart enough to treat both as float values if you cast at least one of them: float milesPerGallon = (float) miles / gallons; Table 2-1 contains a list of some of the most common “primitive” types used in C. 22 | Chapter 2: Thinking in Code: Basic C
  • 47.
    Table 2-1. BasicC data types Type Description Examples int Integer numbers, including negatives 0, 78, –1400 unsigned int Integer numbers (no negatives) 0, 46, 900 float Floating-point decimal numbers, including negatives 0.0, 1.618, –1.4 char Single text character or symbol a, D, ? In addition to the types listed in the table, there’s also a type called double, which is a version of float that can hold larger decimal point numbers, and long, which is a larger version of int. Cocoa has special variable types that automatically adapt to different sizes as necessary, which you’ll learn about in Chapter 7. I’ll also show you how to make your own types in Chapter 3. Constants In computer programming, constants are variables that can’t be modified once you’ve assigned a value to them. C has a keyword const that behaves like a constant most of the time. For example, the compiler won’t let you change the value of an int that you’ve declared as const: int currentSpeed = 55; currentSpeed = 65; const int maximumSpeed = 75; maximumSpeed = 80; If you try to compile this, you’ll get the error: assignment of read-only variable. Changing currentSpeed is fine, but trying to change the constant maximumSpeed won’t work. Constants are a way to prevent your code from accidentally changing important variables. Another way to define a constant in C and Objective-C is to use #define, which is a preprocessor directive. By convention, these are usually in all capital letters: #define MAX_MPG 120 if (milesPerGallon > MAX_MPG) { errorMessage = "You appear to have a nuclear-powered car."; } The preprocessor is a tool that runs behind the scenes when you compile an application. It does a number of different things, such as handling #include statements, but also does a search and replace on placeholders you’ve specified with #define. So the #define directive doesn’t create real variables; it just replaces one string of text with another before the compiler gets its hands on the code. Here’s what the preceding example looks like by the time it’s handed off to the compiler: if (milesPerGallon > 120) { errorMessage = "You appear to have a nuclear-powered car."; } Variables | 23
  • 48.
    In general, #defineis common in pure C programs, but it’s not considered such great style in Cocoa apps. It’s not outright wrong, just considered a bit clumsy or inelegant. Myexperienceisthatconst isgenerallybetter forObjective-C, especially becauseXcode can do a better job with helping you write code if you use real variables. Enumerated Types If you have a group of related values (such as days of the week), you can use C’s enum keyword to create a group of constant values that you can use in your programs. These enumerations are integer types, and the values can be used wherever you would use an integer: enum { monday, tuesday, wednesday, thursday, friday, saturday, sunday }; int day = saturday; Typedefs C lets you define your own types with the typedef statement. You can use this to create aliases to some of the basic types in C, which lets you write code that’s somewhat self-documenting: typedef int Distance; Distance home_to_office = 30; Distance office_to_cafe = 3; What’s more, you can combine typedef and enum to create your own type that can only be assigned one of the values listed in the enum. Doing so eliminates the need to define the day variable shown earlier as an int, and makes for a more self-documenting program: typedef enum { monday, tuesday, wednesday, thursday, friday, saturday, sunday } DayOfWeek; DayOfWeek day = saturday; Functions The previous example programs were just flat lists of instructions. That’s fine for very simple cases, but you need some sort of structure to manage all of the code in a real application. A function is a way to group multiple instructions together so they can be used with a single line of code. When someone asks you what you did today, you might say something like “I went to the grocery.” You probably don’t say “I opened the door, walked outside, closed the door, locked it, walked to the car, opened the car door...” because that level of detail 24 | Chapter 2: Thinking in Code: Basic C
  • 49.
    isn’t relevant tothe conversation. Once somebody understands what the phrase “I went to the grocery store” means, they know that it contains a sensible series of steps. Let’s see how that might look as a list of steps first: Buy Groceries Open front door Walk out front door Close front door Lock front door Walk to car Open car door Enter car Close car door I know this seems like a ridiculous level of detail, but this is how a computer program- mer thinks. In general, software cannot make conceptual leaps. You need to spell out exactly how the application should work. For example, if I wrote out the exact steps to display a PNG image on screen, they would probably look like this: Display Image Save file path as a variable Make sure the path to the file is valid Make sure the file at the path is a PNG image Reserve memory for an image Read data from the file, one byte at a time When all data is read in, close the file Open a new window to display the image Draw the contents of the image into the window ThegoodnewsisthatframeworkslikeCocoahavealreadydonealotofthegroundwork for you. Cocoa has defined what many of these “lists of tasks” are, and they’re ready for you to use. That’s what allows you to place an image in a window without knowing details like the refresh rate of the user’s display. Now let’s go back and translate the “Buy Groceries” steps into something that looks more like C code. I’ll create a function called buyGroceries() that itself calls a series of other functions: void buyGroceries() { openFrontDoor(); walkOutFrontDoor(); closeFrontDoor(); lockFrontDoor(); walkToCar(); openCarDoor(); enterCar(); Functions | 25
  • 50.
    closeCarDoor(); } There are afew things that may look new here, but you can probably still get the gist of what’s going on. My buyGroceries() function is calling other functions like openFrontDoor() and walkOutFrontDoor(). This pattern of functions calling other func- tions is the essence of structured programming. Let’s take a look at the first line again: void buyGroceries() { There are three things to notice here: The word void is the return type for the function. The return type could also be int, float, char, or any other C type. The value a function returns is called a result. When a function doesn’t return anything, the return type is void. Yes, it’s a slightly strange convention, but this is just one of the delightful quirks of C. The function name is followed by a pair of parentheses: buyGroceries(). Programmers usually call the { symbol a “curly brace.” All of the instructions in a function must be inside of a pair of curly braces. It’s easy to forget to add a curly brace to the end of the function. So check this first if Xcode shows you an error when compiling your app. Let’s look at a few actual functions with return values: int numberOfPeople () { return 3; } float dollarsAndCents () { return 10.33; } We’re using all of the same conventions here as in the previous example. In fact, the only difference is now we’re using the return statement, which sends a result back to the caller and ends the function. There’s a subtle point here. The return statement returns a result to the caller, but it will also immediately end the function. If you have any code after the return statement, that code will not run. When you call a function, you can capture the result in variable of the same type. Here are some examples: int count; count = numberOfPeople(); float totalCost; totalCost = dollarsAndCents(); 26 | Chapter 2: Thinking in Code: Basic C
  • 51.
    Another Random ScribdDocument with Unrelated Content
  • 52.
    ST. BOTOLPH, BISHOPSGATE Thischurch escaped the Great Fire of 1666, but was rebuilt in 1725-29 by James Gold. In 1615 the City gave the parishioners additional ground on the west for burial purposes. The earliest date of an incumbent is 1323. The patronage of the church has always been in the hands of the bishops of London since 1323. Houseling people in 1548 were 650. The building includes two aisles, separated from the main body by composite columns. There are galleries on the north, south, and west. The steeple rises at the east end, and the chancel, therefore, is formed beneath the tower. It is built of stone and consists of three stories, the third of which is completed by a small composite temple surrounded by a balustrade and surmounted by an urn. The remainder of the exterior is of red brick with stone dressings. Pictorial Agency. ST. BOTOLPH, BISHOPSGATE Sir Paul Pindar, a great benefactor to the church, who acted as James I.’s Turkish Ambassador in 1611, was buried in this church, and a monument was erected to his memory. Close to this, also in the chancel, is a brass plate in memory
  • 53.
    of Sir WilliamBlizard, President of the Royal College of Surgeons, who died in 1835. John Keats was baptized here in 1795, and Edward Alleyn, founder of Dulwich College, in 1566. Here also Archibald Campbell, 7th Earl of Argyll and father of the celebrated first marquis, was married in 1609. There were a considerable number of small charitable gifts belonging to this parish. Of the larger, Ralph Pindar was a donor of £60; Nicholas Reive, of £406 : 5s. in 1626; William, Earl of Devonshire, of £100. There was one charity school for twenty-five boys and twenty-five girls, who were taught and made apprentices by subscription and legacies. Also almshouses in Lamb’s Court for the poor of the parish, maintained by Dulwich College, and three almshouses by the pesthouse for three poor widows, the gift of Lady Lumley. Some of the notable rectors were: Alfred Earle, Bishop of Marlborough, in 1888; Charles James Blomfield (1786-1857), Bishop of Chester; John Lake (1624- 89), Bishop of Chichester. On the site of Spital Square, Bishopsgate Street Without, stood the ancient house called St. Mary Spital, for an account of which see Mediæval London, vol. ii. p. 322. Bishopsgate Street Without is a curious mixture of old houses, some with grotesque features, and modern buildings presenting only a strip of much- ornamented stone or brick frontage. After the Great Eastern Hotel on the west, the frontage of the station presents a very long row of uniform buildings in new red brick with stone dressings and ornamental gable ends. The famous old house named Paul Pindar’s was pulled down to make way for these. Paul Pindar (b. 1565) was the son of Ralph Pindar, alderman’s deputy for the ward of Bishopsgate. At sixteen he was apprenticed to one Parvish, an Italian merchant who sent him to Venice as his factor, and he stayed there many years. In 1615 he was sent to Turkey as Ambassador by request of the Turkey Company, and he remained there for nine years. He returned in 1623, and was knighted. The King offered him also the Lieutenancy of the Tower, which he declined. Charles thereupon made him Farmer of Customs. In 1639 he possessed £236,000, out of which he gave large sums to the King. He died August 22, 1650. The row of houses that now stand on the site of his house have fairly good shops on the ground-floors, and there are one or two archway entrances into the station premises near the north end. The Black Raven public- house is one of these. Acorn Street, Skinner Street, and Primrose Street need very little comment. They are chiefly composed of the sides of houses fronting Bishopsgate, and some ordinary modern brick buildings. Nos. 131-2-3 are old plaster houses, and No. 120, beyond Acorn Street, has a projecting bay window carried up two stories. This is also an old house. These are all on the west side. On the east, beginning again from the south end, the first building to attract attention is the Metropolitan Fire Brigade Station, erected 1885. It is an improvement on the monstrosities continually perpetrated in the name of the Fire Brigade. The Bishopsgate Institute is near Brushfield Street. It fronts
  • 54.
    Bishopsgate with anelaborate yellow terra-cotta façade, and has an open entry. The entrance to the Bishopsgate Chapel is under an old stuccoed house, and the chapel itself is a large stuccoed building. Beyond this, after a Great Northern Receiving Office, are some very old houses, plastered with rough stucco in imitation of stone. These are Nos. 82 to 84. One of them has wooden rusticated work from above the first story to the top of the gable end. The date 1590 is stated to have been visible on one of them within the memory of man. On the corner house of Spital Street is a tablet noting the point of the City Bounds. This was placed here in 1846.
  • 55.
    GROUP V We comenext to those streets which run north and south of Thames Street. The area is bounded on the north by Ludgate Hill, St. Paul’s Churchyard, Cannon Street, and Fenchurch Street; on the south by the Thames; on the east by Tower Hill and the site of London Wall; and on the west by the bed of the Fleet River, now New Bridge Street. For the sake of convenience we will begin at the west end. The wall of the City originally crossed Ludgate Hill at the gate, and ran down nearly in a straight line to the river. The Castle or Tower of Montfichet was in the middle of this piece of wall, and Baynard’s Castle was at the south end of it. The Tower of Montfichet passed into the Fitzwalter family, who also owned the soke beside it. Now, when the first enmity broke out between John and Fitzwalter, all the castles and houses of the latter were dismantled and destroyed by the King’s command. In 1276 the Dominicans begged permission to occupy a piece of ground lying between the wall and the river Fleet. Lord Fitzwalter gave the Friars the site of Castle Baynard and of Montfichet. They also obtained permission to pull down the town wall at this place, and to rebuild it farther west, so as to include their ground. Here the Black Friars settled and built great buildings, and claimed the right of sanctuary. Westward of the Black Friars was the house of the Carmelites, called the White Friars. They claimed right of sanctuary also, a right which descended to a haunt of rogues, called Alsatia, an account of which may be read in The Fortunes of Nigel: “The ancient sanctuary at Whitefriars lay considerably lower than the elevated terraces and gardens of the Temple, and was therefore generally involved in the fogs and damps of the Thames. The brick buildings by which it was occupied crowded closely on each other.... The wailing of children, the scolding of their mothers, the miserable exhibition of ragged linens hung from the windows to dry, spoke the wants and distresses of the wretched inhabitants; while the sounds of complaint were mocked and overwhelmed in the riotous shouts, oaths, profane songs, and boisterous laughter that issued from the alehouses and taverns, which, as the signs indicated, were equal in number to all the other houses.” Where is now Bridge Street was formerly the Fleet River, and on its western bank was Bridewell Palace, a palace where the Norman kings held Court. The old palace, burnt down in the Great Fire, was built round two courtyards; in its later days rebuilt, it followed the frequent fate of such ancient monuments, and became partly a “hospital” for poor boys, partly a prison for vagrants and other
  • 56.
    unwanted persons. Itwas also a hospital for lunatics, and was put under the same management as Bethlehem in 1557. Bridewell is also fully described in London in the Eighteenth Century. The part of London bounded north and south by Fleet Street and the River, east and west by New Bridge Street and the Temple, is now almost entirely occupied by mammoth printing-offices; yet on the Embankment are one or two buildings of note: Sion College, opened here in 1886 to supersede the old building on London Wall; the Guildhall School of Music; the City of London School for Girls (all modern). After Blackfriars Bridge, running behind the line of wharves and warehouses, begins Thames Street, Upper and Lower, once one of the principal thoroughfares in London, a London that knew nothing of what is now called the “West End.” It is now a noisy street “pestered” with drays and vans, with cranes and their accompaniments, so that to walk therein in work-hours is a perilous proceeding. Yet this ancient street, Thames Street, is, not even excepting West Chepe, the most interesting and the most venerable of all the streets of London. It is the seat of the export and the import trade. From Thames Street the City sent abroad the products of the country—the iron, the wool, the skins and hides; from Thames Street the City distributed the imports to the various parts of the country. Off the wharves of Thames Street lay the shops of all the nations of Western Europe. In the narrow lanes leading down to the stairs between the quays lived the seafaring folk and those who worked for them, and those who worked for the merchants. London at one time was roughly divided into belts of population. The first belt is that of the Service. It consists of the foreshore between Thames Street and the river, with the lanes and houses upon it. The second is that of the Merchants, between Thames Street and the Markets of West and East Chepe. The third is that of the Markets. The fourth that of the Industries between the Markets and the Wall. As to the first: The Wall of London, when it was first erected, was carried along the river from the south-west angle to the Walbrook. Beyond the Walbrook the south wall of the Roman fortress formed a river-wall, which was continued as far as the south-east angle. Beyond that stream the south wall of the Roman fort was allowed to remain as the river-side wall of the City, when all the rest of the Roman buildings, temples, public edifices, tombs, and villas were ruthlessly pulled down to build the wall towards the end of the fourth century. Now, the wall between the south-west angle and the Walbrook ran along the middle of Thames Street. At the time of its construction there were, therefore, no buildings between the wall and the river. It was built about the middle of the bank, which sloped to the river below, with a narrow stretch of mud at low tide; and above it rose on the hill which still exists, to the higher ground on which the City stood. The breadth of the foreshore varied, but, of course, it was not very great. The first break in the wall was that which allowed for the waters of the Walbrook. Here
  • 57.
    there was thefirst port—the Roman port. It may have been the only port, unless, in their haste to complete the wall, which was undoubtedly built under the pressure of panic, the builders deliberately excluded other ports. In that case there may have been many, for nothing was easier than to make a small port, such as the two which still remain of Billingsgate and Queenhithe. A small square space was dug in the mud and shingle of the foreshore. It was maintained by piles placed close together along the three sides of the square, leaving the fourth side open for the ships. Other piles furnished support for wharves and quays. It is therefore quite possible that there may have been other such ports. Puddle Dock may have been one. In the absence of any evidence which might lead one even to form a conjecture, we may believe that Queenhithe, originally Edred’s hithe, was of later, or Saxon, construction; while Billingsgate, close to London Bridge and Bridge Gate, was probably still earlier. What happened, therefore, was this: On the increase of trade, when London was again settled in the sixth century, wharves and quays began to be pushed out on piles upon the foreshore of Billingsgate and Walbrook, or afterwards at other places, when a break in the wall allowed access to the City. When Queenhithe was constructed as an additional port, another break was needed in the wall, and wharves and quays were built along this part of the foreshore as well. The erection of the wharf on piles was speedily followed by the erection of tenements for the people between the wharf and the wall on the bank. The wharf extended laterally; the houses grew up laterally with the wharf; the wharf was pushed out farther upon the mud of the low tide; the wall was broken into here and there at intervals, continually growing less in length. These breaks are marked, possibly, by the ancient stairs, such as those of Paul’s Wharf and Trig Stairs. In a word, the whole of the first belt, that of the Service, is later than the Roman wall. It belongs, therefore, to the Saxon period, and in great part, perhaps, to the early Norman times. It seems likely that, if the riverside wall had been pierced or broken in parts, the Danish and Norwegian besiegers would have attacked the City at those vulnerable points. A narrow stream, such as Walbrook, with wharves on either side, could be easily defended by chains drawn across; but a dozen places where the wall was broken—and there was nothing to defend it except wooden wharves and wooden huts—would have been difficult to defend.
  • 58.
    BLACKFRIARS BRIDGE, 1796 ThamesStreet in later times, when the wall had disappeared, became the most crowded, the most busy part of the City. Its south side was wholly occupied by wharves, warehouses, and the dwellings of the working people, the Service of the port. On the north side and in the streets rising up the hill were the houses of the merchants and the better class—the second belt of the City. Here stood the townhouses of the nobles among the equally stately houses of the merchants. Here kings were entertained by the mayors and aldermen. The great number of churches shows not only the crowded condition of this part, but also the wealth of the merchants by whom the churches were founded, rebuilt, adorned, and endowed. The breadth of the foreshore as at present built upon varies from 150 feet at its narrowest, which is at the western end, to 450 feet at its broadest, which is on either side of the Walbrook. The modern breadth, however, must not be taken to represent the breadth in the twelfth century. The excavations for London Bridge in 1831 disclosed three distinct lines of piles, representing three several occasions when the foreshore was built upon. And the oldest plan of London, called after one Agas, clearly represents the erection by the riverside built upon piles. There are no churches on this belt of reclaimed land. As it was gradually added to the City, so it was gradually added to the riverside parishes. Four churches are built on the south side of Thames Street, viz. Allhallows the Great, Allhallows the Less, St. Botolph, and St. Magnus. The dedication of the last two proclaims their late origin. The last, for instance, must belong to the late eleventh or the twelfth century. The very small size to which the parishes would be reduced if we took away the reclaimed foreshore seems to indicate that much was reclaimed before the Norman Conquest. The dedication of the churches along Thames Street—St. Peter, St. James, St. Michael, St. Mary, St. Andrew—has been supposed to indicate the site of Roman churches. Perhaps the parish boundaries may have been adjusted from time to time. “Roomland” was the name given to the quays and the adjacent plots of land of Queenhithe, Dowgate, Billingsgate, etc., whereon goods might be discharged out of
  • 59.
    vessels arriving there. In1311 and in 1349 we find mention of houses built upon “la Romeland” by St. Michael, Queenhithe. In 1338, and again in 1349, we read of a tenement near the King’s garden upon le Romelonde, near the Tower. In 1339 we learn that there was a Roomland in the parish of Allhallows Barking. After 1374 we find no more mention of any Roomland. Perhaps the limits of the quays were by this time contracted and defined; perhaps the foreshore had been enlarged and the “land” behind had been built upon. Thames Street was the Exchange, the place of meeting for the merchants. One supposes, however, that the lesser sort transacted business at the taverns. Here walked in great dignity Aylwin of London Stone, the first mayor; Whittington, Philpott, Rokesley, and the Beckets, Faringdons, Walworths, Sevenokes, and all the great men of the City, each in his generation, not only building up their own fortunes, but fighting against disorder and crime in their wards, and against encroachments from the sovereign. The Fire swept through the street, raging among the stores of the warehouses, laying low churches, destroying monuments, and burning up old memories and associations. The warehouses were at once rebuilt, but, according to Malcolm (1803), many of the buildings had in his time become ruinous or decayed. There is very little left of the building immediately after the Fire: hardly a single warehouse, and on the north side only one or two of the mansions built by the merchants. The two ports, Billingsgate and Queenhithe, still remain, though the trade of the City is no longer carried on upon the quays. The Custom House still stands very nearly on its old site; the bridge has been moved farther west; there are other City bridges— Blackfriars and Southwark; one can still walk down lanes as narrow as when they were first reclaimed from the foreshore; and there are still one or two of these narrow lanes where, as of old, the people of the Service live. The following is a list of the old signs in Thames Street: “The White Bear” inn; “The White Lion” inn near London Bridge; “The White Lion” inn at the White Lion Wharf; “The Blew Ancor” inn; “The Old Swan” inn; “The Bull Head” inn; “The Naggs Head Tavern” inn; “The Princes Arms” inn; “The Fling Hors” inn; “The Lion and Key” inn; “The Black Bell inn; “The Woodmongers Arms” inn; “The Crose Bulets” inn; “The Suggar Lofe” inn; “The Lobster” inn; “The Bear and Ragged Staff” inn; “The Two Fighting Cocks” inn; “The Blue Boar and Three Horse Shoes” inn; “The Horse Shoe” inn; “The Royal Arms on Shield” inn; “The Cross against Barkin Church” inn. Thames Street itself is the subject of a great many references in the Calendar of Wills dated from 1275 to 1688. The earliest is in 1275, after which they occur repeatedly. In 1280 a tenement is mentioned as that of Ernald Thedmar; in 1282 Henry de Coventre bequeathed to his wife his mansion in the Vintry from Thames Street to the waterside.
  • 60.
    So far, wehave spoken of Thames Street and the riverside generally; let us now take our section in detail. Only a short way to the north lay Ludgate, one of the principal entrances to the City. Ludgate can hardly have been so named later than the Norman Conquest. Stow, in his explanation of the ancient street leading from Aldgate to Ludgate, clearly conveys the belief that it was an ancient gate. Perhaps the necessity of land communications from the City to Westminster caused the piercing of this gate and the construction of the causeway and the bridge over the valley and stream of the Fleet. In that case, one would naturally think of King Knut and his palace at Westminster. The name is said to mean a postern. Ludgate was either repaired or rebuilt in 1215, when the barons, in arms against King John, entered London and destroyed the houses of the Jews, using the stones in the restoration of the City walls and of Ludgate more especially. Stow records a curious confirmation of this circumstance, the discovery, when the gate was rebuilt in the reign of Queen Elizabeth, of a stone with a Hebrew inscription, signifying the sign or note of Rabbi Moses, the son of Rabbi Isaac. On the east side, in a niche, on this renewal, were placed the statues of Lud and his two sons in Roman costumes; and on the west side the statue of Queen Elizabeth. When the gates were taken down (1761-62), Lud and his sons were given by the City to Sir Francis Gosling, who intended to set them up at the east end of St. Dunstan’s Church, in Fleet Street. This, however, he did not carry into effect, and the king and his two sons were deposited in the parish bone-house. The statue of Elizabeth met with a better fate, having a niche assigned it in the outer wall of old St. Dunstan’s, Fleet Street. The Lud gate of 1586 was gutted in the Great Fire, and the stonework seriously injured. Ludgate was first erected into a prison in the reign of Richard II., and was anciently appropriated to the freemen of the City and to clergymen. The place soon became too small for the growing occasions of the City, and it was enlarged at the expense of Dame Agnes Forster, widow of Stephen Forster, mayor in 1454. “Formerly Debtors that were not able to satisfy their debts, put themselves into this prison of Ludgate for shelter from their creditors. And these were merchants and tradesmen who had been driven to want by losses at sea. When King Philip, in the month of August, 1554, came first through London, these prisoners were thirty in number, and owed 10,000 pounds, but compounded for 2000 pounds, who represented a well-penned Latin speech to that Prince to redress their miseries, and by his royal generosity to free them. ‘And the rather for that place was not Sceleratorum Carcer, sed Miserorum Custodia, i.e. a gaol for villains, but a place of restraint for poor unfortunate men; And that they were put in there, not by others, but themselves fled thither; and that not out of fear of punishment, but in hope of better fortune.’ The whole letter was drawn by the curious pen of Roger Ascham, and is extant among his epistles, Lib. III.” (Cunningham). The rules and customs of Ludgate are given by Strype:
  • 61.
    “If a freemanor freewoman of London be committed to Ludgate, they are to be excused from the Ignominy of irons, if they can find sureties to be true prisoners, and if the sum be not above £100. There is another custom for the liberal and mild imprisonment of the citizens in Ludgate; whereby they have indulgence and favour to go abroad into any place, under the guard and superintendency of their keeper; with whom they must return again to the prison at night. “This custom is not to hinder and delay Justice nor to defraud men of their debts and executions, as it is quarrelled against by some, but serves for a mitigation of their punishment; and tends rather for the expedition of their discharge, and speedy satisfaction of their creditors. While they may go and inform themselves, upon their mutual reckonings, both what they owe, and what is due unto them.” For further account of this prison see London in the Eighteenth Century, pp. 581-87. In the year 1659, one Marmaduke Johnson, a prisoner in Ludgate, presented a memorandum on the prison and its Government to the Lord Mayor. In this document he sets forth the history of the prison, its constitution and laws, its officers, its charities, and the grievances of the prisoners. A great many benefactors have left money to the prison, amounting in all to about £60 a year. In addition, the Lord Mayor allowed the prisoners a basket of broken meat every day; and provisions of some kind were every day, to some small extent, bestowed upon them by the markets. Besides which there were two grates, one in Ludgate, and the other on the Blackfriars side, where all day long a man stood crying, “Pity the poor prisoners.” There were about fifty of the prisoners “on the Charity,” as it was called. But the warders and turnkeys, by their exactions, got most of the money. Ludgate Hill was formerly Bowyer Lane. On the south, until a few years ago, were to be seen some fragments of London Wall, now vanished. On the top of Ludgate Hill, and on the west side of St. Paul’s, Digby, Grant, Winter, and Bates were executed, January 30, 1606, for their participation in the Gunpowder Plot. The houses on the south side of the hill were set back when the street was widened in modern times. On the north side there are several old ones.
  • 63.
    ST. MARTIN, LUDGATE Thischurch was rebuilt in 1437 for Sir John Michael, then mayor, but was destroyed by the Great Fire, and rebuilt from the designs of Wren in 1684. The benefice was united with the united benefices of St. Mary Magdalene, Old Fish Street, and St. Gregory by St Paul’s, by Order in Council, 1890. The earliest date of an incumbent is 1322. The patronage of the church, long before 1322, was in the hands of: The Abbot and Convent of Westminster; Henry VIII., who seized it and granted it to the Bishop of Westminster, January 20, 1540-41; the Bishop of London, by grant of Edward VI., 1550, confirmed by Queen Mary, March 3, 1553-54, in whose successors it continued. Houseling people in 1548 were 476. The interior of the church is noticeable as being broader and higher than it is long, its width being 66 feet, height 59 feet, and length 51 feet. The appearance is rendered cruciform by four composite columns, which, with pilasters on the walls, support entablatures at the angles of the church. The ceiling is lowered in the quadrangular corners thus formed. The tower rises at the centre of the south front, and contains three stories; this is concluded by a cornice, above which there is a narrow stone stage surmounted by an octagonal cupola, with a lantern and balcony. The steeple is completed by a tapering spire, with ball, finial, and vane; its height is 158 feet. It is said to have been especially built by Wren to form a foreground to the towering dome of St. Paul’s. Chantries were founded here by: William Sevenoke, whose endowment fetched £3 : 6 : 8 in 1548; Michael de London and John le Hatte, augmented by Roger Payn, William Pows, Simon Newell, and Thomas Froddashame, to which John de Derby was admitted as chaplain, January 11, 1392-93, on being vacated by Roger Shirrene; William Alsone, who also founded chantries in Northants and Derbys. William Sevenoke, grocer, who founded a free school and almshouses in the town of Sevenoaks, Kent, Mayor of London, 1419, was buried here and commemorated by a monument. The other monuments recorded by Stow are of little note. No benefactors are recorded by Stow. Sixty boys and fifty girls, belonging to the charity school of the ward, were clothed and disposed of (when fit) by subscriptions from the inhabitants. William Glyn (d. 1558), Bishop of Bangor, was rector here; also Richard Rawlins (d. 1536), Bishop of St. David’s.
  • 64.
    Photochrom Co., Ltd. LUDGATECIRCUS AND LUDGATE HILL On Ludgate Hill we find also Stationers’ Court, where is the Stationers’ Hall.
  • 65.
    THE STATIONERS COMPANY TheCompany was incorporated in 1557, but it is believed that a brotherhood or society existed upwards of a century and a half previously, called the Brotherhood or Society of Text-writers. There was a Gild of Stationers as early as the beginning of the fifteenth century. It appears to have been a branch of the Scriveners, and to have left them to carry on the preparation of legal documents while they themselves took over the production of books. The charter of the Company shows that it was regarded as a company of printers, and that Queen Mary intended it to be especially a guard against the issue of heretical doctrines. Drawn by Thos. H Shepherd. STATIONERS’ HALL IN 1830 The original charter was destroyed in the Fire of London, but the Company have a copy of it; also of the charter granted by William and Mary, confirming the privileges granted by the charter of 1556. The Company has continued ever since its incorporation, and still is, a trade guild consisting exclusively of members of the trade of a stationer, printer, publisher, or bookmaker, and their children, and descendants born free. The greater number of printers’ apprentices in the City of London are bound at Stationers’ Hall, and the Company’s pensioners, and the recipients of the charities under their control, are principally journeymen printers, compositors, and pressmen.
  • 66.
    The Company wasoriginally established for the purpose of fostering and encouraging the trade of a printer, publisher, and stationer, and from the time of its original foundation to this date a limited number of liverymen of the Company have carried on at Stationers’ Hall the trade of a publisher for their own benefit, and a division of profits has been annually made amongst the partners. Other portion of the profits has been distributed annually amongst poor freemen of the Company, applied towards the necessary expenses of the Company, and invested in the purchase of the hall and premises adjoining. The capital for this trade was originally subscribed by the members of the Company in certain proportions or shares, and these shares have been regularly transmitted from time to time since 1605, as in the case of shares of trade companies. The copyright registry was first established by the Company at the commencement of the sixteenth century or even earlier. It would appear from the ancient records that a register of copies had existed previous to the incorporation. In 1565 rules were made by the Company regulating the transmission of copies upon the decease of the owner, and requiring them to be entered in the books of the Company. In 1584 the Privy Council (through the Lord Mayor) ordered that all copies should be entered in the Company’s register, and copyrights were from time to time transferred by entries in these registers. Between 1580 and 1615, there are letters from the Lords of the Council and the Lord Mayor calling attention to the publication of certain books of a traitorous or mischievous tendency. There is no mention of any power or authority belonging to the Stationers Company for the suppression of these books. On one occasion the Wardens of that Company are ordered to produce the printer of a certain pamphlet with the person who was circulating it. Various orders were from time to time issued by the Lords of the Privy Council and High Commissioners, regulating printing. In 1660 a committee of the House of Commons was appointed to prepare a Bill regulating printing, and in 1662 the Bill was passed, and was known as the Licensing Act. It required all printed works to be registered at Stationers’ Hall. This Act expired in 1681, and in 1710 the first copyright Act was passed, which has been superseded by the Act of 1842. The Act of 1710 required copies to be entered at Stationers’ Hall before publication, and the Act of 1842 makes entry at Stationers’ Hall a condition precedent to the title to sue for protection against infringements. As a printer, not as a novelist, Samuel Richardson was a member. The most ancient hall stood in Milk Street, Cheapside, but in 1553 the Company moved to St. Peter’s College, near the Deanery of St. Paul’s, and in 1611 they purchased Abergavenny House in Stationers’ Court. This was burnt in the Great Fire. The present building was erected in 1670, and in 1805 the exterior was cased in Portland stone, according to a design by the Company’s architect, Robert Mylne, F.R.S. The present livery is 284; the Corporate Income is but small, and the Trust Income £1200. The Company formerly published almanacks, primers, “A.B.C.’s,” psalters, and school books, in which they maintained a valuable monopoly until the middle of
  • 67.
    the eighteenth century,when it was declared illegal. The Company established a school at Bolt Court, Fleet Street, in 1861; this is now at Ridge Road, Hornsey. The school has accommodation for more than three hundred boys. This corner of London to the south of Ludgate Hill was covered with narrow lanes and courts into which light was admitted by the construction of Queen Victoria Street. It is the site of the Blackfriars’ Precinct. This house was in the hands of the Dominicans. See Mediæval London, vol. ii. p. 354. Church Entry marks the site of St. Anne, Blackfriars, standing adjacent to the walls of Blackfriars’ Monastery; it was consecrated in 1597 by Edmund Stanhope, Doctor of Laws, by virtue of a commission from the Bishop of London. It was enlarged on the south side in 1613, which was consecrated by the Bishop of London in 1617. The church was burnt down in the Great Fire and not rebuilt, but the parish was annexed to St. Andrew by the Wardrobe. The earliest date of an incumbent is 1597. The patronage was in the hands of the Crown and parishioners alternately, since the Great Fire when it was burnt down, and the parish was annexed to St. Andrew by the Wardrobe; before this the parishioners presented. Isaac Oliver, miniature painter, was buried here. STATIONERS’ HALL (INTERIOR) The charities and reliefs recorded in this parish were few. John Bobhurst was a donor of £2 per annum, also Edward Corbet and Mrs. Miller. The greatest benefactor was Peter Jorge, who founded a free school, appointing Sion College trustees.
  • 68.
    Forty boys andthirty girls were to be taught reading and writing, and some useful work besides. All were to be given clothing once a year and two to be put out as apprentices. The school was endowed with £150 a year, and salaries for teachers. As there were many tailors among the foundation, the children of such were to have preference of admission (Stow and Strype). St. Anne’s had some notable vicars, among them William Gouge (or Goughe), D.D., forty-six years minister of the parish. In November 1633 “Mr. William Goughe, Doctor of Divinity, prayed to be admitted freeman of the Society of Apothecaries, and was so.” On the west is an open space fairly wide, with asphalt centre and scrubby bushes round. This is jealously guarded by iron rails and wall from all intruders. It was sacred ground, the churchyard, though there are no monuments or stones left to bear testimony. Close beside the churchyard in a carpenter’s shop are certain old arches belonging to the Dominicans’ Buildings. Westward there is a small court, called Fleur-de-Lys, on the west side of St. Anne’s churchyard, which escaped the Fire, though here the Fire had raged most hotly. A little consideration will show the reason. An open space called Church Entry lay between the backs of the Fleur-de-Lys Houses and St. Anne’s Church and churchyard. Now the church stood high, and during the continuance of the Fire the wind blew steadily from the east. The view of the City after the Fire shows that the walls of the churches and of many houses were still standing. Therefore, even though the roof was burned, the flames blew over this court, while, when the roof had fallen, the walls of the church sheltered the little court on the other side. I dare say that, had we a more exact account of the Fire, it would be found that many houses or courts escaped in the same way. “Eminent inhabitants—(of Blackfriars), Isaac Oliver, the miniature-painter. He died here in 1617, and was buried in St. Anne’s, Blackfriars. Lady Ayres, wishing to have a copy of Lord Herbert of Cherbury’s picture to wear in her bosom, went ‘to Mr. Isaac the painter in Blackfriars, and desired him to draw it in little after his manner.’—Cornelius Jansen, the painter (d. 1665). He lived in the Blackfriars for several years, and had much business, but left it a little before Van Dyck’s arrival. Sir Anthony Van Dyck, from his settlement in England in 1632, to his death in 1641. The rent of his house, ‘at a moderate value,’ was estimated, in 1638, at £20, and the tithe paid £1 : 6 : 8. His daughter Justina was born here December 1, 1641, and baptised in St. Anne’s, Blackfriars, December 9, 1641, the day of her father’s death. Ben Jonson, who dates his dedication of Volpone or The Fox ‘from my house in the Blackfriars, this 11th day of February, 1607.’ Here he has laid the scene of The Alchemist. The Earl and Countess of Somerset were living in the Blackfriars when Overbury was murdered. The precinct no longer exists, but is now a part of the ward of Farringdon Within. I have not been able to trace any attempt to assert its privileges later than 1735, when in the July of that year the Court of Common Council brought an action against Daniel Watson, for opening a shop and vending shoes in the Blackfriars without being free of the City. The court
  • 69.
    of King’s Benchgave it in favour of the City. The sheriffs could arrest here many years before” (Cunningham). Note that the Earl of Northumberland had a town house in 1612 in the unfashionable precinct of Blackfriars. FLEUR-DE-LYS COURT Within the precinct were—and are—several places of interest. The Blackfriars Theatre was built in 1576. It was rebuilt or extensively repaired in 1596 when Shakespeare and Richard Burbage were sharers. In 1633 it was let by Cuthbert and William Burbage for a rent of £50. The building was pulled down in 1655 and tenements put up in its place. Playhouse Yard preserves the memory of the theatre. Standing at the western end of Queen Victoria Street and taking a general view we see St. Paul’s Station of the L.B. and S.C. Railway. Water Lane runs by the railway. Here is the Apothecaries’ Hall.
  • 70.
    THE APOTHECARIES COMPANY Twoopposite forces acted upon the City Companies: one separating them and multiplying Companies for different parts of the same trade or craft; the other uniting in one Company crafts which were related chiefly by using the same material. Thus the Barbers divided into Barbers and Surgeons; the Grocers into Grocers and Apothecaries; while at one time the Weavers included in their body all those trades which had to do with woven stuffs, and were so powerful that they threatened to rule the whole City. It happened sometimes that some trades were injured by the inability of the Company to look after them. Thus it was quite natural that the Grocers who imported drugs and spices and oils used by Apothecaries should include these persons in their own livery. But, the wardens not being skilled in the use of medical prescriptions and preparations, could not look after their own people. Consequently complaints became general of the ignorance and incompetence of Apothecaries for want of proper supervision. Towards the end of the sixteenth century these complaints were brought forward categorically. It took time for the matter to be understood, and it was not until 1617 that James bestowed a separate charter upon the Apothecaries in spite of the remonstrances of the Grocers. The objects of this charter, concisely stated, are to restrain the Grocers (the former associates of the Apothecaries) or any other City Company from keeping an apothecary’s shop or exercising the “art, faculty, or mystery of an apothecary within the City of London or a radius of seven miles.” To allow no one to do so unless apprenticed to an apothecary for seven years at least, and at the expiration of such apprenticeship such apprentice to be approved and allowed by the master and wardens and representatives of the College of Physicians, before being permitted to keep an apothecary’s shop, or prepare, dispense, commix, or compound medicines. To give the right of search within the City of London or a radius of seven miles of the shops of apothecaries or others, and “prove” the drugs, and to examine within the same radius all persons “professing, using, or exercising the art or mystery of apothecaries.” It also confers the power to burn “before the offender’s doors” any unwholesome drugs, and to summon the offenders before the magistrates. And to buy, sell, or make drugs. Up to the passing of the Apothecaries Act, 1815, so far as the prescribed radius extended, the three first-stated objects of the charter and the existence of the society in relation to its members were identical. A member of the Society of Apothecaries and an apothecary of the City of London or within seven miles were convertible terms. As regards the fourth object prescribed by the charter, the Society, doubtless from its want of means, has never itself until the present time bought, sold, or made drugs, but owing to the great difficulty of its members obtaining pure drugs
  • 71.
    it allowed themto raise money themselves and create stock or shares for that purpose, and to carry on such trade in the name of the Society for their own personal profit as a private Company or partnership under various titles. Owing to such trade having ended in a loss, this private partnership was dissolved in 1880, and the Society is now itself carrying on the trade at its own risk. As regards the three first-stated powers of the charter, the Society (by means of the Apothecaries Act of 1815) extended them so greatly as to effect not only a revolution in their own sphere of operations, but also in the medical profession and in the relations subsisting between the latter and the general public. This Act (after placing the right of search referred to in the third-stated power of the charter on a more precise and practical basis, but to which it is unnecessary to allude as having fallen into necessary desuetude by the various Pharmacy and Poisons Acts) created a court of 12 examiners to be appointed by the master, wardens, and court of assistants, who were to examine all persons in England and Wales as to their skill and ability in the science and practice of medicine, and five examiners to examine assistants for the compounding and dispensing of medicine. It authorised the Society to receive fees for granting the respective licences, and (saving the rights of the Colleges of Physicians and Surgeons) it empowered the Society to recover penalties for practising or compounding without such licences. The Apothecaries Act, 1815, contained, however, two restrictions which were removed by the Apothecaries Act Amendment Act, 1874, namely, (a) the obligation of the 12 examiners being members of the Society of Apothecaries, and being of at least 10 years’ standing, and (b) of candidates for examination having served an apprenticeship of five years to an apothecary. The Act of 1874 also contains other provisions which relate more to questions of medical legislation than this present inquiry. Shortly the effect of the Act of 1815 was to make the Society of Apothecaries one of the three great medical licensing bodies for England and Wales [the number of its present licentiates is between 8000 and 9000], and of the Act of 1874 was to throw open the Society’s examinerships, and to confer on it a freedom in reference to future medical reform to an extent not exceeded by any other body. The Company consists of about 400 members including the court, the livery, and the yeomanry or freemen. The hall, which stands on the eastern side of Water Lane, formerly consisted of the town house of Lady Howard of Effingham. It was, of course, destroyed by the Fire, but the buildings which were erected after the Fire have a delightful air of quiet and peace, such as belongs very fitly to a scientific society. The hall stands behind a small paved court; on the left hand is the shop, at the north end of the hall are the offices, the library and the court rooms. The Physic Gardens at Chelsea also belong to the Apothecaries on certain conditions, especially that the Company should every year present to the Royal Society fifty dried specimens of plants growing in these gardens, till the number of 2000 was reached. As this was in 1731, that number has long since passed and the Company’s debt is paid.
  • 72.
    Among the moreeminent members of this Company have been William and John Hunter, Jenner, Smollett, Humphry Davy, Dr. Sydenham, Erasmus Wilson, and Sir Spencer Wells. Oliver Goldsmith and Keats were also members. Printing House Square contained the King’s Printing House. “The first I have discovered was John Bill, who, ‘at the King’s Printing House in Black Friars,’ printed the proclamations of the reign of Charles II., and the first London Gazette, established in that reign. Charles Eyre and William Strahan were the last King’s printers who resided here, and in February, 1770, the King’s Printing House was removed to New Street, near Gough Square, in Fleet Street, where it now is. The place still continues to deserve its name of Printing House Square, for here every day in the week (Sunday excepted) The Times newspaper is printed and published, and from hence distributed over the whole civilized world. This celebrated paper, finding daily employment on the premises for between 200 and 300 people, was established in 1788,—the first number appearing on the 1st of January in that year.” (Cunningham.) The Times office is a very notable feature in Queen Victoria Street by reason of its great height and conspicuous clock. Queen Victoria Street and Upper Thames Street gradually diverge at a very acute angle. The former is on a lower level than the latter, and is divided from it for about seventy yards by a low wall only, with an open space crossed by steps. In Queen Victoria Street on the left is the square tower of St. Andrew by the Wardrobe, outlined in white stone, and thrown into relief by a rather ornamental red-brick building which stands in front. St. Andrew’s Hill was sometimes called Puddle Dock Hill. In Ireland Yard stood the house bought by Shakespeare in 1612, and bequeathed by him to his daughter Susanne Hall. In Green Dragon Court there stood, until a year or two ago, one of the oldest of the London taverns from which the court took its name. The Wardrobe.—On the north side of St. Andrew’s church stands a small square which, with its trees and the absence of vehicles or shops, is one of the most quiet spots in the whole City. This square was formerly the court of the town house built by Sir John Beauchamp (d. 1359), whose tomb in St. Paul’s Cathedral was commonly called Duke Humphrey’s tomb. Before his death the house became the property of King Edward III. who made it a Royal Wardrobe House, and so it remained until the Great Fire. James I. gave the collection of dresses—called by Fuller a “Library of antiquaries wherein to read the fashion and mode of garments in all ages”—to the Earl of Dunbar, by whom they were all sold and dispersed. The wardrobe was taken after the Fire to the Savoy and then to Buckingham Street, Strand. The last keeper was Ralph, Duke of Montagu (d. 1709). When Charles V. came to England in 1522, among the lodgings assigned to his suite was the house of Margaret Hanley, “under the Wardrobe side, having two chambers and two beds.” Wardrobe Place is a delightful spot with an air of brooding quietness. The houses are nearly all old “post fire,” dating from about 200 years ago. That on the east side of the entry is black with age, and the lines in the brickwork waver as they
  • 73.
    cross its front.Next to it on the east side of the court is a plaster-fronted one, and then a row of three dark-brick houses with the so-called “flat arch” of brighter red bricks glowing above the rectangular windows. Nearly a dozen twisted plane trees, all young, and measured by inches only in circumference, straggle irregularly from the cobblestones of the courtyard. On the west side there are charming houses in the same style as the above-mentioned. The largest of these, No. 2, is wainscotted from floor to ceiling, and has in many rooms great projecting fireplaces forming recesses on either side half the width of the rooms. From the south-east corner there is a covered-in passage leading to the back of the Old Bell Hotel, and with Wardrobe Chambers opening into them.
  • 75.
    ST. ANDREW BYTHE WARDROBE The church derived its title from its proximity to the King’s Wardrobe above described. It was formerly called St. Andrew-juxta-Baynard’s Castle. After the Great Fire, the church was rebuilt by Wren and completed in 1692, and the parish of St. Anne, Blackfriars, was united with it. The earliest date of an incumbent is 1261. The patronage of this church was in the hands of: The family of Fitzwalter, Lords of Woodham, 1361, which becoming extinct, it passed to Thomas, Lord Berkeley, then to Richard, Earl Warwick, who married Berkeley’s daughter; the three daughters of the Countess of Warwick, viz. Lady Talbot, afterwards Countess of Shrewsbury; Lady Ross; and Lady Latimer, afterwards Countess of Dorset in 1439; and the Crown, since St. Anne’s, Blackfriars, was annexed to it. Houseling people in 1548 were 450. Pictorial Agency. BRITISH AND FOREIGN BIBLE SOCIETY HOUSE This church measures 75 feet in length, 59 in breadth, and 38 feet in height, and contains two side aisles divided from the nave by square pillars, encased in wood to the height of the top of the galleries. The ceiling is exceptionally fine, with beautifully moulded wreaths. The exterior is of red brick with stone dressings. The
  • 76.
    tower, which issquare and of four stories, rises at the south-west; the two lower ones contain windows, the third a clock, and the highest has square-headed openings with louvres. A cornice and balustrade complete the tower, which is about 86 feet in height. Chantries were founded here by: John Parraunt, armiger, for himself and Clemencia his late wife, and for John Loc, alias Foxton, citizen and fishmonger, and Margaret, his wife (licence was granted December 3, 1409; the endowment fetched £12 : 3 : 4 in 1518 when Thomas Mores was priest, “aged 54, meanly learned”); Humphrey Talbot, whose endowment fetched £7 : 6 : 8 in 1548. There are three pyramidal monuments of white marble to three successive rectors—the Rev. William Romaine, a celebrated preacher; the Rev. William Goode, rector in 1795; and the Rev. Isaac Saunders, who held the living for nearly twenty years. Some of the donors of charities were: John Lee, of a house and wharf, leased for £30 per annum; Mrs. Paradine, £3 per annum; Mrs. Cleve, thirteen penny loaves to be dealt out every Sunday. There was a free school founded by a private person for the benefit of the children of poor tailors, where forty boys and thirty girls were taught and clothed. Also three almshouses maintained by the rent of an adjoining house, built partly by charity of the Lady Elizabeth, Viscountess Chomondeley, and partly at the expense of the inhabitants, in 1679. Among the most notable of the rectors were: Philip Baker (d. 1601), Vice- Chancellor Cambridge University; William Savage (d. 1736), Master of Emmanuel College, Cambridge; William Romaine (1714-1795), Professor of Astronomy at Gresham College, London; William Goode (1762-1816), President of Sion College; John Harding (1805-74), Bishop of Bombay. A little passage, right-of-way to the public, goes round the north and east sides of the church, and at the corner where this joins St. Andrew’s Hill stands the old Rectory House. This is a charming old building, dating from soon after the Fire. There is, curiously enough, no oak in the woodwork, excepting only in the cross- pieces of the window-frames. The fireplace in the study is of interest, fashioned of marble and tiles set in polished wood; and on the overmantel there is a little slab bearing the words, all in capital letters: Laus Deo per Jesum Christum. Church Missionary Society, Instituted April 12, 1799, in this room; the committee meetings of the Society were held from June 17, 1799, to January 3, 1812: and here on January 2, 1804, its first missionaries were appointed to preach among the Gentiles the unsearchable riches of Christ. The house betrays its age in all its lines, and though there is no other special feature worthy of comment in it, the tiny garden behind is well worth a visit; it contains a plane-tree, and is a curious little oasis in a wilderness of bricks and mortar.
  • 77.
    Queen Victoria Streetwas only begun in 1867-68 as a direct thoroughfare from the embankment to the Mansion House. It was formally opened November 4, 1871. The headquarters of the British and Foreign Bible Society is solidly designed, with pilasters running up the front between the windows. Over the great door, supported by blocks of polished granite, is a heavy stone balcony, and three smaller balconies project from the windows above. An ornamental cornice runs round the roof. The architect was Mr. Edward l’Anson. The library contains the Fry collection of English Bibles, the most complete ever made. This was purchased by the Society for £6000. It includes a copy of the earliest edition of Coverdale printed abroad 1535, and one of the earliest editions printed in England two years later. In the cases about the room are many objects of interest—a German Bible printed 1473; Codex Zacynthus, a palimpsest, of which the earlier writing is supposed to date from the fifth or sixth century, the later from the twelfth. The Society was founded in 1804. Its object is simply to “circulate the Bible without note or comment, in all languages and in all lands.” Since its foundation over 140 million copies of the Bible, whole or in parts, have been issued. The Society now produces the Bible in about 330 languages and dialects. The University Press monopolises the printing of English Bibles, and much of the printing of the Society in foreign languages is done abroad. The only actual printing carried on in Queen Victoria Street is that done by one man, who works with two hand-presses for the blind. But the issue of fresh copies by the Society comes to an average of 13,000 for every working day. The General Post Office Savings Bank offices, with a frontage of about 250 feet, are next door. The garden belonging to the old Doctors Commons stretched across the roadway at this point, and was only finally cleared away in 1867 at the making of the new street. The Heralds’ College or College of Arms is a fine old building in deep-coloured brick. The front stands back from the street, and is supported by two wings. The small courtyard resulting is separated from the street front by high iron railings and gates. There are two brick and stone piers at each gateway, with that favourite ornament of the Stuart period—stone balls—on their summits. The back of the eastern wing abuts on Peter’s Hill, and the wide, outside flap shutters of an old- world style give the little hill a quaint aspect. The College was rebuilt after the Fire, and restored at the opening of Queen Victoria Street. It was originally Derby House, built by the first Earl of Derby and presented in 1555 by Queen Mary to the then Garter King-of-Arms; so it has long been devoted to its present use. Returning to Queen Victoria Street we see opposite in enormous gilt letters, each four or five feet long, “Salvation Army International Headquarters” right across the front of a great building. Addle Hill, like Addle Street, is supposed to be derived from the Saxon Adel, noble. It has been found written Adling Hill. The whole space between Addle Hill and Bell Yard, and between Queen Victoria Street and Carter Lane, with the exception of Knightrider Street, is now occupied by General Post Office Savings
  • 78.
    Bank Department. Northward,on the south side of St. Paul’s Churchyard, near the west end, was the church of St. Gregory mentioned elsewhere. Carter Lane was formerly divided into Great and Little Carter Lane. From the Bell Inn, Bell Yard, in Carter Lane, the only letter addressed to Shakespeare that is known to exist was sent to him by Richard Quiney—“To my loveing good friend and country man, Mr. William Shakespeare, deliver these.” Bell Yard led to the Prerogative Will Office, Doctors’ Commons. Carter Lane, also called Shoemakers’ Row, is mentioned in the Calendar of Wills in the year 1295. The west end still retains that name in Ogilby’s map of 1677. In 1424 the exchequer paid to John Kyllyngham, master of a house called The Bell in Carter Lane, the sum of £17 : 14 : 8 for costs and expenses of Sir Gilbyn de Lauvoy, knight, and John de la Roe, Esq., and their servants and horses for twenty- eight days. The said Sir Gilbyn and John de la Roe had been sent to the Holy Land by Henry V. “upon certain important causes.” Deeds of the fourteenth century speak of tenements in Carter Lane. In this street were several taverns of note such as the White Horse, the Sun, the Bell, and the Saracen’s Head. Here was a famous meeting-house in which many of the most distinguished of Nonconformist ministers preached. Pictorial Agency. THE COLLEGE OF ARMS Here is the school for St. Paul’s choir-boys, with a stencilled frieze. The playground is on the roof. Creed Lane was formerly called Sporier Row. An inn in Sporier Row is assigned in the fifteenth century by the Dean and Chapter of St. Paul’s to their canons. After the Fire there were differences as to the sites and boundaries of
  • 79.
    houses destroyed inCreed Lane. The Lane was widened in 1750 as one of the improvements made at that time. Dean’s Court has now warehouses erected on the north and east sides. The house over the archway was said to have been occupied by Sir Christopher Wren as his office during the building of St. Paul’s. Within this court were also the vicar general’s, the commissary and the consistory courts, and offices for procuring marriage licences. St. Peter’s College adjoined Dean’s Court on the west side in St. Paul’s Churchyard (see under the Stationers Company, p. 199). When Charles V. came to London in 1522, Doctors’ Commons among other places furnished for his suite a hall, a parlour, and three chambers with feather beds. Mention is made of the dining-hall of Doctors’ Commons and of the “entre going into the great canonicale House now naymed the Doctors’ Commons with a chamber over the said entre,” and of other parts of the building. This ancient College or House of Doctors of Law was swept away in 1861-67 in consequence of alterations in legal procedure. The courts were removed, and the business of the proctors was merged in the ordinary work of the High Courts of Justice and the Bar. The Deanery itself is on the west side standing back behind a high brick wall, painted yellow. It is attributed to Sir Christopher Wren, and was built soon after the Great Fire. The stone piers of the gates are surmounted by cones. The building itself is tiled with three dormer windows standing out from the roof and heavy projecting eaves. In the interior there is no carving or anything of antiquarian interest calling for remark, but the front door has some rich wood-carving in the style of Grinling Gibbons. Paul’s Chain and the greater part of St. Bennet’s Hill are now Godliman Street. The origin of the name “Godliman” is unknown. Cunningham says that the earliest mention of the name is 1732. It is not found in Ogilby nor in Strype. It has been spelt “Godalmin.” A little court named Paul’s Bakehouse seems to have been asleep while the rest of the world passed it by. It is true the house immediately fronting the entry is covered with ugly yellow plaster, but it is by no means obtrusively modern, and if we except an iron railing in the corner over an area in the north-east, and the house above it, the remainder of the court has been touched by time alone since it left the builders’ hands in the seventeenth century. The houses on the north and south sides are of brick; the northern ones bulge forward out of the perpendicular, and they have low wooden doorways. That in the south-west corner is supported by grooved pilasters. The northern building claims a better staircase in the interior—a staircase with spiral balusters and carved woodwork, low and substantial. Knightrider Street.—Why this street should be named, as Stow says, “after knights riding” more than any other street, it is impossible to explain. One may, however, suppose that it was named after some branch of the Armourers’ or Loriners’ Craft. Dr. Linacre lived here. Knightrider Street now extends to Queen
  • 80.
    Victoria Street, butformerly the eastern part from Old Change was called Old Fish Street. Do Little Lane, between Carter Lane and Knightrider Street, now Knightrider Court, is found in many ancient documents called “Dolite,” “Do Lyttle,” “Doelittle” in deeds of Edwards I., II., and III. DOCTORS’ COMMONS, 1808 From a drawing by Rowlandson and Pugin.
  • 82.
    ST. NICHOLAS COLEABBEY The church stands in Knightrider Street; it has been known by several other names, Coldenabbey, Coldbey, etc. It was burnt down in the Great Fire, and rebuilt from the designs of Sir Christopher Wren in 1677, when the parish of St. Nicholas Olave was annexed. In 1873 it was thoroughly repaired. Four other parishes were subsequently united. The earliest date of an incumbent is 1319. The patronage of the church was in the hands of: The Dean of St. Martin’s-le- Grand, then the Abbot and Convent of Westminster, 1532. Henry VIII., who seized it, and so continued in the Crown till Queen Elizabeth granted it in 1559 to Thomas Reeve and George Evelyn, from whom it passed to several private persons and at length came to the Hacker family in 1575, one of whom, Colonel Francis Hacker, was involved in the beheading of Charles I.; he was finally executed as a traitor, his estate including this advowson being forfeited and thus it came to the Crown, and so continued until St. Nicholas Olave was annexed after the Great Fire, when the patronage was shared alternately with the Dean and Chapter of St. Paul’s. Houseling people in 1548 were 180. The interior of the church, which contains no aisles, measures 63 feet in length, 43 feet in breadth, and 36 feet in height. The steeple, which rises at the north-west, consists of a tower of four stories concluded by a cornice with urns at each angle; above this a spire rises, completed by a balcony, and supporting a square pedestal with a finial, ball, and vane. The total height is about 135 feet. Chantries were founded here: By John Sywarde and Thomas Blode, who endowed it with lands which fetched £6 in 1548, when Anthony Little was priest “of 50 years and of mean learning”; by John Tupley, who left lands and tenements valued at £12 : 8 : 4 in 1548, when Ralph Jackson was priest “of 30 years of age and very well learned”; Thomas Barnard, John Saunderash, and William Cogshale, who gave their lands in Distaff Lane to endow the same, which yielded £7 : 6 : 8 in 1548, when William Benson was priest, “46 years of age, and a very poor and sickly man.” The church contained no monuments of any special note. Walter Turke, mayor in 1349, was interred here. Barnard Randolph bequeathed £900 to this parish and St. Mary Magdalene for charities; he died in 1583. No other names are recorded by Stow. Herbert Kynaston (1809-1878), High Master of St. Paul’s School, was rector here. But the most notable among the rectors is the most recent, Prebendary Shuttleworth, whose death in 1900 left a gap difficult to fill. Among the most notable of his social schemes was the foundation of a social club for young men and women who work in the City (see p. 219).
  • 83.
    Old Fish Street,partly wiped out by Knightrider Street, was a row of narrow houses built along the middle of the street like the old houses at Holborn Bars, or like Butchers’ Row behind St. Clement Danes; or like Holywell Street, Strand. Stow says: “These houses, now possessed by fishmongers, were at the first but moveable boards or stalls, set out on market-days to show their fish sold; but procuring license to set up sheds, they grew to shops, and by little and little to tall houses of three or four stories in height, and now are called Fish Street.” St. Mary Magdalene, Old Fish Street, was situated on the north side of Knightrider Street at the west corner of the Old Change. It was destroyed by the Great Fire, and subsequently rebuilt and made the parish church for this and the parish of St. Gregory; but it was again burnt down in 1886, and has not been rebuilt. In 1890 these two parishes were united to St. Martin, Ludgate. The earliest date of an incumbent is 1162. The patronage of the church was in the hands of the Dean and Chapter of St. Paul’s, as a vicarage, about 1162, but about 1319 it was a rectory in the same patronage and has so continued. Houseling people in 1548 were 360. The church formerly contained a considerable number of monuments, but the individuals commemorated were of comparatively little note. Among them was one, Barnard Randolph, common sergeant of the City of London, and benefactor of the parish. He died in 1583. Some of the charitable gifts recorded by Stow are: A messuage, leased at £28 per annum, the gift of Thomas Berry; 40s. per annum, the gift of Justice Randall; £3 : 18s. per annum, the gift of the Company of Wax Chandlers. In St. Gregory’s Parish, in the Ward of Castle Baynard, there was a school purchased at the cost of Alderman Barber, where thirty boys and twenty girls were educated. There was one almshouse upon Lambeth Hill. John Hewitt was rector here; he was tried by Cromwell’s High Court of Justice in 1658 and beheaded. Also William Crowe (d. 1743), Chaplain in Ordinary to George II. Sermon Lane.—According to Stow this was originally Sheremonier’s Lane. The name is found as “Sarmoneres,” “Sarmoners,” “Sarmouneris,” and “Seremoneres” Lane. The most interesting mention of the Street is contained in the Hist. MSS. Comm. Rept. IX., Part I. 26b. (A.D. 1315): “Whereas a house belonging to the Chapter of St. Paul’s, at the north-east corner of ‘Sarmouneris’ Lane, has been assigned to Sir Nicholas Housebonde, minor canon of St. Paul’s, for his residence, the said Sir Nicholas has complained that it is inconvenient for the purpose on account of the grievous perils which are to be feared by reason of its distance from the cathedral and the crossing of
  • 84.
    dangerous roads bynight, and the attacks of robbers, and other ill-disposed persons, which he had already suffered, and also on account of the ruinous condition of the building and the crowd of loose women who live around it. The Chapter, therefore, assigns to him a piece of ground at the end of the schools upon which to make a house.” In Sermon Lane is the charity school. It was built in the beginning of the eighteenth century. Two quaint figures of charity children, each perhaps a couple of feet high, project from the first floor. The boy dressed in the long lapelled coat, the girl in panniers, apron, and cap. The house is of brick. The two lower floors have ordinary wide arched windows, but the two upper ones have each a unique display of no less than nine narrow, circular headed windows in a row extending across all the front. These give a curious cloistral aspect to the place. Over the doorway and two ground-floor windows are scrolls fixed up, but on one only is there an inscription, which is clearly readable, as follows: To the Glory of God and for the benefit of the poor children of this parish of Castle Baynard Ward this house was purchased at the sole cost of John Barber, Esq., Alderman of this ward, in the year of our Lord 1722. And on an immense plaster slab running all across the story above is “Castle Baynard Ward School, supported by voluntary contributions.” St. Bennet’s Hill.—Strype: “Upon Paul’s Wharf Hill, within a great Gate, and belonging to that gate next to the Doctors’ Commons are many fair Tenements, which in their Leases made from the Dean and Chapter go by the name of Camera Dianæ, or Diana’s Chamber. So denominated from a spacious building that in the time of Henry II. stood where they now are standing. In this Camera, an arched and vaulted structure, this Henry II. kept, or was supposed to have kept, that jewel of his heart, fair Rosamund, whom there he called Rosa Mundi; and hereby the name of Diana. To this day are remains and some evident testifications of turnings tedious and windings as also of a passage underground from this House to Castle Baynard, which was, no doubt, the king’s way from thence to his Camera Dianæ.” In 1452 (Hist. Comm. IX.) the “Inn called Camera Dianæ,” alias Segrave, in the parish of St. Benet is assigned by the Dean and Chapter of St. Paul’s to a Canon Residentiary of the Cathedral. And in 1480 we find the Camera described as a messuage with a garden let at eight marks a year to Sir John Clay; it was formerly occupied by Lord Berners, “but probably belonging to Richard Lichefield, Canon Residentiary, who pays to the Chapter 26s. a year for the obit of Richard Juvenis.
  • 86.
    Welcome to ourwebsite – 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! ebookultra.com