100% found this document useful (5 votes)
16 views

Beginning iOS 5 Development Exploring the iOS SDK 1st Edition Dave Mark All Chapters Instant Download

SDK

Uploaded by

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

Beginning iOS 5 Development Exploring the iOS SDK 1st Edition Dave Mark All Chapters Instant Download

SDK

Uploaded by

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

Download the full version of the ebook at 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 BUTTON

DOWNLOAD EBOOK

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
Exploring the Variety of Random
Documents with Different Content
had had to do with the death of my rabbit, and I hope you'll forgive
me for thinking it. I had no right to think so badly of you as that, and
now I'm dreadfully ashamed to remember that I did. Do forgive me,
won't you?"

"I—I've nothing to forgive," gasped Tim, utterly taken aback by the


little girl's words and the remorseful expression of her face. "I—I wish
you wouldn't speak like that, and—"

"Just say you forgive her, Shuttleworth, and she'll be satisfied,"


interposed Bob. "It's been on her mind that she's thought worse of
you than you deserve," he added with a smile.

"Yes, I ought to have taken your word, Tim," said Kitty distressfully. "I
know now that you wouldn't tell a story for the world. Why, what's the
matter?"

Well might she inquire, for Tim's plain, freckled countenance was
quivering with strong emotion. The next moment he disappeared
from view on the other side of the wall, leaving the brother and sister
staring at each other in blank amazement.

"He could hardly keep from crying," said Bob, "that's why he's gone. I
should never have thought he was such a moody-hearted chap as
that."

"I didn't say anything to hurt him, did I?" asked Kitty anxiously. Then,
as Bob shook his head, she proceeded, "Fancy his keeping the
secret about Fluffy all this time! If father had allowed me to tell him
that I saw him take away the covered basket, we should have found
out the truth before. I was right about that, you see. Perhaps he'll
come back in a few minutes and talk to us again."

But Tim did not return. He had rushed indoors and upstairs to his
own room; and whilst Kitty and Bob lingered in the garden, waiting
and hoping to see his red head appear over the wall he was sobbing
by his bedside and shedding the bitterest, most repentant tears that
had ever dimmed his eyes in his short life, as he recalled the words
Kitty had spoken in such a tone of conviction—"I know now that you
wouldn't tell a story for the world."

CHAPTER XII.
TIM ENTERTAINS.

"TIM, there's a letter from your father by this evening's post," said Mr.
Shuttleworth, opening his nephew's bedroom door, "and it contains
news which will interest you. Why, dear me, what's amiss?" he
inquired, as Tim rose hastily from his knees by the bedside and
turned his tear-stained face towards him.

Receiving no response, Mr. Shuttleworth entered the room, and,


seating himself on a chair by the window, surveyed the little boy
through his spectacles, his expression one of deep concern.

"You are not home-sick?" he asked dubiously. Then, as Tim shook


his head, he continued: "That's well. Cannot you tell me what
troubles you? Perhaps I can help you."

Tim hesitated. His uncle's voice was very kind, and the near-sighted
eyes which met his were full of sympathy. A great longing possessed
Tim to confide in some one, and, obeying the impulse of the
moment, he opened his heart to his uncle, and told him how he had
killed Kitty's rabbit and subsequently denied having overturned the
hutch, how he had tried to make amends, and how Kitty's humble
request for forgiveness for her suspicion of him and her assurance
that she knew he would not tell a lie for the world had made him feel
the falsity and cowardice of his past conduct. Mr. Shuttleworth
listened without remark until his nephew had finished his confession;
then he said:

"It seems to me, Tim, there's only one course to be taken—to make
a clean breast of everything to the people next door."

"I should like them to know, but I can't tell them—I can't!" cried Tim in
great distress. "Think what a bad opinion they'll have of me, and
they've all been so kind. I never meant to kill the rabbit, Uncle John; I
didn't know what was in the box."

"It was a spiteful trick anyway, Tim, and I don't wonder you were
ashamed afterwards when your temper had cooled down; but I don't
comprehend why, instead of owning to the truth, you were led to tell
a lie."

"It was because I was afraid the Glanvilles wouldn't have anything to
do with me if they knew what I'd done, and I did so want to be
friendly with them, Uncle John."

