100% found this document useful (2 votes)
13 views

Beginning iOS 5 Development Exploring the iOS SDK 1st Edition Dave Mark 2024 scribd download

The document provides links to various eBooks related to iOS development and other topics, including 'Beginning iOS 5 Development' and 'Municipal Solid Waste to Energy Conversion Processes.' It emphasizes the availability of instant digital products in multiple formats such as PDF, ePub, and MOBI. Additionally, it contains copyright information and a detailed table of contents for the iOS development book.

Uploaded by

ononnoentoma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
13 views

Beginning iOS 5 Development Exploring the iOS SDK 1st Edition Dave Mark 2024 scribd download

The document provides links to various eBooks related to iOS development and other topics, including 'Beginning iOS 5 Development' and 'Municipal Solid Waste to Energy Conversion Processes.' It emphasizes the availability of instant digital products in multiple formats such as PDF, ePub, and MOBI. Additionally, it contains copyright information and a detailed table of contents for the iOS development book.

Uploaded by

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

Download the Full Version of the Ebook with Added Features ebookname.

com

Beginning iOS 5 Development Exploring the iOS SDK


1st Edition Dave Mark

https://ebookname.com/product/beginning-ios-5-development-
exploring-the-ios-sdk-1st-edition-dave-mark/

OR CLICK HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookname.com


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

Beginning iPhone 4 Development Exploring the iOS SDK 1st


Edition David Mark

https://ebookname.com/product/beginning-iphone-4-development-
exploring-the-ios-sdk-1st-edition-david-mark/

ebookname.com

Beginning iPhone Development with Swift 3 Exploring the


iOS SDK 3rd ed. Edition Maskrey

https://ebookname.com/product/beginning-iphone-development-with-
swift-3-exploring-the-ios-sdk-3rd-ed-edition-maskrey/

ebookname.com

Beginning iPhone 3 Development Exploring the iPhone SDK


1st Edition David Mark

https://ebookname.com/product/beginning-iphone-3-development-
exploring-the-iphone-sdk-1st-edition-david-mark/

ebookname.com

Paradigms of Combinatorial Optimization 2nd Edition


Problems and New Approaches Paschos

https://ebookname.com/product/paradigms-of-combinatorial-
optimization-2nd-edition-problems-and-new-approaches-paschos/

ebookname.com
Municipal Solid Waste to Energy Conversion Processes
Economic Technical and Renewable Comparisons 1st Edition
Gary C Young
https://ebookname.com/product/municipal-solid-waste-to-energy-
conversion-processes-economic-technical-and-renewable-comparisons-1st-
edition-gary-c-young/
ebookname.com

Update on Troubleshooting the PVC Extrusion Process 1st


Edition Subramanian

https://ebookname.com/product/update-on-troubleshooting-the-pvc-
extrusion-process-1st-edition-subramanian/

ebookname.com

Frommer s California 2008 Frommer s Complete Harry Basch

https://ebookname.com/product/frommer-s-california-2008-frommer-s-
complete-harry-basch/

ebookname.com

Roman Villas in Central Italy A Social and Economic


History Annalisa Marzano

https://ebookname.com/product/roman-villas-in-central-italy-a-social-
and-economic-history-annalisa-marzano/

ebookname.com

Primary Care Geriatrics A Case Based Approach 5th Edition


Richard J. Ham Md

https://ebookname.com/product/primary-care-geriatrics-a-case-based-
approach-5th-edition-richard-j-ham-md/

ebookname.com
Chinese Journalist 1st Edition Hugo De Burgh

https://ebookname.com/product/chinese-journalist-1st-edition-hugo-de-
burgh/

ebookname.com
Beginning iOS 5
Development
Exploring the iOS SDK

■■■

Dave Mark
Jack Nutting
Jeff LaMarche

i
Beginning iOS 5 Development: Exploring the iOS SDK
Copyright © 2011 by Dave Mark, Jack Nutting, Jeff LaMarche
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed. Exempted from this
legal reservation are brief excerpts in connection with reviews or scholarly analysis or material
supplied specifically for the purpose of being entered and executed on a computer system, for
exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is
permitted only under the provisions of the Copyright Law of the Publisher's location, in its
current version, and permission for use must always be obtained from Springer. Permissions for
use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable
to prosecution under the respective Copyright Law.
ISBN-13 (pbk): 978-1-4302-3605-4
ISBN-13 (electronic): 978-1-4302-3606-1
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
President and Publisher: Paul Manning
Lead Editor: Tom Welsh
Technical Reviewer: Mark Dalrymple
Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Morgan Ertel,
Jonathan Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman,
James Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben
Renow-Clarke, Dominic Shakeshaft, Gwenan Spearing, Matt Wade, Tom Welsh
Coordinating Editor: Kelly Moritz
Copy Editor: Marilyn Smith
Compositor: MacPS, LLC
Indexer: BIM Indexing & Proofreading Services
Artist: SPi Global
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233
Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com, or visit www.springeronline.com.
For information on translations, please e-mail rights@apress.com, or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or
promotional use. eBook versions and licenses are also available for most titles. For more
information, reference our Special Bulk Sales–eBook Licensing web page at
www.apress.com/bulk-sales.
Any source code or other supplementary materials referenced by the author in this text is
available to readers at www.apress.com. For detailed information about how to locate your book’s
source code, go to www.apress.com/source-code/.
This book is dedicated to the memory of Steve Jobs.
We continue to be inspired by his spirit and his vision.
Contents at a Glance

Contents .............................................................................................................. v
About the Authors .............................................................................................xiv
About the Technical Reviewer ...........................................................................xv
Acknowledgments ............................................................................................xvi
Preface ............................................................................................................xvii
■Chapter 1: Welcome to the Jungle .................................................................. 1
■Chapter 2: Appeasing the Tiki Gods .............................................................. 13
■Chapter 3: Handling Basic Interaction........................................................... 45
■Chapter 4: More User Interface Fun .............................................................. 69
■Chapter 5: Autorotation and Autosizing ...................................................... 113
■Chapter 6: Multiview Applications .............................................................. 133
■Chapter 7: Tab Bars and Pickers ................................................................. 163
■Chapter 8: Introduction to Table Views ....................................................... 217
■Chapter 9: Navigation Controllers and Table Views .................................... 277
■Chapter 10: Storyboards ............................................................................. 353
■Chapter 11: iPad Considerations ................................................................. 381
■Chapter 12: Application Settings and User Defaults.................................... 407
■Chapter 13: Basic Data Persistence ............................................................ 445
■Chapter 14: Hey! You! Get onto iCloud! ....................................................... 493
■Chapter 15: Grand Central Dispatch, Background Processing, and You ..... 525
■Chapter 16: Drawing with Quartz and OpenGL ............................................ 563
■Chapter 17: Taps, Touches, and Gestures ................................................... 603
■Chapter 18: Where Am I? Finding Your Way with Core Location ................. 633
■Chapter 19: Whee! Gyro and Accelerometer! .............................................. 645
■Chapter 20: The Camera and Photo Library ................................................ 673
■Chapter 21: Application Localization........................................................... 685
■Chapter 22: Where to Next?......................................................................... 705
Index ............................................................................................................... 711

iv
Contents

Contents at a Glance .......................................................................................... iv


About the Authors .............................................................................................xiv
About the Technical Reviewer ...........................................................................xv
Acknowledgments ............................................................................................xvi
Preface ............................................................................................................xvii

■Chapter 1: Welcome to the Jungle .................................................................. 1


What This Book Is ...................................................................................................................................................1
What You Need .......................................................................................................................................................1
Developer Options ..............................................................................................................................................3
What You Need to Know ....................................................................................................................................4
What’s Different About Coding for iOS? ..................................................................................................................5
Only One Active Application ...............................................................................................................................6
Only One Window ...............................................................................................................................................6
Limited Access ...................................................................................................................................................6
Limited Response Time......................................................................................................................................6
Limited Screen Size ...........................................................................................................................................7
Limited System Resources ................................................................................................................................7
No Garbage Collection, but… ............................................................................................................................8
Some New Stuff .................................................................................................................................................8
A Different Approach..........................................................................................................................................8
What’s in This Book ................................................................................................................................................9
What’s New in This Update? .................................................................................................................................11
Are You Ready? .....................................................................................................................................................11
■Chapter 2: Appeasing the Tiki Gods .............................................................. 13
Setting Up Your Project in Xcode ..........................................................................................................................13
The Xcode Workspace Window ........................................................................................................................18
A Closer Look at Our Project ............................................................................................................................28
Introducing Xcode’s Interface Builder ...................................................................................................................30
What’s in the Nib File? .....................................................................................................................................32
The Library .......................................................................................................................................................33
Adding a Label to the View ..............................................................................................................................34
Changing Attributes .........................................................................................................................................37
v
■ CONTENTS