Mr. Shuttleworth was puzzled. He found himself incapable of


entering into the workings of his nephew's mind; but he saw he was
very conscience-stricken, and in great trouble, and longed to comfort
him. "I wish I could set matters on a right footing for you, Tim," he
said thoughtfully. "Would you like me to repeat to the Glanvilles all
you have imparted to me to-night?"

"Oh, Uncle John, if you only would I should be so glad! I expect they
will all despise me, but I can't have Kitty asking me to forgive her,
when—Oh, I don't think I ever before told such a big lie as the one I
told her, and it's worried me ever since."

"I'm glad to hear it, my boy; it shows me you're not in the habit of
uttering falsehoods, It's a grand thing to be truthful, for it takes a deal
of courage to be that."

"Yes, indeed it does," Tim rejoined with a sigh.


"The path of truth is difficult to walk because it's steep at times," Mr.
Shuttleworth said gravely, "but you know the old adage about putting
a stout heart to a steep hill, don't you? And the path of falsehood
seems easy travelling at first, because it's all down hill, and we don't
see the obstacles that are sure to rise before us as we go on. Take
my advice and don't turn from the uphill path in the future, my boy."

"I will try not to," Tim responded earnestly, much touched by his
uncle's little sermon. "It is very good of you not to be harder on me,
Uncle John. Did you not say you had heard from father?"

"Dear me, I had forgotten that. Yes, I heard from your father by to-
night's post; he is going to have his holiday from the bank next
month, and proposes to come and fetch you home. What do you
think of his plan?"

"I call it a capital one," said Tim, his face brightening.

"Your father will spend his holidays—a fortnight—here. It will be a


great pleasure to me to have his society. I shall be sorry to lose you,
Tim; and I have been thinking—"

But what Mr. Shuttleworth had been thinking he did not inform his
nephew then, for he broke off in the middle of his sentence, and a
few minutes later he went downstairs.

That night, after Tim had gone to bed, Mr. Shuttleworth made his call
next door. He saw Mr. and Mrs. Glanville, and repeated Tim's
confession to them. Needless to say they were greatly surprised; but
much to Mr. Shuttleworth's relief, Mrs. Glanville seemed to
understand Tim in the matter.

"I see he has a very passionate temper," she said, "and I can quite
believe he did not know it was a rabbit's hutch he was overturning,
for I am sure he would not wilfully injure a living creature. If only he
had owned the truth and not told Kitty that lie!"
"To me that seems the worst part of the business," said Mr.
Shuttleworth gravely. "But I think the lie brought its punishment,
judging by the distress of mind I found Tim in to-night; I do not
believe he will so easily give way to temptation again. I am afraid he
has exhibited himself to you all in a very bad light in this matter, but I
assure you he is sincerely repentant, and if your little girl and boy
can find it in their hearts to forgive him and continue to be his friends,
I shall be truly glad."

"I shall explain everything to Kitty and Bob," Mrs. Glanville replied,
"and I am sure they will not be harsh in their judgment of Tim. Poor
Tim! I must have a little talk to him myself."

Mrs. Glanville kept her word, and the following morning, whilst her
children were at school, she made a point of seeing Tim and
speaking to him as gently and sympathetically as his own mother
would have done under such circumstances, pointing out to him that
the fact of his having given way to his passionate temper and having
sought revenge had brought about the death of an innocent creature,
and had thus led him into further sin. No more was to be said on the
subject, she told him, but she hoped he had learnt a lesson he would
never forget.

"And Kitty and Bob?" Tim asked falteringly. "I suppose they won't be
friends with me any longer now?"

"Oh, yes, indeed I hope they will," Mrs. Glanville replied. "You are
going to entertain them on Saturday, you know. Had you forgotten
that?"

"No," Tim answered in a low tone. "But I thought—I was afraid that
they might not care to come. What did they say, Mrs. Glanville, when
they heard it was I who overturned the hutch?" he inquired with
considerable anxiety.

"Of course they were greatly astonished, but neither of them believe
you meant to injure the rabbit; they know you are not in the least
cruel. Kitty was hurt because you had told her a falsehood and Bob
was incredulous at first—it seems he had formed a very high opinion
of your sense of honour and truth."