Some iPhone Polish—Finishing Touches .............................................................................................................39


Bring It on Home ...................................................................................................................................................44
■Chapter 3: Handling Basic Interaction........................................................... 45
The Model-View-Controller Paradigm ...................................................................................................................46
Creating Our Project..............................................................................................................................................47
Looking at the View Controller ..............................................................................................................................48
Understanding Outlets and Actions..................................................................................................................49
Cleaning Up the View Controller ......................................................................................................................51
Designing the User Interface ...........................................................................................................................52
Trying It Out .....................................................................................................................................................64
Looking at the Application Delegate .....................................................................................................................64
Bring It on Home ...................................................................................................................................................68
■Chapter 4: More User Interface Fun .............................................................. 69
A Screen Full of Controls ......................................................................................................................................69
Active, Static, and Passive Controls......................................................................................................................72
Creating the Application .......................................................................................................................................73
Implementing the Image View and Text Fields .....................................................................................................74
Adding the Image View ....................................................................................................................................74
Resizing the Image View ..................................................................................................................................77
Setting View Attributes ....................................................................................................................................79
Adding the Text Fields .....................................................................................................................................82
Creating and Connecting Outlets .....................................................................................................................89
Closing the Keyboard ............................................................................................................................................91
Closing the Keyboard When Done Is Tapped ...................................................................................................91
Touching the Background to Close the Keyboard ............................................................................................93
Adding the Slider and Label .............................................................................................................................95
Creating and Connecting the Actions and Outlets ...........................................................................................97
Implementing the Action Method .....................................................................................................................98
Implementing the Switches, Button, and Segmented Control ..............................................................................98
Implementing the Switch Actions ..................................................................................................................102
Implementing the Segmented Control Action .....................................................................................................105
Implementing the Action Sheet and Alert ...........................................................................................................105
Conforming to the Action Sheet Delegate Method .........................................................................................106
Showing the Action Sheet ..............................................................................................................................106
Spiffing Up the Button .........................................................................................................................................109
Using the viewDidLoad Method .....................................................................................................................110
Control States ................................................................................................................................................111
Stretchable Images ........................................................................................................................................111
Crossing the Finish Line......................................................................................................................................112
■Chapter 5: Autorotation and Autosizing ...................................................... 113
The Mechanics of Autorotation ...........................................................................................................................114
Points, Pixels, and the Retina Display ............................................................................................................114
Autorotation Approaches ...............................................................................................................................115
Handling Rotation Using Autosize Attributes ......................................................................................................115
Configuring Supported Orientations...............................................................................................................116
Specifying Rotation Support ..........................................................................................................................117
Designing an Interface with Autosize Attributes ............................................................................................118

vi
■ CONTENTS

Using the Size Inspector’s Autosize Attributes ..............................................................................................120


Setting the Buttons’ Autosize Attributes ........................................................................................................122
Restructuring a View When Rotated ...................................................................................................................123
Creating and Connecting Outlets ...................................................................................................................125
Moving the Buttons on Rotation .....................................................................................................................125
Swapping Views .................................................................................................................................................126
Designing the Two Views ...............................................................................................................................128
Implementing the Swap .................................................................................................................................130
Changing Outlet Collections ...........................................................................................................................131
Rotating Out of Here ...........................................................................................................................................132
■Chapter 6: Multiview Applications .............................................................. 133
Common Types of Multiview Apps ......................................................................................................................133
The Architecture of a Multiview Application .......................................................................................................138
The Root Controller ........................................................................................................................................141
Anatomy of a Content View ............................................................................................................................142
Building View Switcher .......................................................................................................................................142
Creating Our View Controller and Nib Files ....................................................................................................144
Modifying the App Delegate ...........................................................................................................................146
Modifying BIDSwitchViewController.h ...........................................................................................................148
Adding a View Controller ...............................................................................................................................148
Building a View with a Toolbar ......................................................................................................................150
Writing the Root View Controller ....................................................................................................................152
Implementing the Content Views ...................................................................................................................156
Animating the Transition ................................................................................................................................159
Switching Off ......................................................................................................................................................161
■Chapter 7: Tab Bars and Pickers ................................................................. 163
The Pickers Application ......................................................................................................................................164
Delegates and Data Sources ...............................................................................................................................169
Setting Up the Tab Bar Framework .....................................................................................................................170
Creating the Files ...........................................................................................................................................171
Adding the Root View Controller ....................................................................................................................172
Creating TabBarController.xib ........................................................................................................................173
The Initial Test Run ........................................................................................................................................181
Implementing the Date Picker ............................................................................................................................182
Implementing the Single-Component Picker ......................................................................................................186
Declaring Outlets and Actions ........................................................................................................................186
Building the View ...........................................................................................................................................187
Implementing the Controller As a Data Source and Delegate ........................................................................188
Implementing a Multicomponent Picker .............................................................................................................192
Declaring Outlets and Actions ........................................................................................................................193
Building the View ...........................................................................................................................................193
Implementing the Controller ..........................................................................................................................194
Implementing Dependent Components ...............................................................................................................196
Creating a Simple Game with a Custom Picker ..................................................................................................203
Writing the Controller Header File ..................................................................................................................203
Building the View ...........................................................................................................................................204
Adding Image Resources ...............................................................................................................................205

vii
■ CONTENTS

Implementing the Controller ..........................................................................................................................205


Final Details ...................................................................................................................................................210
Linking in the Audio Toolbox Framework.......................................................................................................214
Final Spin ............................................................................................................................................................215
■Chapter 8: Introduction to Table Views ....................................................... 217
Table View Basics ...............................................................................................................................................218
Table Views and Table View Cells..................................................................................................................218
Grouped and Plain Tables ..............................................................................................................................220
Implementing a Simple Table .............................................................................................................................221
Designing the View ........................................................................................................................................221
Writing the Controller .....................................................................................................................................222
Adding an Image ............................................................................................................................................226
Using Table View Cell Styles ..........................................................................................................................228
Setting the Indent Level .................................................................................................................................230
Handling Row Selection .................................................................................................................................231
Changing the Font Size and Row Height ........................................................................................................233
Customizing Table View Cells .............................................................................................................................235
Adding Subviews to the Table View Cell ........................................................................................................236
Creating a UITableViewCell Subclass.............................................................................................................237
Loading a UITableViewCell from a Nib ...........................................................................................................242
Grouped and Indexed Sections ...........................................................................................................................248
Building the View ...........................................................................................................................................248
Importing the Data .........................................................................................................................................248
Implementing the Controller ..........................................................................................................................249
Adding an Index .............................................................................................................................................254
Implementing a Search Bar ................................................................................................................................255
Rethinking the Design ....................................................................................................................................255
A Deep Mutable Copy .....................................................................................................................................256
Updating the Controller Header File ...............................................................................................................258
Modifying the View ........................................................................................................................................259
Modifying the Controller Implementation ......................................................................................................264
Putting It All on the Table ....................................................................................................................................276
■Chapter 9: Navigation Controllers and Table Views .................................... 277
Navigation Controller Basics ...............................................................................................................................277
Stacky Goodness ...........................................................................................................................................278
A Stack of Controllers ....................................................................................................................................278
Nav, a Hierarchical Application in Six Parts ........................................................................................................280
Meet the Subcontrollers ................................................................................................................................280
The Nav Application’s Skeleton .....................................................................................................................286
Adding the Images to the Project ...................................................................................................................294
First Subcontroller: The Disclosure Button View ...........................................................................................295
Second Subcontroller: The Checklist .............................................................................................................304
Third Subcontroller: Controls on Table Rows .................................................................................................310
Fourth Subcontroller: Movable Rows .............................................................................................................317
Fifth Subcontroller: Deletable Rows ..............................................................................................................324
Sixth Subcontroller: An Editable Detail Pane .................................................................................................330