Tim's cheeks burnt with shame on hearing this, and he wondered if


he would ever be able to restore Bob's faith in him again. Well was it
for him that he had not heard the words in which Bob had remarked
on his conduct; he would have greeted his visitors on Saturday even
more nervously than he did, had he known that it was to their mother
he owed their having kept their appointment. For they had been
justly indignant against the boy next door, who, as Kitty had taken
care to point out, had acted the enemy's part, at least on one
occasion, and by his own confession had proved that she had not
been far from the truth after all.

But Kitty and Bob were kind-hearted children, and it was not in their
natures to harbour resentment against any one for long; so that
when Tim, rather falteringly, put forward the plan for making a tent in
the back garden, they agreed to it cordially, and set to work with a
will, and by the aid of a clothes' prop for a centre pole and several
old wrappers, they managed to erect a kind of awning under which
they decided they would have their tea.

"Won't Mr. Shuttleworth have tea with us?" asked Kitty, when
Deborah arrived with the tea-things, which were placed on a small
gipsy table inside the tent. "There's only room for two chairs, but he
can have one, can't he?"

"And you must have the other, Kitty," said Tim. "For, of course, you'll
pour out the tea."

"If you wish it, I will," the little girl replied, a look of extreme
gratification settling on her face.

"I'll tell master you're beginning tea," remarked Deborah. "Then he


can join you or not as he likes."

A few minutes later Mr. Shuttleworth appeared upon the scene. He


thought it would have been more comfortable to have had the meal
in the house; but as the children assured him it was much nicer to
have it outdoors, he good-humouredly took the second chair in the
tent, whilst Kitty poured out the tea, and the boys sat cross-legged
on the ground. They were all very friendly and merry, and by-and-by
a glad bark was heard, and Snip, who had been waiting for an
opportunity of joining his young mistress and master all the
afternoon, and had just gained admittance into the garden, jumped
into Kitty's lap.

"Oh, Snip, you weren't invited, sir!" she cried reproachfully, kissing
him on the top of his head.

"Nevertheless, he must have some tea," Mr. Shuttleworth said with a


smile, as he poured out a saucer of milk for the little dog. "Dear me,
he has been in the wars, has he not?"

Kitty immediately explained how Snip had come by his wounds, and
went on to give Mr. Shuttleworth a graphic description of old Jacob
Dottin and his shop, finally telling him that Fluffy had come from
there.

"Who is Fluffy?" Mr. Shuttleworth inquired.

"The beautiful white rabbit Tim gave me in place of the one he


killed," she replied. Whereat Tim turned crimson and looked terribly
abashed, and Bob changed the conversation.

It was not until shortly before his visitors left that Tim plucked up
sufficient courage to speak to them about the bad turn he had served
them at the commencement of his acquaintance with them, and to
beg their forgiveness, which was willingly granted.

"It was an unneighbourly trick, and we didn't deserve you should


have done it," Bob said frankly, "but, of course, you never dreamt it
was something living we had in the box. We'll never mention it
more."

"And the lie I told," faltered Tim, looking at Kitty.


"Why didn't you own up to me?" she questioned.

"Because I was so afraid if I did you and Bob would never let me be
your friend, that was my reason," he rejoined. "I bitterly repented
afterwards that I hadn't told the truth."

"Well, you can be our friend still, if you like," Bob remarked, glancing
at his sister, who nodded her head assentingly. "I'm sure we'd both of
us much rather have a friend than an enemy next door."

CHAPTER XIII.
A REGULAR BRICK.

"KITTY! Kitty!" called Bob. "Oh, there you are! Keep Snip here with
you, will you, till I'm gone? Don't let him get away and follow me!"

"Why not?" demanded Kitty.

It was again a Saturday afternoon, several weeks having passed


since the sister and brother had been entertained next door. The little
girl, who had been watching Fluffy eating a sprig of parsley, turned
away from the rabbit hutch as she spoke, and joined Bob, who,
fishing rod in hand, and accompanied by Snip, had addressed her
from the back door.

"Because I'm going to Lang's pond, with Shuttleworth," he explained,


"and if Snip went with us he'd for certain spoil our sport by hunting
for water-rats and disturbing the fish. He seems to have an idea that
I want to get rid of him, for he's keeping as near me as he can, and
—"