viii
■ CONTENTS

But There’s One More Thing. . . .....................................................................................................................349


Breaking the Tape ...............................................................................................................................................352
■Chapter 10: Storyboards ............................................................................. 353
Creating a Simple Storyboard .............................................................................................................................354
Dynamic Prototype Cells .....................................................................................................................................358
Dynamic Table Content, Storyboard-Style .....................................................................................................358
Editing Prototype Cells ...................................................................................................................................359
Good Old Table View Data Source..................................................................................................................361
Will It Load? ...................................................................................................................................................363
Static Cells ..........................................................................................................................................................364
Going Static....................................................................................................................................................365
So Long, Good Old Table View Data Source ...................................................................................................366
You Say Segue, I Say Segue ...............................................................................................................................367
Creating Segue Navigator ..............................................................................................................................368
Filling the Blank Slate ....................................................................................................................................369
First Transition ...............................................................................................................................................372
A Slightly More Useful Task List ....................................................................................................................372
Viewing Task Details ......................................................................................................................................373
Make More Segues, Please ...........................................................................................................................374
Passing a Task from the List..........................................................................................................................374
Handling Task Details ....................................................................................................................................376
Passing Back Details .....................................................................................................................................377
Making the List Receive the Details...............................................................................................................378
If Only We Could End with a Smooth Transition .............................................................................................379
■Chapter 11: iPad Considerations ................................................................. 381
Split Views and Popovers ...................................................................................................................................381
Creating a SplitView Project ..........................................................................................................................383
The Storyboard Defines the Structure ...........................................................................................................385
The Code Defines the Functionality ...............................................................................................................387
Here Come the Presidents ..................................................................................................................................394
Creating Your Own Popover ................................................................................................................................401
iPad Wrap-Up ......................................................................................................................................................406
■Chapter 12: Application Settings and User Defaults.................................... 407
Getting to Know Your Settings Bundle ................................................................................................................407
The AppSettings Application ...............................................................................................................................410
Creating the Project .......................................................................................................................................414
Working with the Settings Bundle .................................................................................................................415
Reading Settings in Our Application ..............................................................................................................431
Registering Default Values .............................................................................................................................436
Changing Defaults from Our Application ........................................................................................................437
Keeping It Real ...............................................................................................................................................440
Beam Me Up, Scotty ...........................................................................................................................................443
■Chapter 13: Basic Data Persistence ............................................................ 445
Your Application’s Sandbox ................................................................................................................................446
Getting the Documents Directory ...................................................................................................................447
Getting the tmp Directory...............................................................................................................................448
File-Saving Strategies.........................................................................................................................................448
ix
■ CONTENTS

Single-File Persistence ..................................................................................................................................448


Multiple-File Persistence ...............................................................................................................................449
Using Property Lists ............................................................................................................................................449
Property List Serialization ..............................................................................................................................449
The First Version of the Persistence Application ...........................................................................................451
Archiving Model Objects .....................................................................................................................................456
Conforming to NSCoding ................................................................................................................................457
Implementing NSCopying ..............................................................................................................................458
Archiving and Unarchiving Data Objects ........................................................................................................459
The Archiving Application ..............................................................................................................................460
Using iOS’s Embedded SQLite3 ..........................................................................................................................463
Creating or Opening the Database .................................................................................................................464
Using Bind Variables ......................................................................................................................................466
The SQLite3 Application .................................................................................................................................467
Using Core Data ..................................................................................................................................................473
Entities and Managed Objects .......................................................................................................................475
The Core Data Application .............................................................................................................................479
Persistence Rewarded ........................................................................................................................................491
■Chapter 14: Hey! You! Get onto iCloud! ....................................................... 493
Managing Document Storage with UIDocument .................................................................................................494
Building TinyPix .............................................................................................................................................494
Creating BIDTinyPixDocument .......................................................................................................................495
Code Master ...................................................................................................................................................499
Initial Storyboarding.......................................................................................................................................505
Creating BIDTinyPixView ................................................................................................................................508
Storyboard Detailing ......................................................................................................................................513
Adding iCloud Support ........................................................................................................................................516
Creating a Provisioning Profile .......................................................................................................................517
Enabling iCloud Entitlements .........................................................................................................................518
How to Query .................................................................................................................................................518
Save Where? ..................................................................................................................................................520
Storing Preferences on iCloud .......................................................................................................................521
What We Didn’t Cover .........................................................................................................................................522
■Chapter 15: Grand Central Dispatch, Background Processing, and You ..... 525
Grand Central Dispatch .......................................................................................................................................525
Introducing SlowWorker .....................................................................................................................................526
Threading Basics ................................................................................................................................................530
Units of Work ......................................................................................................................................................531
GCD: Low-Level Queueing ..................................................................................................................................531
Becoming a Blockhead ..................................................................................................................................532
Improving SlowWorker ..................................................................................................................................533
Background Processing ......................................................................................................................................539
Application Life Cycle.....................................................................................................................................541
State-Change Notifications ............................................................................................................................541
Creating State Lab .........................................................................................................................................543
Exploring Execution States ............................................................................................................................544
Making Use of Execution State Changes .......................................................................................................546

x
■ CONTENTS

Handling the Inactive State ............................................................................................................................547


Handling the Background State .....................................................................................................................552
Grand Central Dispatch, Over and Out ................................................................................................................562
■Chapter 16: Drawing with Quartz and OpenGL ............................................ 563
Two Views of a Graphical World .........................................................................................................................563
The Quartz 2D Approach to Drawing ...................................................................................................................564
Quartz 2D’s Graphics Contexts ......................................................................................................................565
The Coordinate System ..................................................................................................................................566
Specifying Colors ...........................................................................................................................................567
Drawing Images in Context ............................................................................................................................569
Drawing Shapes: Polygons, Lines, and Curves ..............................................................................................569
Quartz 2D Tool Sampler: Patterns, Gradients, and Dash Patterns .................................................................570
The QuartzFun Application ..................................................................................................................................572
Setting Up the QuartzFun Application ............................................................................................................572
Adding Quartz 2D Drawing Code ....................................................................................................................584
Optimizing the QuartzFun Application............................................................................................................589
The GLFun Application ........................................................................................................................................592
Setting Up the GLFun Application ..................................................................................................................593
Creating BIDGLFunView .................................................................................................................................594
Updating BIDViewController ...........................................................................................................................601
Updating the Nib ............................................................................................................................................602
Finishing GLFun .............................................................................................................................................602
Drawing to a Close ..............................................................................................................................................602
■Chapter 17: Taps, Touches, and Gestures ................................................... 603
Multitouch Terminology ......................................................................................................................................604
The Responder Chain ..........................................................................................................................................604
Responding to Events ....................................................................................................................................605
Forwarding an Event: Keeping the Responder Chain Alive ............................................................................606
The Multitouch Architecture ...............................................................................................................................606
The Four Touch Notification Methods .................................................................................................................607
The TouchExplorer Application ...........................................................................................................................608
The Swipes Application.......................................................................................................................................613
Automatic Gesture Recognition .....................................................................................................................616
Implementing Multiple Swipes ......................................................................................................................618
Detecting Multiple Taps ......................................................................................................................................620
Detecting Pinches ...............................................................................................................................................625
Defining Custom Gestures ..................................................................................................................................627
The CheckPlease Application .........................................................................................................................628
The CheckPlease Touch Methods ..................................................................................................................630
Garçon? Check, Please! ......................................................................................................................................632
■Chapter 18: Where Am I? Finding Your Way with Core Location ................. 633
The Location Manager ........................................................................................................................................634
Setting the Desired Accuracy ........................................................................................................................634
Setting the Distance Filter .............................................................................................................................634
Starting the Location Manager ......................................................................................................................635
Using the Location Manager Wisely ...............................................................................................................635
The Location Manager Delegate .........................................................................................................................635

xi
■ CONTENTS

Getting Location Updates ...............................................................................................................................636


Getting Latitude and Longitude Using CLLocation .........................................................................................636
Error Notifications ..........................................................................................................................................638
Trying Out Core Location ....................................................................................................................................639
Updating Location Manager ...........................................................................................................................643
Determining Distance Traveled ......................................................................................................................644
Wherever You Go, There You Are ........................................................................................................................644
■Chapter 19: Whee! Gyro and Accelerometer! .............................................. 645
Accelerometer Physics .......................................................................................................................................645
Don’t Forget Rotation ..........................................................................................................................................646
Core Motion and the Motion Manager ................................................................................................................647
Event-Based Motion .......................................................................................................................................647
Proactive Motion Access ................................................................................................................................653
Accelerometer Results ...................................................................................................................................655
Detecting Shakes ................................................................................................................................................656
Baked-In Shaking ..........................................................................................................................................657
Shake and Break ............................................................................................................................................658
Accelerometer As Directional Controller .............................................................................................................664
Rolling Marbles ..............................................................................................................................................664
Writing the Ball View ......................................................................................................................................666
Calculating Ball Movement ............................................................................................................................669
Rolling On............................................................................................................................................................672
■Chapter 20: The Camera and Photo Library ................................................ 673
Using the Image Picker and UIImagePickerController ........................................................................................673
Implementing the Image Picker Controller Delegate ..........................................................................................675
Road Testing the Camera and Library.................................................................................................................677
Designing the Interface ..................................................................................................................................679
Implementing the Camera View Controller ....................................................................................................679
It’s a Snap! ..........................................................................................................................................................684
■Chapter 21: Application Localization........................................................... 685
Localization Architecture ....................................................................................................................................685
Strings Files ........................................................................................................................................................687
What’s in a Strings File? ................................................................................................................................687
The Localized String Macro ...........................................................................................................................688
Real-World iOS: Localizing Your Application .......................................................................................................688
Setting Up LocalizeMe ...................................................................................................................................689
Trying Out LocalizeMe ...................................................................................................................................693
Localizing the Nib ..........................................................................................................................................694
Localizing an Image .......................................................................................................................................698
Generating and Localizing a Strings File .......................................................................................................701
Localizing the App Display Name...................................................................................................................703
Auf Wiedersehen .................................................................................................................................................704
■Chapter 22: Where to Next?......................................................................... 705
Apple’s Documentation .......................................................................................................................................705
Mailing Lists ........................................................................................................................................................706
Discussion Forums..............................................................................................................................................706
Web Sites ............................................................................................................................................................707
xii
■ CONTENTS

Blogs ...................................................................................................................................................................708
Conferences ........................................................................................................................................................708
Follow the Authors ..............................................................................................................................................710
Farewell ..............................................................................................................................................................710
Index ............................................................................................................... 711

xiii
About the Authors

Dave Mark is a longtime Mac developer and author, who has written a number
of books on Mac and iOS development, including Beginning iPhone 4
Development (Apress, 2011), More iPhone 3 Development (Apress, 2010), Learn
C on the Mac (Apress, 2008), Ultimate Mac Programming (Wiley, 1995), and
The Macintosh Programming Primer series (Addison-Wesley, 1992). Dave was
one of the founders of MartianCraft, an iOS and Android development house.
Dave loves the water and spends as much time as possible on it, in it, or near it.
He lives with his wife and three children in Virginia.

Jack Nutting has been using Cocoa since the olden days, long before it was
even called Cocoa. He has used Cocoa and its predecessors to develop software
for a wide range of industries and applications, including gaming, graphic
design, online digital distribution, telecommunications, finance, publishing,
and travel. When he is not working on Mac or iOS projects, he is developing
web applications with Ruby on Rails. Jack is a passionate proponent of
Objective-C and the Cocoa frameworks. At the drop of a hat, he will speak at
length on the virtues of dynamic dispatch and runtime class manipulations to
anyone who will listen (and even to some who won’t). Jack has written several
books on iOS and Mac development, including Beginning iPhone 4
Development (Apress, 2011), Learn Cocoa on the Mac (Apress, 2010), and Beginning iPad
Development for iPhone Developers (Apress, 2010). He blogs from time to time at
www.nuthole.com.

Jeff LaMarche is a Mac and iOS developer with more than 20 years of
programming experience. Jeff has written a number of iOS and Mac
development books, including Beginning iPhone 4 Development (Apress, 2011),
More iPhone 3 Development (Apress, 2010), and Learn Cocoa on the Mac
(Apress, 2010). Jeff is a principal at MartianCraft, an iOS and Android
development house. He has written about Cocoa and Objective-C for MacTech
Magazine, as well as articles for Apple’s developer web site. Jeff also writes
about iOS development for his widely read blog at
www.iphonedevelopment.blogspot.com.

xiv
Another Random Document on
Scribd Without Any Related Topics
"And be sent back to Dublin for me stepfather to kill
me! Oh, musha! Thank you, but I won't do that if the water
in these parts can drown me. Do you mind the way I was in
when you took me on first?"

"I do; but where is the use of talking?" Avery said


angrily. "I'm sorry for you, but I can't help you. Roger's got
the place, and does the work better than you did."

"But," said Roger, "I'll go, all the same; if you'll take
Deasy back, I'll go. I've saved money enough to set me
going. I see a real good chance of getting on here; I'd
rather go, anyhow, than stand in his way."

Avery looked hard at him—then shouted, "Jack Sparling,


come here."

And Jack left his work and came.

"Look here, Jack. Young Deasy has come back, and, as


you may see, he hasn't been making his fortune since he
left us. He wants to get his place again, and I thought Roger
was the lad to stick to it when he had it; but Roger says he
will give up and won't stand in Deasy's way. Now the boy
learned that kind of talk from you, Jack, so I just called you
to see what you'd say."
Jack nodded and looked at Roger, who said,—

"'Do unto others as you would that they should


do to you,'

"That's plain enough."

"You may never get such another chance," put in Avery,


who looked annoyed.
"That's just it," said Roger, still speaking to Sparling.
"I've been all for No. 1 as long as I can remember. I'm
never likely to be able to do much, but here's a chance, I
may do something. If I don't do it, I suppose it would just
show that I'm not in real earnest. And don't be afraid for
me, Jack. I have a plan, and I've saved enough to set it
going. I shall do very fairly."

"Ay, lad," said Jack. And he stretched out a grimy paw


and gave Roger's equally grimy paw a hearty shake, and
then turned and walked back to his work.

Avery broke into a laugh, in which there was a queer


mixture of unwilling admiration and annoyance.

"It's well for you, Roger, I do believe, that you'll be


parted from him, he's making you as great a fool as he is
himself; but there, you'll say you wish to be just such
another, I suppose. All I have to say is,—Remember, if you
give it up, you must stand by what you've done; I won't
allow another change."

And Avery walked off.

"You be off now," said Roger to Deasy. "Here's sixpence,


go and get some food, and come to work in the morning."

Deasy, who had passed the last ten minutes in staring


hard at every one in turn, now stared harder than ever at
Roger. Finally, his face began to work, and big tears ran
down his dirty cheeks, making strange tracks of whiteness
in the grey tint his countenance presented.

"Roger—Roger Read! I'm—not good at saying it—but I


feel it, I do! I'll never forget—"
Here Roger was loudly called by half a dozen voices at
once.

"Go," said he, "I have no time to talk now;" and when
he came back Deasy was gone, to his great contentment.

That evening, when the men left work, Roger unfolded


his plan to his friend Sparling, who pronounced it a good
one, but said that if it did not succeed, Roger was to write
to him at an address in Birmingham, and he would get a
friend to answer the letter and send him money to come to
Birmingham, where he thought so handy a fellow would
surely get work.

Among the other men, particularly the younger ones,


Roger's decision about his place was much spoken of, some
calling it an act of folly, some admiring it. Avery told his
wife privately that he was rather glad, for that one saint
was enough! But between Sparling and Roger very little was
said on the subject. Very unlike in most things, they were
alike in this—they were honestly in earnest in their
endeavour to be like their Master. To Sparling, Roger's act
seemed natural under the circumstances, though he was
sorry that the lad had exchanged a certainty for a chance.
In a few days the workmen returned to Birmingham, and
Roger was left alone.