"Oh, do let me go with you this afternoon!" interposed Kitty, eagerly.


"Why can't I?" she asked, as her brother shook his head.

"Well," he said, "it's possible that we may meet Richards, and that he
may ask us to his house to tea—that is, if you're not there."

"Then you'd better go your own way!" snapped Kitty, adding under
her breath, "Such selfishness!"

"But will you keep Snip with you?" questioned Bob.

Kitty assented. She took Snip into the house, and shut herself into
the dining-room with him, feeling deeply aggrieved. Mr. and Mrs.
Glanville had gone away for the day, therefore it was exceedingly
unkind of Bob, she considered, to go off with Tim Shuttleworth and
leave her.

"He makes a great deal too much of Tim," she reflected. "It's all very
well to let bygones be bygones, but Bob seems to have forgotten
altogether how disgusted he was with Tim at one time, and is making
him his chief friend. I haven't such a short memory as Bob."

This was true. Bob had a happy knack of putting anything he wished
to forget away from him. But Kitty, though she had agreed never
again to mention the ill-turn Tim had done her, often allowed her
mind to dwell on it, and the consequence was that she was
considerably less genial to him than was her brother.

By-and-bye, when she judged the boys must have taken their
departure, she decided to go out with Snip. It had rained earlier in
the day, but the weather had cleared about noon, and now the sun
was shining brilliantly. It was a really perfect May afternoon.

"I'll get some wild hyacinths for mother," the little girl thought,
remembering that she had heard Mrs. Glanville remark at breakfast
that they must now be in bloom and she would like some. "And on
my way home, I'll pass by Lang's pond and pay the boys a surprise
visit. I'll see Snip doesn't interfere with them."

Accordingly she sallied forth, with a basket on her arm, and


accompanied by the faithful Snip. First she went to a confectioner's,
where she purchased some chocolate creams, then left the town by
a side street, and a quarter of an hour later found her in a pretty
wood, carpeted with masses of wild blue hyacinths. She filled her
basket with the fragrant flowers, after which she sat down on the
moss-covered trunk of a fallen tree, and ate her chocolates, sharing
them with Snip.

"There!" she cried, as she popped the last chocolate into her mouth,
and rose. "Now we'll go to Lang's pond—we've as much right there
as anyone, eh, Snip? Still, I think I'd better lead you. Bob can't
complain if I do that."

Nevertheless Bob was not altogether pleased when, ten minutes


later, standing by the side of Tim Shuttleworth, on the edge of Lang's
pond, his eyes fixed on the float of his fishing rod, he heard a shout
and recognised his sister's voice.

"It's Kitty," Tim informed him. "She's brought Snip with her, but she
has him on the leash."

"Well, boys, what sport?" Kitty questioned, as she joined them. "The
fish are biting well, I suppose, after the rain? Let me see what you've
caught!"

She opened a fishing-basket which lay on the ground, and gave a


little laugh as she viewed its contents.

"Three dace, two roach, and an eel!" she cried. "The dace are the
smallest I ever saw. You ought to have put them back into the water
again, they aren't worth cooking. The roach are not so bad, but—"
"I daresay you think you could catch bigger ones!" Bob broke in,
sarcastically. He was disappointed that they had not had better sport,
and his sister's candid comments had vexed him.

"Richards is not here, I see," observed Kitty, after a few minutes'


silence.

"No, he has not turned up," Tim answered. "He did not promise to
come—only said that he might. What lovely hyacinths you have
there!"

"Yes, haven't I?" said Kitty.

She placed her basket on the ground, and stood watching the boys
for some while, but she soon tired of inactivity, and strolled around
the edge of the pond, still leading Snip. By-and-bye she caught sight
of some fine forget-me-nots growing close to the water, and stooped
to gather them. At that exact moment Snip spied a water-rat, and,
jerking the leash out of his mistress' hand, sprang Into the water in
pursuit of it.

"There!" cried Bob. "I knew what it would be!" He threw aside his rod
as he spoke, and glared angrily at his sister. "You must have let him
go on purpose, Kitty!" he asserted.

"I did not!" the little girl declared. "Indeed I did not! Oh, Bob, I'm so
sorry! Come here, Snip! Come here, sir!"