At first, he felt very lonely, but he was soon far too busy
to think about it, though he missed Jack Sparling very
much, and regretted greatly that his friend could not write.
He began to carry out his cherished plan at once. In fact,
the first day that the train began to run regularly between
Kingsmore and Sandsea, Roger, with a huge basket filled
with fine fish, was one of the first third-class passengers.
He saw with satisfaction that none of the owners of the
original baskets and carts seemed to have thought of
leaving their old beats.

He had found out that no fish was brought to Kingsmore


regularly, and, to use his own words, "to be first in the field
was half the battle, and this was a fine chance." First in the
field he surely was; and before one o'clock he had sold
every fish in his basket at good prices. And he returned to
Sandsea, to be ready for the morning boats, a proud and
happy lad.

"If I could only tell Jack!" he said.

And now time passed rapidly with Roger for though his
work was not exactly hard, it required him to be always on
the alert, and to be at the place where the boats came in
very early. After a time, others set up baskets to convey
fish to Kingsmore, finding the prices there better than at
Sandsea. Then, indeed, Roger had a rather anxious time for
they tried to undersell him; but after a few days, he found
that most of his customers waited for him, saying that he
always gave them good fish, and never tried to cheat. He
went on making money steadily; in fact, his savings
presently amounted to so considerable a sum that his
common sense told him he ought not to carry it about with
him, even though he had sewed it up in a piece of stout
leather, and the leather in a piece of calico, and wore it tied
to a piece of cord round his neck.

All this time Roger attended church regularly at


Sandsea, where he always slept and spent his Sundays. He
now rented the room he had once shared with Sparling; and
here he kept his few belongings and his Bible, which he still
studied, and still longed to understand better. Many a kind
action too, known only to himself and those he helped,
Roger did; and Jack Sparling would have felt satisfied if he
could have seen how the lad he was so fond of was living.

But Roger, a far more intelligent fellow than Jack, felt


his ignorance weigh very heavily on him, and often longed
for "a chance" of learning many things—to understand his
Bible, to write a fair hand, and to learn arithmetic. He was
clever at figures, and could calculate the price of a fish
when he sold by weight, well enough; but as he aspired to
rise in life, he felt that he ought to know how to keep
accounts.

A year and some months went by, and Roger began to


feel sure that he could sell more fish than he could carry,
even if the basket were yet woven of willow that would
contain them: in fact, he knew, to use his own words, that
he was losing chances, and to lose a chance went to his
heart.

One afternoon he was going up Cecil Street towards the


railway station with his empty basket, when an adventure
befel him which proved of some importance. He saw a
neatly dressed little girl with pretty curly hair, kneeling on
the pavement beside a rusty grating which admitted the
light to a small window below. The child resisted every
effort to get her out of the way, holding on to the bars and
screaming dismally. Every one seemed in a hurry, for a train
to Sandsea was just about to leave, and many Kingsmore
people had lodgings in Sandsea that year, going out there in
the afternoon.

Roger stooped over the child and said,—

"What's the matter, you poor little thing? Stop crying


and tell me, and I'll help you."
"My shilling, my new bright shilling that father gave
me."

"Well, where is it?" said Roger.

"It went down there! Father gave it to me, to buy a


wooden spade and a tub, for we're going to Sandsea, you
know, and I want to dig like the others; and he bid me keep
it in my pocket, but I took it out to look at it, and some one
hit my elbow, and it fell, and it rolled along, and I—and it
went down there!"

"Well now, you dry your eyes and never fear, we'll get
the shilling. Why, it's the shut up house—and the train will
be gone. Never mind, I can go by the late one for once.
Come along, missy, till I find out who has the key of this
house. Your shilling is safe enough, for no one can get at
it."

He entered the shop next door, a baker's shop, where


Roger was well known; and fortunately it turned out that
the baker had the key himself, and he at once handed it to
Roger.

With the little girl confidently holding his hand, Roger


unlocked the door, and saw before him a narrow passage,
with a door at the side which opened into the shop. But the
place was so dark that the little girl would not enter it, and
Roger could see no way of descending to the basement
storey. He groped his way to the window, and, after much
fumbling, found that the shutters were outside—a fact
which he ought to have remembered, for he was quite
familiar with the look of the house. Out he went, and having
with difficulty removed the heavy bar, he took down one
shutter.
Then the light showed him a small shop, and behind the
counter, he found a flight of steps going down to the lower
storey. Down he went, groped about in darkness, and found
a little door by which he could get out into the area; so he
ran back for the little girl, and they went out together.

But at first, the shilling could not be found, and the


child was almost in despair, when Roger's keen eyes caught
a glimmer from something bright, and with a shout, he
pounced upon the coin. The child set up a joyful cry,
whereupon a voice from above called aloud,—

"Mary! That's certainly Mary's voice—Where are you,


child?"

"That's father. Oh, look, what fun! He's walking over our
heads! Father, father—I'm here in this hole."

"Why, how on earth did you get there?" exclaimed the


man on the pavement, gazing down at his little daughter in
great amazement.

"Wait one moment, and I'll come to you," said the child.

Roger let her go, but he stayed to close up the door and
window, and then followed. He found her at the door, telling
her story as fast as her little tongue could wag, to a well-
dressed man without a hat, who seemed greatly relieved at
having found her.

"And I should never, never, have seen my shilling again,


only for him. He said he'd find it, and he did find it; and he
was so kind, father, and I was just mis'able."

"Why, Read! Is it you?" and Roger recognised Mr.


Wilson, who kept the Post Office and had a fine shop, where
he carried on business as a bookseller and stationer.
"I am greatly obliged to you. It was very kind of you to
waste your time helping my careless little woman here. Her
mother missed her from the door, and was so frightened
that I had to be off without my hat to search for her. She
can't pay me visits in the shop, if she runs off like this."

"I didn't want to run off, indeed! I wanted to look in the


window at the spades and pails."

"Well, you came the wrong way, You little goose. Come
now, let us get home. Thank you, Read—look in with your
basket in the morning."

"Yes, sir," said Roger absently; he was in deep thought,


and hardly heard what Mr. Wilson said. As soon as he was
alone, he took down a second shutter and examined the
shop. It was very dirty, it wanted painting badly, and the
woodwork was broken and defaced. Roger looked carefully
at everything. Behind the shop there was a tiny room,
upstairs there were two rooms, and below there was a good
kitchen and a little back yard, all much in need of repair and
very dirty.

"I wonder why it is not let; but as it is now, it ought to


go cheap," said Roger, standing once more in the shop.
"Here's a chance; I can only try."

And having shut up the house carefully, he went back to


the baker with the key.

CHAPTER IV.
ROGER READ, FISHMONGER.

"IF you please, Mr. Allen, can you tell me anything


about the shop next door? It has been empty as long as
I've been coming to Kingsmore, and yet it is in a good
situation."

"It has been empty longer than that," said Mr. Allen,
taking back the key. "Did you find the shilling?"

"Yes, sir."

"Then old Rider's ghost ain't quite as sharp as old Rider


when alive," said the baker with a chuckle. "You want to
know why that shop stands empty?"

He looked out and saw that no one was coming in just


then, so he disposed himself for a chat. Busying himself in
arranging the buns on his counter, their fair array having
been much diminished since morning, he went on.

"It's a queer story, and many folk laugh at it; and for
my part I've lived next door for years and never saw
anything. I've heard noises, but laid them to the rats. Rats
are restless beasts, and it stands to reason that they'll
scamper about an empty house for diversion; when they
mean business, they come to me, worse, luck."

However interesting the natural history of rats from Mr.


Allen's point of view might be, Roger would much rather
have heard the history of the house; but he knew that there
was no use in trying to hurry Mr. Allen, who would stand
half an hour in discussing the merits of the basket of fish,
and end by buying a herring or a small whiting.
Still, the last train to Sandsea must not go without him,
so he kept an eye on the baker's clock and waited as
patiently as he could.

"They say that it's haunted, you know," resumed Mr.


Allen.

"By what?" asked Roger.

"Naturally, by a ghost. Old Rider, the last owner, the last


who lived there at least, was found dead in his bed one day.
And the servant, a girl from the workhouse, had robbed the
till, and off she went, and was never caught to this day. And
she won't be now, for that happened fifteen or sixteen years
ago. Then a tailor—stop though, I forgot. Old Rider left a
heap of money, though I do believe that a shilling a day
would have paid his expenses; and his heir was a young
lawyer in London, and he didn't want the shop."

"So then a tailor took it?"

"A tailor, a mite of a man, with a face like a half-baked


roll," said the baker professionally. "And having been there
a month, he gave it up and moved at great expense—said
he couldn't stand the behaviour of old Rider, creeping up
and down the stairs counting his money all night. He said
he heard the chink of the money. Mind you, I say, rats!"

He did say "rats," and that with such energy that his
little terrier, peacefully dozing under the counter, sprang up
barking like a dog possessed, and flew at Roger, under the
impression that he was a rat in disguise. He was ashamed
of himself at once, for he and Roger were friends, and
retired, with a reproachful glance at his master.

The worst of this incident was, that Mr. Allen had to tell
many anecdotes, all indicating Chip's superior pluck and
wisdom, before he would return to the next door house.
However, Roger at last discovered that a milliner and
dressmaker had also given up the house because the old
man would go up and down the stairs and count his money;
also a fancy stationer. In fact, the shop, after changing
hands many times and getting into very low hands, had
been shut up, young Mr. Rider giving the key to Mr. Allen,
and saying that he would let it no more until these absurd
stories were forgotten.

"And I saw it advertised once or twice in the 'Kingsmore


Herald,' but no one ever called to see it. It's a ruinous dirty
hole, and no one would take it unless it was cleaned and
painted; and Mr. Rider won't do that, for he thinks no one
will stay in it."

"I wonder what he would ask for it?" said Roger eagerly.

"It was twenty-five in old times. I dare say he'd take


fifteen now."

"Mr. Allen, don't tell any one, because may be some one
would try to be beforehand with me. But I'd take it at
fifteen pounds a year, and do what wants doing myself. I
want to set up a fish shop, and am on the look-out for a
good chance. Old Rider won't disturb me, for I must sleep
at Sandsea!"

The baker was, as he often afterwards declared,


knocked all of a heap by the audacity of this proposal. But
after some discussion, he promised to write to young Mr.
Rider, adding,—

"The father of that little lassie that lost her shilling, if he


would write a line in your favour, could do the business. He
and George Rider married sisters, and I believe they are
good friends."
Roger was in such a state of excitement that he actually
started off for the Post Office to speak to Mr. Wilson; but
before he was at the end of Cecil Street, he stopped and
turned back.

"It would be a bad beginning, to disappoint all my


customers and lose my day. One thing at a time, that's a
good rule, though my grandfather didn't say so. I'll have
time enough to-morrow afternoon."

So he ran back to the station, and was just in time for


the train.

Next day, he not only sold a fine haddock to Mrs.


Wilson, but was promised the Wilsons' influence and best
word with Mr. Rider. And the upshot of the search for Mary
Wilson's shilling was, that Roger got the haunted house for
fifteen pounds a year.

Now began a busy time indeed. The first thing Roger


did, was to take a holiday, and a trip by rail to Colchester.
He had seen fishmongers' shops in London, but he wanted
to refresh his memory. The glories of the shops in
Colchester almost disheartened him—the gold letters, the
gilt rails, the marble tables with water always trickling
gently down to keep the fish fresh.

"But I'll just do the best I can," he said aloud as he


walked back to the station. "To be first in the field is half the
battle. I can't afford one of those outside blinds; but then,
luckily, I'm on the shady side of the street. I must make a
sloping table, though it won't be of stone, and I can keep a
watering-pot and trickle water over the fish every now and
then. I must make some way for the water to run into a
tub, though; I can't have it slopping about the floor.
Fishmonger, M O N G E R, not U; now, I'd have spelt it with
a U if I hadn't looked! What luck, to be sure."

He went back to Kingsmore and set to work. His savings


amounted to twenty pounds and a few shillings; but he had
to pay half a year's rent in advance for his shop, Mr. Rider
saying that if he were fool enough to be frightened away by
the ghosts, he should forfeit his rent. If he employed
carpenters and painters, the rest of his money would
speedily disappear; so he valiantly determined to clean,
mend, and paint for himself.

Every day, as soon as his fish was sold, he shut himself


up in the house in Cecil Street and set to work. He bought
only what he found he could not do without; a little stock of
coal, a big tub, a big iron pot, a water-can, and a scrubbing-
brush. Thus provided, he scrubbed and dusted and
scrubbed again, until the house was clean from top to
bottom.

Then he went to a timber yard and bought wood. The


men there were so much amused at the minute accuracy of
his measurements and his determination to get exactly
enough and no more, that they took pains to suit him; and
one of them, who lived in Cecil Street, helped him to carry
it home, Roger gratefully making him a present of a fine
fish next day. Hammer and nails he purchased, and a ladder
he borrowed from Mr. Allen, and, thus provided, he mended
and altered the woodwork to suit his purposes, putting a
broad sloping table in the window.

Now came the painting. Several pounds of yellow paint


and some brushes had to be bought; but the time he had
spent in watching the workmen at Sandsea terminus was
now proved not to have been wasted, for he made a very
good job of his painting. He painted his shutters black and
varnished them until they shone again. He removed the
glass from the lower part of the window. Finally, he
remounted the ladder and painted the board over the
window, on which he could discern dim traces of former
tenants' names; but he blotted them all out with two or
three coats of white paint.

By this time, curiosity was excited in the


neighbourhood, and several passers-by asked him, "What
sort of shop was this to be?"

"You'll see to-morrow or next day," was all the answer


Roger would make.

And when he had devoted a third evening to the white


board, he came down the ladder and retired to his shop to
consider the state of affairs.

He intended to try to paint his own name and the


important word "Fishmonger," for himself. If he failed, he
could only put on another coat of white, covering his failure;
if he succeeded, it would be a great saving. But if he could
only do it unseen, he knew that he would be far more likely
to succeed, and besides no one need know of his failure. At
last he concluded that as soon as the white paint was
perfectly dry, he would sleep in town one night and "have a
try," the moment the light would suffice; and as it was still
early in August, that would give him a good time.

When the time came for his attempt, he brought his


blankets from Sandsea, and at night retired to the little
room behind the shop, where he slept soundly and never
once thought of the ghost! Perhaps the said ghost was
huffed at this disrespectful conduct, perhaps the rats had
forsaken the long empty house; at all events, neither then
nor ever did Roger hear or see a ghost. I cannot say he
never heard or saw a rat, for in the days to come, he was
obliged to keep a dog to drive them away.

He was up and at work long before the sun appeared,


and when he left off, the whole board bore the inscription—

"ROGER READ, FISHMONGER"

In big capitals. What if the letters were not all the same
height? What if the ER at the end had to be compressed
into a very narrow space? What if the three words were so
close together as to look more like one gigantic word than
three ordinary ones? Roger was aware of these faults, yet
he thought on the whole it looked well, and would do for the
present.

"What a pity I can't open to-day!" he said to himself.

And having further considered the matter, he took his


big basket and ran off to the station, to meet the train by
which he usually came to Kingsmore himself. His rivals in
the trade were by this time reduced to two, a man and a
very old woman, to whom Roger had often been very kind.
Now the question was,—Would one or both of these persons
consent to sell all their fish to him, if they knew why he
wanted it? And it would not be fair dealing not to tell them.
He accosted them as they got out of the railway carriage,
telling them what he wanted, and offering what he knew
was a good price for the fish. To his great joy they both
consented, the old woman saying,—

"One good turn deserves another, and your shop won't


injure my little trade!"
While the man bargained for an extra shilling; but,
being a lazy fellow, he was glad to be spared his usual
tramp. Roger hurried home, sorted out and examined his
fish, arranged it temptingly on the yellow table, tried if his
arrangement with watering-pot and tub would work, and at
ten o'clock proudly took down his shutters, and began
business in his own shop.

"If Jack could only see it!" he muttered.

His first customer was Mrs. Wilson, who was going out
for a walk with her children, but stopped to admire the shop
and congratulate the new tradesman; also to buy a fish, for
which she said she would send in an hour or so.