But Snip paid not the least attention to her. He was now swimming
around the edge of the pond, and sniffing into the rat-runs which
undermined the bank. Tim was secretly as vexed with Kitty as was
Bob, but out of pity for her he did not show his feelings, and stood
listening in silence to the hot words which were now passing
between the sister and brother.

"Well," Bob said at length, his anger beginning to cool, "of course, if
you say you didn't let him go on purpose, I believe you, and we'll
drop the subject. We'd better go home to tea now, I suppose."
"I'm sorry I came," murmured Kitty, almost tearfully. "I know you
didn't want me. Oh, oh!" she cried, her tone suddenly changing to
one of great excitement. "Look at Snip, boys! Oh! Do look! What's
the matter with him? Oh, see how he's struggling! Oh, Bob! Oh, Tim!
He'll drown—he'll drown!"

Snip had turned a rat out of its lair in the bank, and had been
swimming across the pond, which was very deep in the centre, after
it, when something had become entwined about his hind legs, and
he was now struggling in vain to get them free.

"Don't be silly, Kitty!" Bob said, speaking sharply, because he was


frightened and could not think what had happened to the dog. "How
can Snip drown when he can swim like—"

"Oh, you don't understand!" broke in Kitty, wringing her hands in her
distress. "It's the leash! It's got around his legs, and—Oh, Bob, go to
him, go to him!"

It was all very well to say "Go to him!" But Bob could not swim, and
knowing that he would be out of his depth in the water before he
could reach Snip, he naturally hesitated. At that minute, evidently
realizing the peril of his situation, the little dog uttered a piteous cry,
which nearly drove his mistress frantic; she would have dashed into
the pond herself if her brother had not prevented her.

"Oh, what can we do?" she wailed. "Oh, this is awful—awful! Oh,
Bob, can't you do anything? Oh, Tim!—where's Tim?"

"Here!" answered Tim, behind her. "It'll be all right, Kitty! Don't you be
frightened! I'll get him!"

Kitty now perceived that Tim had divested himself of his coat and
waistcoat, and was hurriedly unlacing his boots.

"I can swim—a little," he told her. "I think I shall be able to reach him.
There!"—As he pulled off his last boot. "Now I'm ready!"
He waded into the pond till the water reached his chin, Kitty and Bob
watching him with deepest anxiety, then swam a few strokes which
brought him within reach of Snip. He grasped the little dog by the
back of the neck, and, turning, essayed to swim back with him, but
Snip continued to struggle, and no progress was made.

"Can you get off the leash?" shouted Bob. "Try! Try!"

Tim did try, and, after several vain attempts, succeeded in


disentangling the leash, and setting the dog free. That done Snip
swam ashore of his own accord, and his rescuer followed him, to be
greeted with tearful thanks from Kitty as he waded out of the pond,
and a warm hand-clasp from Bob, who told him that he was "a brave
chap, and no mistake!"

"Yes, indeed," agreed Kitty. "But for you, Tim, poor Snip would
certainly have been drowned. Oh! I wonder what mother and father
will say when they hear about this? Oh, dear me, how dreadfully wet
you are, to be sure!"

"It would be a miracle if he was not!" Bob exclaimed, with a laugh,


which hid deep feeling. "What silly remarks you do make, Kitty! We
must get you home as quick as we can, Tim, or you'll catch cold!"

Tim had pulled on his boots over his wet stockings with some
difficulty by this time, and was now kneeling to lace them up.

"Oh, I shan't catch cold!" he declared cheerfully.

"I hope not," said Kitty, her voice full of concern, "because if you did
you might get pneumonia again. Oh, Tim, I haven't thanked you for
what you've done."

"Please don't!" Tim interposed, adding—"I'm so glad I could swim!"

He rose from his knees as he spoke, and, meeting Kitty's eyes, still
rather tearful, smiled at her.
"Oh," the little girl cried, "you don't know how grateful I feel to you."

"You're a brick, Tim—yes, a regular brick!"

CHAPTER XIV.
CONCLUSION.

"YOU'LL find me in the garden when you've finished your lessons,"


said Kitty, one evening, a few weeks later, as she poked her fair
head around the dining-room door to address her brother, who was
seated at the table, at work on his French translation. "I want to
consult you about something," she added impressively.