"Write 'sold' in big letters on a bit of paper, Read, and


lay it on the fish; that will look well," said she.

And Roger rather thought it did look well! Though, till


his window was empty, he had not much time to think
about it.

But after that first day Roger got a little frightened. His
customers had no objection to coming to the shop, but they
objected to carrying the fish home, and he had no one to
send with it. He was obliged to engage a messenger, which
did not suit him at all, as he liked to do all his work for
himself, and was afraid of the expense. But there was no
help for it, and it turned out a very good move—though he
was constantly changing his boy, for he expected every one
to work as hard as he was willing to do himself; and the
boys, alas! had weak leanings towards marbles and tops,
and were constantly in scrapes.

In a few months, his custom became so great, that his


shop was often cleared before one o'clock, and many people
had to go away disappointed.
Roger was now obliged to take another forward step,
and again it was a step he did not half like. He was so fully
impressed with the truth of the saying, "If you want your
work well done, do it yourself," that he hated being
dependent on any one for the success of any part of his
undertaking. But he thought he would try it for a time, and
if he found it did not answer, he could return to his old plan
of sleeping at Sandsea and choosing his fish for himself. He
made an agreement with the owner of one of the best boats
to send him a supply every morning; and, on the whole,
this was a good plan and worked well.

But it gave him several hours to himself in the evening,


which he at first employed in making the room he inhabited
and his kitchen more comfortable. The rooms upstairs he
meant to put in good order as soon as he could afford it,
and let them. As his notions of comfort were very simple,
his work was soon done; and then, indeed, the idle evening
hours began to seem long and tiresome.

One evening, strolling along the street in which the


church stood, he met a good many boys coming along in
haste, and saw that they all ran round the church, to where
he knew the Kingsmore schools lay. They were big lads,
ranging from fourteen to eighteen, and Roger felt curious to
know "what they were up to," so he followed them round
the church. They were going into the boys' school-room;
and while Roger gazed and wondered, another boy came
quickly round the corner and nearly knocked him down.

"Never mind," Roger said, laughing; "you didn't see me,


I know. Tell me what is going on in there, if you don't
mind?"

"It's the evening school. Mr. Aylmer, the young parson,


has begun it, and he teaches us. It's for lads that have to
work all day, and who wish to improve themselves."

Roger's eyes actually flashed, so delighted was he.

"Do you think I may go in?" said he. "I'm busy all day,
and there are some things I do so want to learn."

"You're the man for Mr. Aylmer, then. Come along; I'm
afraid I'm late."

Roger followed him into a long, whitewashed school-


room, one end of which was well lighted, and a fire burned
cheerily in the grate, for it was winter now, and the
evenings were cold. Fifteen boys sat on the benches near
the fire; and beside a desk stood a tall young clergyman,
just preparing to offer an opening prayer.

The two late arrivals got seats as quickly as they could,


and were hardly seated before the prayer began. Then Mr.
Aylmer set them all to work, one at one study, another at
something else; and when this was done, he came and sat
down on the end of the bench on which Roger and his new
acquaintance were sitting, to speak to the stranger.

All this time Roger has never been described, nor does
the reader know his exact age. He was not very tall, but
well-made and strong-looking. He had a sensible, freckled
face, not handsome, but remarkably pleasant-looking;
honest blue eyes; and brown hair, which he kept cropped
very short. It was a bright, wide-awake face, but very
pleasant and honest-looking; and Mr. Aylmer felt inclined to
like the lad even before he spoke to him.

Mr. Aylmer was a tall, stalwart young man, a splendid


cricketer, and a hard-working clergyman, whose evening
school was his own idea and his pet undertaking.
CHAPTER V.
THE EVENING SCHOOL.

"YOU have never been here before, I think?" said Mr.


Aylmer. He had a pleasant voice, and, curious to say, it
sounded familiar to Roger, though he was sure he had never
seen Mr. Aylmer before.

"No, sir; I never heard of it before."

"A stranger here, I suppose?"

"Not exactly, sir."

"Tell me your name, that is, if you wish to attend here


regularly. I keep school here for two hours every evening
except Saturday."

"Oh, I should like that well! What do they teach here,


sir?"

"They, means me," said Mr. Aylmer, laughing. "I have no


help as yet. I teach whatever my lads want to know, and
some of them have had more education than others. What
do you wish to learn?"

"To understand the Bible and to keep accounts," replied


Roger, with all the promptitude of one whose mind is made
up.
Mr. Aylmer looked curiously at him.

"Tell me your name," said he, "and your age."

"Roger Read, sir; and I'm going on seventeen."

"And your employment? Are you in any of the shops


here?"

"No; at least, yes. I keep a shop. I'm a fishmonger,"


answered Roger with some pride.

Mr. Aylmer at first thought that this was meant as a


joke, and was not sure that he liked it. But Roger looked so
quiet and grave that he gave up that suspicion, and said
gravely,—

"Were you born a fishmonger?"

"Why, no, sir!" Roger said, laughing. "What do you


mean?"

"You are so young to be in trade on your own account,


that I want to know if it really is so, and how it came
about."

"I have a shop in Cecil Street, and there's no one but


myself. But I was born down in Devonshire, and my
grandfather, Nicholas Read, was gamekeeper at Sir Carew
Shafton's place near Bideford town."

Mr. Aylmer looked again at him, and said, "What was


the Vicar's name?"

"The Reverend George Aylmer, sir."

"And I am his son, and you are the boy about whom Sir
Carew was so unhappy, because, when your poor father's
death became known to him, he could not find you. One of
my brothers, who is in London, is on the look-out for you
still, for all I know. I thought there was a touch of old
Devon in your voice. Why did you not write to Sir Carew?"

Roger opened his eyes wide.

"Why, sir, he told me, if I went to my father, he would


never have anything to say to me again! And I thought he
meant it too. But I've done very well without his help."

"Ah, well! He'll be glad to know that," said Mr. Aylmer


drily. "Now I must waste no more time, but when school is
over, I must have a talk with you. Do you know anything of
arithmetic? I'll set you to work at once."

"And to think you're one of the Vicarage young


gentlemen!"' said Roger. "Master George, I'm sure; Master
Fred was not so tall."

"Master George it is. Here's a slate and here's a book.


Look over the book, and I'll come presently and see how
much you know."

"I could tell him that now," thought Roger. "'Nothing' is


easy said. I'll just begin at the beginning and learn it right
off."

Mr. Aylmer soon found that he had a good pupil in Roger


Read—good in a way. Roger spared no pains to learn what
he wanted to know; but anything of which he did not see
the practical use, he would not learn at all.

History! Of what use would history be to him? Mr.


Aylmer said nothing for a long time: all that winter Roger
worked away at arithmetic, book-keeping, writing, and his
Bible. Before summer came, he could write a fair business
hand, was a tolerable accountant, and could write without
errors in spelling. His business was thriving, his time was
fully occupied, and he was very happy.

No one would ever take Jack Sparling's place in his


affections; but he was beginning to regard Mr. Aylmer as a
friend, and to love him; and something to love was a great
blessing to poor lonely Roger—greater than he knew it to
be.

May was a week old, and one Saturday afternoon,


Roger was putting up his shutters when some one touched
him on the shoulder.

"Oh, Mr. Aylmer! Is that you?"

"It is; and I have come to talk to you. Shall I go down


with you to your kitchen, or will you come out for a walk?"

"Whichever you like, sir. If you're not tired, it is


pleasanter out than in my kitchen."

"Very good; follow me up to the station. I have a


message to leave there."

Roger hastened to finish his work; and having made


himself very neat and scrubbed his face and hands until
they were crimson, he took his cap and set out for the
station. Very soon he and Mr. Aylmer were going along a
country road at a great pace.

"There's a wood out here," said Mr. Aylmer, "where I


expect to get some primroses. Roger, I think you used to
play cricket down in Devonshire?"

"Oh, yes, sir; you see, I had so little to do."


"Well, I'm going to set up a cricket club here, and I
count on you as one of my best members. There'll be a
yearly subscription, but it will be small. Mr. Dunlop has
given us the use of a very nice field. It is easier to find a
good flat field here than at home, Roger."

"Well, yes, sir. But don't count on me, Mr. Aylmer, I