"All right," Bob answered. "I'll be with you before long."

Kitty went into the garden, and took up her position on a seat under
the apple tree. There, in a very few minutes, Bob joined her.

"Well?" he said interrogatively.

"Tim has gone out with his uncle," Kitty informed him. "I saw them
start together; so I thought this would be a good opportunity to
consult you about something—Tim not being about, you know."

"The 'something' has to do with Shuttleworth, then?" questioned


Bob.

Kitty nodded. "He'll be going home soon now," she observed. "Dear
me, it's quite remarkable we should both of us be so friendly with him
after—"

"Not remarkable at all," her brother broke in, rather impatiently. "He's
a jolly nice fellow—he's proved it. Speak out! What is it you want to
consult me about?"

"Well, I've been thinking that before Tim leaves we ought to give him
a present," Kitty said eagerly. "You know, he really did save Snip's
life. Father says that the poor little thing would certainly have
drowned if Tim hadn't gone to him and freed him from the leash."

"And you think he should have a testimonial as a reward?"


suggested Bob, with a teasing smile.

"I think nothing of the kind," the little girl answered, flushing. "You are
pretending to misunderstand me. I meant this—that we may never
see Tim again, and I should like to give him a present for a
keepsake, something that will put him in mind of us when he looks at
it."

"Well, I don't think that's a bad idea," Bob said, now speaking
seriously. "Let me consider. What could we give him? How much
money have you by you?"

"One shilling and two-pence, but I shall be having my sixpence


pocket-money on Saturday, of course."

"So you'll be good for one shilling and eight-pence. If I put a couple
of shillings to that, what could we buy? I know! A pocket-knife! We
could get a beauty, with three blades, the best that's made, for three
shillings and sixpence or four shillings."

"Oh, Bob, that would be the very thing! Tim has only an old bone-
handled pocket-knife with one blade, and that blade is broken! When
shall we get it! The new one, I mean? On Saturday?"

"Yes, if you like."


"And how shall we give it to him? I mean, will you, or shall I? You are
the elder, but it was my idea that we should make him a present.
Still, if you'd like to give it to him—" Kitty broke off, and looked at her
brother inquiringly.

"We can draw lots to decide that point," he answered, "then


everything will be fair."

Thus it came to pass that the following Saturday, shortly before one
o'clock, when Tim spoke to Kitty over the garden wall, and inquired
how she and Bob were going to spend the afternoon, she replied,
with an air of reserve, which puzzled him and rather aroused his
curiosity, that they were going into the town on private business.

"But we shall not be away very long," she added. "And I daresay we
shall see you as soon as we get back."

"I don't know about that," he answered, rather piqued because the
little girl seemed afraid that he might suggest accompanying her and
her brother. "I may not be at home then."

After the mid-day meal Tim had half a mind to go for a walk in the
country by himself, for his uncle betook himself as usual to his study.
But, as Kitty had spoken of seeing him on her return from the town,
he decided to remain at home, write to his mother, and afterwards
stroll out into the garden, so that the young folks next door could hail
him if they wanted him. Accordingly, he settled himself in the dining-
room, and had barely finished his letter, when, to his great
amazement, Deborah opened the door, and announced:

"Miss and Master Glanville!"

"Kitty! Bob!" he exclaimed, rising from his seat at the table, and
looking quickly from one to the other of his visitors. "Why didn't you
call to me from the garden as you usually do? I should have heard
you."
"If you're writing to your people perhaps you don't want to be
disturbed, and we'd better not stay?" suggested Bob. "Hurry up,
Kitty!" he whispered to his sister.

"Oh, do stay!" cried Tim. "Sit down, won't you? Here, Kitty, have this
easy chair?"

Kitty sank into the chair indicated, but not before she had put her
hand in her pocket, and drawn therefrom a small package. It had
fallen to her lot to present the pocket-knife.

"I daresay you thought it was rather odd of me not to tell you where
Bob and I were going this afternoon," she commenced, addressing
Tim. "Now, didn't you?"

"Well, yes, I did," he admitted, candidly. "Of course, I saw you didn't
want me to go with you—"