couldn't spare the time."

"Roger, when I urged you last week to join my English


History class, you said the same thing."

"It is quite true, sir. I've got on wonderful, I know; but I


have my rent to make up, and I have to put by for the
furniture of the two rooms upstairs, and I have to live. And
all that won't be done by pleasuring."

"Do you know what the boys call you, Roger?"

"Old Hard-as-nails," said Roger, laughing.

"And you're a little proud of the name? So I see. And


they complain that you won't make friends with any of
them, but keep altogether to yourself, and work morning,
noon, and night."

"So I do, and so I ought! Do you remember my father,


sir? He was the cleverest man I ever knew, and yet for want
of sticking to his work, see how things went with him. I
don't mean to end as he did."

"Very good. But if my dear old father, instead of being a


hearty and a temperate old gentleman, bless him! had died,
let us say, of over-eating himself, would you advise me to
try to live without eating at all?"

"That's not at all the same thing," said Roger.


"I am not so sure of that. Most people divide a man into
body, soul, and spirit; but, for my own convenience just
now, I divide him into soul, brains, and heart, his body
being the house in which these live. And if he doesn't take
care of the house, the lodgers suffer for it. Now you, Roger,
are neglecting the house, and taking care of only one of the
lodgers."

"Which, sir?" said Roger, laughing.

"Your soul; yes, I am sure you are at heart a Christian;


and that being the case, I expect you to listen to me when I
give you a lecture, which I am going to do forthwith. Here's
a very convenient wall, and we'll sit down and have it out.
Let me see, how did I mean to begin? Oh, what was Mr.
Dunlop's text last Sunday, Roger?"

Roger looked a little surprised and puzzled, but replied,


"'Seek the peace of the city whither I have


caused you to be carried away captives, and
pray unto the Lord for it; for in the peace
thereof shall ye have peace.'"

"Yes. Well, what did he say?"

"He spoke a good deal of the Prophet Jeremiah, and


what a sad life he had; and so he had, poor man, though I
never thought of it before. Then he told us who the people
were who were to seek the peace of the city: what's this he
called it?"

"Babylon."
"Yes—and then he said, that if the Jews, being no better
than slaves and captives, were to seek the peace of that
city, how much more should men seek the peace of
England, their own native country, where all have rights and
privileges and all are free! And he gave a lot of texts, more
than I could remember afterwards, but I know he said that
the Lord Himself loved His native country, for He wept over
Jerusalem."

"Yes. Now, to whom do you suppose Mr. Dunlop was


speaking?"

"He said, to all men. But when he began to talk about


votes, I didn't understand him."

"Because of your ignorance, Roger. You know nothing


about the past of your native land, nor even what is going
on at this present time. But you know what a vote is, don't
you?"

"I believe I do, sir. As to all that about my native land, I


don't see what business I have with it."

"Well, Mr. Dunlop said that the time is coming when


every man, or nearly every man, in England will have a
vote. And he said that if people used that power well and
conscientiously, it would be seeking the peace of the
country. Now, you are sure to be a rich man, Roger; one of
these days, you'll have a vote. If you knew something of
the history of your country, you'd be in a position to use
that vote intelligently and to help others to do the same. If
you don't, you'll just be taken in by fine words and false
promises, and you'll follow with others like a flock of sheep.
Therefore I say that, whether you feel the want of it or not,
you are bound as a Christian man to—join my English
History class."
Roger laughed.

"I knew that was coming!" said he.

"That's one reason. Another is for your own sake. You


have plenty of brains, but you are trying to starve them.
You want to learn only what you can turn to immediate use
and profit. Now that you have learned all the arithmetic you
want, what are you going to do in the long evenings? If
you'll learn other things, you'll soon get a taste for reading,
and I can lend you books. If you don't care for reading—
well, indeed, Roger, I don't like to think what may be the
end of those long, lonely, stupid evenings."

"That's true," Roger admitted. "Before I began to go to


the classes, I was almost mad with the long time, and
nothing to do."

"I know it. And by degrees, either you must give in and
find something to do, or it will be found for you. You know
the old hymn,—

"'Satan finds some mischief still


For idle hands to do.'

"And if I had written that hymn, I should have added,


'Also for idle brains.'"

"Well, Mr. Aylmer, I'll come!" said Roger, laughing again.


"I won't keep my brains idle."

"Or feed them with only one kind of food, of which of


course they would get very tired. And a tired brain, weary
with harping on one idea, is no joke. That is what fills our
mad-houses, the doctors say. So much for your brain.

"Now for the third lodger. Why don't you make friends
with some of my lads? There are a few that I can
understand not liking; though, mind you, if you could help
them to improve, and don't, you are leaving a duty undone.
But Robert Brown and John Meyler, and one or two more,
would be good friends for you through life, and you would
be the better for their companionship even now."

"But if I get mixed up with a lot of fellows, I shall be


losing time, Mr. Aylmer."

"Do you call our walk this evening a loss of time?"

"No! Oh no, sir, I always know I shall get good by being


with you."

"That's a great compliment, my dear boy, and a sincere


one, I know. But now, are you not aware that what you
have said is another proof of what I am trying to make you
see—that you want to live altogether for yourself? You
think, and plan, and work—all for what? You would get this
good at least from making friends with lads of your own age
and position; you would find your level, and cease to think
of nothing but Roger Read, Fishmonger."

A short silence followed this home-thrust.

"Have I offended you, Roger?"

"No, sir," said Roger in a low voice. "It is true. Jack


warned me that I must guard against that. Yet, sir, I do try
to be kind to any one that is in want."
"My boy, I know you do. Did I not hear only yesterday
that you have taken that poor old Betty Price, the
fishwoman, to be your servant, only because she is no
longer able to trudge about with her basket? And what I like
so much is, that you never speak of these things. But there
is something more wanting; you must come out of your
shell, and realize that we have duties to our equals and to
ourselves. If you don't, Roger, you'll never become more
than half a man. And I want you to be a true man—body,
soul, and spirit all at their best, so that our Lord may have a
trained soldier in His service."

"I'll do whatever you tell me, Mr. Aylmer, I know you are
right."

"Then you'll subscribe to my Cricket Club, and come


every Wednesday and Saturday evening to help me to teach
those who know nothing about it. And that brings me round
to my fourth and last head. You know I divided you into four
at the beginning, and I have disposed of the three lodgers.
Now for the house, Roger, you don't look half so well as you
did the evening you astounded me by proclaiming yourself a
fishmonger."

"No, I am not; I miss the journey to and from Sandsea,


and the pure salt breezes. But I can't go back to the old
way now; my business has outgrown that."

"The cricket, and good long walks when you can spare
time, will do just as well. By the way, we ought to be
walking homewards. No primroses for me to-night; but if
you keep your word, Roger, I shall not mind that."

"No fear, sir, I'll keep my word, and I'll try to get out of
my shell."
It was not long before Roger felt the benefit to both
mind and body which followed upon this determination. He
was a clever, thoughtful fellow, and the study of the history
of his native land led on to other studies; in fact, he became
so fond of reading, that his evenings seemed as much too
short as once they had seemed too long. He also took so
kindly to cricket that the two evenings in the week were not
grudged to it.

But it was a good long time before he succeeded in


being on frank and friendly terms with the lads he had so
long kept at a distance. They did not like him nor wish for
his company. But he succeeded in time, thanks, partly, to a
lecture Mr. Aylmer gave to Robert Brown; and he became
popular when they knew him better, and he was much
happier when he had "got out of his shell."

And his business did not suffer by all these other


interests; he attended to it so thoroughly, and was so
honest and trustworthy, that when a new fishmonger's
shop, with marble slab, gold lettering, and every modern
improvement, was opened in Kingsmore, the owner got so
little custom that he was obliged to close the shop in a few
months.

Now it happened, oddly enough, that this shop also


belonged to Mr. George Rider; and Roger at once wrote to
ask leave to exchange the house he was in for this far
better one, as he was quite able to pay the higher rent.

Having got Mr. Rider's consent to this arrangement, he


made a fair offer to the disappointed tradesman for the
shop fixtures, and moved into his new premises as soon as
his name, in all the glories of gold and scarlet, had replaced
that of the original owner.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like