"That was just it," Kitty broke in. "We didn't want you to go with us
because we were thinking of buying you a present. We've bought it!
Bob chose it! It's a pocket-knife, and, oh, I do hope you'll like it!
There was one with a tortoiseshell handle I rather fancied, but Bob
said he was sure you'd prefer this one—if not, the man in the shop
won't mind changing it. This one has three blades, all of the very
best steel, they cut like lances, and it has a buck-horn handle. Oh,
look at it, do!" She thrust the little package into Tim's hands as she
spoke.

Tim, who had become quite red in his surprise, opened the package
with fingers which trembled with eagerness, and a very handsome
pocket-knife was revealed to view.

"You have bought this for me?" he cried, glancing first at Kitty, who
was watching him anxiously, trying to read from the expression of his
countenance if he approved of her brother's choice, and then at Bob,
who nodded assent. "Oh, how kind—how very, very kind of you both!
Oh, thank you—thank you! Oh, it's a grand knife! Three blades! Oh, I
say, I shall never be able to thank you half enough for this!" His eyes
were sparkling with delight.

"Do you prefer it to one with a tortoiseshell handle?" questioned


Kitty.

"Of course he does!" Bob exclaimed, without giving Tim time to


answer for himself, "Any boy would! That tortoiseshell handled knife
wasn't half as strong as this one; it was nice enough in its way, but it
was only fit for a girl."

"You couldn't have given me one I should have liked better than
this," Tim said earnestly, "I'm quite sure of that."

Kitty was satisfied. "That's all right then!" she said.

"Mother told us to ask you to tea with us, Shuttleworth," remarked


Bob, a few minutes later, after Tim had tried all three blades of his
new pocket-knife on a lead pencil. "Will you come?"

"Oh, thank you, I should like to—you know that," Tim replied. "Just
wait whilst I put away my writing things and tell uncle where I'm
going. I say, whatever made you think of giving me a present?"

"It was Kitty who thought of it," said Bob. "And when she mentioned
it to me, I considered it a very good idea and wondered I hadn't
thought of it myself. We're awfully pleased you like the knife—it's a
keepsake, you know—something for you to remember us by."

Tim was much touched—so touched, indeed, that he could find no


words to answer, but his face was eloquent of all the feelings in his
warm Irish heart.

"We shall be very sorry when you're gone," said Kitty, looking at him
with friendly blue eyes. "We shall miss you, oh, ever so much! You'll
think of us all, and of Snip—oh, I shall never forget that you saved
Snip's life! But, come, I'm sure it's near tea-time. I'm getting so
hungry!"
The three young people were very happy and merry together during
the hour or so which followed. After tea they repaired to the garden,
and on the trunk of the big apple tree Tim carved Kitty's initials, and
then Bob's, and then his own, with the big blade of his new treasure.

"There!" he cried, as he surveyed his finished handiwork, "How's


that!"

"Beautifully done!" answered Kitty, admiringly.

"Ah," said Tim, "I've a good tool—I never before handled such a
splendid knife." He shut it with a snap, and returned it to his pocket.

"Glad it suits you, old fellow!" said Bob, whilst Kitty looked very
gratified. "Yes, the initials look all right—they're very well done
indeed."

*****

Shortly before midsummer, Tim's father arrived at B—, and, after his
fortnight's holiday, returned to Dublin, taking his son with him. Tim
had been quite low-spirited at parting with his friends next door
although he had been going home; he had been sorry to say good-
bye to his uncle, too. But, as it happened, he was not to be absent
from B— long; for his uncle had offered to take him to live with him
and to send him to the B— Grammar School. And as he was to go to
his own people for the Christmas and the summer holidays, he was
simply delighted with this arrangement. So the end of September
found him once more a resident beneath his uncle's roof; and at the
beginning of the autumn term he was entered as a pupil at B—
Grammar School, where he was introduced to the boys by Bob
Glanville as "my friend, Shuttleworth."
Kitty and Bob scarcely ever think of the old days now when they
were so prejudiced against Tim Shuttleworth, and there is no one for
whom Kitty has a greater liking and regard than the boy whom she
once looked upon as her enemy.

THE END.

HEADLEY BROTHERS, 18, DEVONSHIRE STREET, E. C. 2; AND


ASHFORD, KENT.

You might also like