Objectivec The Ultimate Guide Sufyan Bin Uzayr Download
Objectivec The Ultimate Guide Sufyan Bin Uzayr Download
download
https://ebookbell.com/product/objectivec-the-ultimate-guide-
sufyan-bin-uzayr-50848970
https://ebookbell.com/product/the-ultimate-book-on-stock-market-
timing-volume-5-technical-analysis-and-price-objectives-raymond-
merriman-46848006
Objectivec Programming The Big Nerd Ranch Guide 1st Edition Aaron
Hillegass
https://ebookbell.com/product/objectivec-programming-the-big-nerd-
ranch-guide-1st-edition-aaron-hillegass-2627310
Objectivec Programming The Big Nerd Ranch Guide 2e Big Nerd Ranch
Guides Hillegass
https://ebookbell.com/product/objectivec-programming-the-big-nerd-
ranch-guide-2e-big-nerd-ranch-guides-hillegass-38183932
Objectivec Programming The Big Nerd Ranch Guide 2nd Edition Aaron
Hillegass
https://ebookbell.com/product/objectivec-programming-the-big-nerd-
ranch-guide-2nd-edition-aaron-hillegass-4654516
Objectivec Programming The Big Nerd Ranch Guide 2e Big Nerd Ranch
Guides Hillegass
https://ebookbell.com/product/objectivec-programming-the-big-nerd-
ranch-guide-2e-big-nerd-ranch-guides-hillegass-22846750
Objectivec Programming The Big Nerd Ranch Guide 2e Big Nerd Ranch
Guides Aaron Hillegass Mikey Ward Hillegass
https://ebookbell.com/product/objectivec-programming-the-big-nerd-
ranch-guide-2e-big-nerd-ranch-guides-aaron-hillegass-mikey-ward-
hillegass-29287066
Objectivec Programming The Big Nerd Ranch Guide Aaron Hillegass Mark
Fenoglio
https://ebookbell.com/product/objectivec-programming-the-big-nerd-
ranch-guide-aaron-hillegass-mark-fenoglio-32632590
Objectivec Programming The Big Nerd Ranch Guide Big Nerd Ranch Guides
Hillegass Aaron Aaron
https://ebookbell.com/product/objectivec-programming-the-big-nerd-
ranch-guide-big-nerd-ranch-guides-hillegass-aaron-aaron-35406134
Objectivec Programming The Big Nerd Ranch Guide 2e Big Nerd Ranch
Guides Aaron Hillegass Ward
https://ebookbell.com/product/objectivec-programming-the-big-nerd-
ranch-guide-2e-big-nerd-ranch-guides-aaron-hillegass-ward-36156342
Objective-C
Objective-C: The Ultimate Guide walks developers and coders through a straight-
forward and practical method of learning the Objective-C programming language.
This book discusses the basics in brief, and then moves on to more advanced and
detailed exercises to help readers quickly gain the required knowledge. The focus in
this book remains on writing optimized and well-structured code in Objective-C.
Key Features:
DOI: 10.1201/9781003357506
LOOPS IN OBJECTIVE-C 27
CONTROL STATEMENTS FOR LOOPS 28
INFINITE LOOP 28
DECISION MAKING IN OBJECTIVE-C 29
THE ? : OPERATOR 30
FUNCTIONS IN OBJECTIVE-C 30
CREATING A METHOD 31
DECLARATIONS OF METHOD 32
CALLING A METHOD 32
FUNCTION ARGUMENTS 34
BLOCKS IN OBJECTIVE-C 34
Simple Block Declaration Syntax 35
Implementation of a Simple Block 35
BLOCKS TAKE ARGUMENTS AND RETURN VALUES 35
BLOCKS USING THE TYPE DEFINITIONS 35
NUMBERS IN OBJECTIVE-C 36
ARRAYS IN OBJECTIVE-C 38
DECLARING ARRAYS 38
ARRAYS INITIALIZATION 39
ACCESSING ARRAY ELEMENTS 39
ARRAYS IN OBJECTIVE-C IN DEPTH 40
POINTERS IN OBJECTIVE-C 41
WHAT EXACTLY ARE POINTERS IN OBJECTIVE-C? 41
How Do Pointers Work? 42
OBJECTIVE-C NULL POINTERS 43
DETAILS ABOUT OBJECTIVE-C POINTERS 43
STRINGS IN OBJECTIVE-C 44
STRUCTURES IN OBJECTIVE-C 46
CREATING A STRUCTURE 47
ACCESS TO STRUCTURE MEMBERS 47
FUNCTION ARGUMENTS AS STRUCTURES 48
POINTERS TO STRUCTURES 50
x ◾ Contents
BIT FIELDS52
PREPROCESSORS IN OBJECTIVE-C52
EXAMPLES OF PREPROCESSORS53
PREDEFINED MACROS54
OPERATORS OF PREPROCESSORS55
Macro Continuation (\)55
Stringize (#)55
Token Pasting (##)55
defined() Operator56
PARAMETERIZED MACROS56
Typedef IN OBJECTIVE-C57
typedef vs #define58
TYPE CASTING IN OBJECTIVE-C59
INTEGER PROMOTION59
USUAL ARITHMETIC CONVERSION60
LOG HANDLING IN OBJECTIVE-C61
NSLog METHOD61
DISABLING LOGS IN THE LIVE Apps61
ERROR HANDLING IN OBJECTIVE-C62
NSError62
COMMAND-LINE ARGUMENTS64
BIBLIOGRAPHY65
UI ELEMENTS128
What Are UI Elements?128
How Do We Insert UI Elements?128
Our Focus128
Our Strategy128
LIST OF UI ELEMENTS129
ACCELEROMETER IN iOS130
UNIVERSAL APPLICATIONS IN iOS131
CAMERA MANAGEMENT IN iOS132
LOCATION HANDLING IN iOS134
SQLite DATABASE IN iOS137
SENDING EMAIL ON iOS144
AUDIO AND VIDEO IN iOS146
FILE HANDLING IN iOS148
METHODS FOR FILE HANDLING148
Check to See If a File in Objective-C Exists at a Given Path148
Comparing the Contents of Two Files148
Check to See If It Is Writable, Readable, and Executable149
Move File149
Copy File149
Remove File149
Read File149
Write File149
ACCESSING MAPS ON iOS150
IN-APP PURCHASE IN iOS152
iAd INTEGRATION IN iOS158
GameKit IN iOS159
STORYBOARDS IN iOS162
AUTO LAYOUTS IN iOS163
Aim of Our Example163
Our Strategy163
The Involved Steps164
xiv ◾ Contents
Types 250
Methods 250
Pragma Mark and Implementation Organization 251
Control Structures 251
Switch 252
For 253
While 253
Import 253
Header Prefix 254
Properties 254
Private Methods and Properties 254
Extern, Const, and Static 255
Naming 255
Enums 256
HARDENING OF SYSTEMS 256
Hardening of Systems to Reduce the “Attack Surface” 256
Advantages of System Hardening 257
NOTE 257
BIBLIOGRAPHY 257
APPRAISAL, 259
INDEX, 309
About the Author
Sufyan bin Uzayr is a writer, coder, and entrepreneur with over a decade
of experience in the industry. He has authored several books in the past,
pertaining to a diverse range of topics, ranging from History to Computers/IT.
Sufyan is the Director of Parakozm, a multinational IT company spe-
cializing in EdTech solutions. He also runs Zeba Academy, an online
learning and teaching vertical with a focus on STEM fields. He special-
izes in a wide variety of technologies such as JavaScript, Dart, WordPress,
Drupal, Linux, and Python. He holds multiple degrees including ones in
Management, IT, Literature, and Political Science.
Sufyan is a digital nomad, dividing his time between four countries.
He has lived and taught in numerous universities and educational institu-
tions around the globe. Sufyan takes a keen interest in technology, politics,
literature, history, and sports, and in his spare time, he enjoys teaching
coding and English to young students.
Learn more at sufyanism.com
xix
Acknowledgments
There are many people who deserve to be on this page, for this book would
not have come into existence without their support. That said, some names
deserve a special mention, and I am genuinely grateful to:
xx
Chapter 1
Crash Course in
Objective-C
IN THIS CHAPTER
➢ What is Objective-C
➢ Major Concepts
➢ Advantages and Disadvantages
➢ Syntax and Code Basics
➢ Additional Info
OBJECTIVE-C SPECIFICS
Objective-C is excellent for memory management; there are avail-
able compilers that can turn Objective-C code into static code analy-
sis, which the language then uses to distinguish important information
from “trash.”
The most crucial aspect of Objective-C to understand is that it is very
object-oriented. Using this additional language, you can move graphs and
modify files, but it is crucial to understand its limits to comprehend its
benefits.
Objective-C, a programming language created in the 1980s, retains
many features used in iOS-specific mobile app development. While there
has been no breakthrough that enables Objective-C to be utilized on all
platforms, Objective-C is compatible with C and other languages for iOS
apps.
Objective-C competes with Swift, a more recent iOS programming lan-
guage. Several discussions over whether programming language provides
superior iOS mobile application development outcomes.
WHY OBJECTIVE-C?
For several reasons, the Objective-C programming language is selected.
It’s an object-oriented language, first and foremost. Object-oriented
approaches are required to give the type of capability seen in the Cocoa
frameworks. Second, since Objective-C is an extension of ANSI C, exist-
ing C applications are converted to utilize the software frameworks with-
out sacrificing any of the efforts that went into their creation. Because
Objective-C includes C, you receive all of the advantages of C while deal-
ing with it.
You may select whether to use object-oriented programming methods
(for example, to create a new class) and when to use procedural program-
ming techniques (define a structure and some functions instead of a class).
Furthermore, Objective-C is a very basic programming language. It has
a simple, clear syntax that is simple to pick up.
Crash Course in Objective-C ◾ 3
would be more productive and successful for big software projects; several
senior experts see this as the cause for C++’s widespread acceptance in
the years that followed. According to programming community experts,
C++ is the language used to create most current desktop applications. As
a result of its popularity, many frameworks and libraries have been devel-
oped to extend C++ for functions such as high-performance graphics,
audio digital signal processing, and user interface design.
Both languages are derived from C, but they are two entirely distinct
languages. Objective-C relies heavily on its runtime library to handle
inheritance and polymorphism, while C relies heavily on compile-time
choices for transmission. Nevertheless, in C++, the focus is often on com-
pile-time conclusions. C++ is a middle-level programming language that
runs on several cross-platform operating systems including Windows,
UNIX, Mac OS, etc. Objective-C, in contrast, is a general-purpose, object-
oriented programming language that Apple uses in its operating systems
and Cocoa APIs, etc.
Downsides
FACTORS TO CONSIDER
Objective-C application development may be expedited and is an
excellent approach to adding object-based functionality to an appli-
cation. There are many important considerations about this superset
language:
Maintenance is essential; this pertains to upgrading Objective-C devel-
oped applications. Although the language is dated, it is not outdated. It
merely takes minimal maintenance to remain current.
Less adaption is necessary as many APIs still have a lot to catch up for
Swift-developed applications. This suggests that Objective-C may be sim-
pler to deploy to iOS mobile applications.
Object handling made simpler Apple is all about having an object net-
work. Using Objective-C, these objects are readily movable.
Objective-C may simplify iOS mobile applications in all Apple iOS
devices, including smartphones and tablets.
OBJECTIVE-C OVERVIEW
Objective-C supports object-oriented programming, along with the four
object-oriented development pillars.
• Encapsulation
• Data hiding
• Inheritance
• Polymorphism
Example:
#import <Foundation/Foundation.h>
LEARNING OBJECTIVE-C
When studying Objective-C, the essential thing to remember is to stay
focused on principles rather than getting bogged down in language
technicalities.
The goal of studying a programming language is to become a better
programmer or become more successful at developing, implementing, and
maintaining existing systems.
USING OBJECTIVE-C
As previously stated, Objective-C is utilized in iOS and Mac OS X. It has
a sizable iOS user base and a rapidly growing Mac OS X user base. And
because Apple prioritizes quality, this is fantastic news for individuals who
have just begun learning Objective-C.
EDITOR OF TEXT
This is where we will type our program. Some editors are Windows
Notepad, the OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
On various operating systems, the name and version of the text editor
may differ. Notepad, for example, will be used on Windows, and use vim
or vi on both Windows and Linux or UNIX.
Source files are files that we produce with our editor that contain pro-
gram source code. Objective-C source files are commonly named with the
extension “.m.”
Crash Course in Objective-C ◾ 7
Before starting our programming, make sure we have one text editor
in place, and we have enough knowledge to develop a computer program,
store it in a file, compile it, and eventually run it.
GCC COMPILER
Our program’s source code is written in a source file and is human read-
able. It must “compiled” into machine code before our CPU can run the
program as instructed.
Use this GCC compiler to transform our source code into an executable
application. We’re assuming we’re familiar with programming language
compilers.
The GCC compiler is available for free on various systems, and the tech-
nique for installing it on those platforms is detailed here.
UNIX/LINUX INSTALLATION
The first step is to install gcc and the gcc Objective-C package. This is
accomplished by:
$ su -
$ yum install gcc
$ yum install gcc-objc
$ cd gnustep-startup-<version>
8 ◾ Objective-C
$. /configure
$ make
$ ./usr/GNUstep/System/Library/Makefiles/GNUstep.sh
#import <Foundation/Foundation.h>
MAC OS INSTALLATION
If we’re running Mac OS X, the simplest method to get GCC is to down-
load Apple’s Xcode development environment and follow the straightfor-
ward installation instructions. Once we’ve installed Xcode, we’ll be able to
utilize the GNU C/C++ compiler.
Xcode is presently being downloaded at https://developer.apple.com/
xcode/.
Crash Course in Objective-C ◾ 9
WINDOWS INSTALLATION
To run an Objective-C program on Windows, we must first install MinGW
and GNUStep Core. Download both at: https://www.gnu.org/software/
gnustep/windows/installer.html.
We must first install the MSYS/MinGW System package. The GNUstep
Core package then is installed and both of which have a self-explanatory
Windows setup.
Then, go to Start -> All Programs -> GNUstep -> Shell to utilize
Objective-C and GNUstep.
Navigate to the helloeveryone.m folder.
We may use to compile the code.
• Preprocessor Commands
• Interface
• Implementation
• Method
• Variables
• Statements & Expressions
• Comments
#import <Foundation/Foundation.h>
@interface SampleClass:NSObject
10 ◾ Objective-C
- (void)sampleMethod;
@end
@implementation SampleClass
- (void)sampleMethod {
NSLog(@"Hello, Everyone \n");
}
@end
int main() {
/* first program in the Objective-C */
SampleClass *sampleClass = [[SampleClass alloc]
init];
[sampleClass sampleMethod];
return 0;
}
• The following line, int main(), is the program’s main function, where
execution starts.
Crash Course in Objective-C ◾ 11
• The next line /*…*/ will be disregarded by the compiler and has been
included to provide additional program comments. Therefore, these
lines are known as comments in the program.
• The following line NSLog(…) is an Objective-C function that causes
the message “Hello, Everyone” to appear on the screen.
• The next line return 0; concludes the main() function and returns
the number 0.
OBJECTIVE-C TOKENS
A token is a keyword, an identifier, a constant, a string literal, or a symbol
in an Objective-C program. For instance, the following Objective-C state-
ment is made up of six tokens:
NSLog
@
(
"Hello, Everyone \n"
)
;
SEMICOLONS;
A semicolon is a statement terminator in an Objective-C program. That is, a
semicolon must follow each sentence. It denotes the end of a single logical entity.
For example, consider the following two statements:
COMMENTS
Comments are similar to help text in our Objective-C application and are
disregarded by the compiler. As illustrated below, they begin with/* and
end with the characters */.
IDENTIFIERS
An Objective-C identifier recognizes a variable, function, or other user-
defined items. An identifier starts with a letter A to Z, a to z, or an under-
score and ends with zero or more letters, underscores, or numbers (0 to 9).
Punctuation characters such as @, $, and per cent are not permitted
within identifiers in Objective-C. Objective-C is a computer language
that is case sensitive. Thus, in Objective-C, Manpower and manpower
are two different IDs. The following are some instances of appropriate
identifiers:
KEYWORDS
The following is a list of reserved terms in Objective-C. These reserved
terms are not permitted to be used as constant, variable, or other identifier
names.
WHITESPACE IN OBJECTIVE-C
A blank line has simply whitespace, potentially with a remark, and is com-
pletely ignored by an Objective-C compiler.
In Objective-C, whitespace refers to blanks, tabs, newline charac-
ters, and comments. Whitespace divides one section of a statement from
Crash Course in Objective-C ◾ 13
another and allows the compiler to determine where one element, such
as int, ends, and the next element starts in a statement. As a result, in the
following sentence
int ages;
For the compiler to distinguish between int and age, there must be at
least one whitespace character (typically a space). In contrast, the follow-
ing statement,
The aggregate types are the array and structure types combined. A
function’s type indicates the type of the function’s return value.
14 ◾ Objective-C
TYPES OF INTEGERS
The table below contains information on standard integer types, including
storage sizes and value ranges.
The sizeof operator can determine the precise size of a type or variable
on a specific platform. The phrase sizeof(type) returns the object or type’s
storage size in bytes. The following is an example of determining the size
of an int type on any computer.
#import <Foundation/Foundation.h>
int main() {
NSLog(@"The Storage size for int : %d \n",
sizeof(int));
return 0;
}
TYPES OF FLOATING-POINT
The table below contains information on typical float-point types, includ-
ing storage sizes, value ranges, and precision.
The float.h header file includes macros that let us use these values and
other information about the binary representation of real numbers in our
applications. The following example will output the storage space occupied
by a float type and its range values.
Crash Course in Objective-C ◾ 15
#import <Foundation/Foundation.h>
int main() {
NSLog(@"The Storage size for float : %d \n",
sizeof(float));
return 0;
}
VOID TYPE
The void type indicates that there is no value available. It is used in three
different contexts.
VARIABLES IN OBJECTIVE-C
A variable is just the name assigned to a storage location that our pro-
grams may access. In Objective-C, each variable has a type that governs
the amount and layout of the variable’s memory, the range of values stored
inside that memory, and the set of operations that can apply to the variable.
A variable’s name can be letters, numbers, and the underscore char-
acter. Start it with a letter or an underscore. Because Objective-C is case-
sensitive, upper and lowercase letters are different.
type variablelist;
In this case, a type must be a valid Objective-C data type, such as char,
w char, int, float, double, bool, or any user-defined object. The variable list
can have one or more identifier names separated by commas. Here are
some examples of valid declarations.
int c, d, e;
char k, kh;
float g, salary;
double q;
The line int c, d, e; declares and defines the variables c, d, and e; and tells
the compiler to create variables of type int called c, d, and e.
In their declaration, variables can be initialized (given an initial value).
The initializer is made of an equal sign followed by a constant expression,
as seen below.
Example:
extern int c = 3, d = 5; // declaration of c
and d.
int c = 3, d = 5; // definition and
initializing c and d.
byte k = 22; // definition and
initializes k.
char y = 'y'; // the variable y has
the value 'y'.
Crash Course in Objective-C ◾ 17
// Variable-declaration:
extern int x, y;
extern int z;
extern float f;
int main () {
/* variable-definition: */
int x, y;
int z;
float f;
/* actual-initialization */
x = 10;
y = 20;
z = x + y;
NSLog(@"The value of z : %d \n", z);
f = 70.0/3.0;
NSLog(@"The value of f : %f \n", f);
return 0;
}
18 ◾ Objective-C
// function-declaration
int func();
int main() {
// function-call
int k = func();
}
// function-definition
int func() {
return 0;
}
Variables are lvalues and can thus appear on the left side of an assign-
ment. Because numerical literals are rvalues, they cannot be allocated
and cannot appear on the left-hand side. The following is a correct
statement:
int k = 20;
CONSTANTS IN OBJECTIVE-C
The constants denote values that the program cannot modify during its
execution. These values are also known as literals.
Any fundamental data type may include integer constants, floating
constants, character constants, and string literals. Additionally, there are
enumeration constants.
The constants are processed identically to regular variables, except their
values are not altered once they are defined.
INTEGER LITERALS
An integer literal may be a decimal, octal, or hexadecimal constant. The
base or radix is specified by a prefix: 0x or 0X for hexadecimal, 0 for octal,
and nothing for decimal.
A literal integer may also include a suffix consisting of U and L, which
stand for unsigned and long, respectively. Write the suffix with uppercase
or lowercase letters and in any sequence.
The following are instances of integer literals:
414 /* Legal */
235u /* Legal */
0xFeeL /* Legal */
068 /* Illegal: 8 is not octal digit */
032UU /* Illegal: cannot repeat suffix */
95 /* decimal */
0215 /* octal */
0x6b /* hexadecimal */
50 /* int */
50u /* unsigned int */
50l /* long */
50ul /* unsigned long */
FLOATING-POINT LITERALS
An integer part, a decimal point, a fractional part, and an exponent part
comprise a floating-point literal. Floating-point literals can be represented
in either decimal or exponential form.
When representing in decimal form, including the decimal point, expo-
nent, or both; when representing in exponential form, include the integer
portion, fractional part, or both. e or E introduces the signed exponent.
20 ◾ Objective-C
3.14159 /* Legal */
314159E-5L /* Legal */
510E /* Illegal: the incomplete exponent */
210f /* Illegal: no-decimal or exponent */
.e55 /* Illegal: missing integer or the
fraction */
CHARACTER CONSTANTS
Character literals, such as ‘x,’ are contained in single quotes and may be
kept in a simple char variable.
A character literal in Objective-C can be a simple character (for exam-
ple, ‘x’), an escape sequence (for example, ‘\t’), or a universal character (for
example, ‘u02C0’).
Certain letters in C have unique significance when followed by a back-
slash and signify things like newline (\n) or tab (\t). A list of some of these
escape sequence codes is as follows.
#import <Foundation/Foundation.h>
int main() {
NSLog(@"Hello\tEveryone\n\n");
return 0;
}
Crash Course in Objective-C ◾ 21
STRING LITERALS
Double quotes “” are used to surround string literals or constants.
Characters in a string are comparable to character literals in that they
are plain characters, escape sequences, and universal characters. We can
divide an extensive line into numerous lines using string literals and
whitespaces.
Here are some string literal instances. The strings in all three variants
are identical.
"hello, sweetie"
"hello, \
sweetie"
CONSTANT DEFINITION
In C, there are two straightforward ways to define constants.
#define Preprocessor
The following is the syntax for using the #define preprocessor to declare a
constant:
#define identifiervalue
Example:
#import <Foundation/Foundation.h>
#define LENGTH 10
#define WIDTH 5
#define NEWLINE '\n'
int main() {
int area;
22 ◾ Objective-C
const Keyword
Constants of a specific type can be declared with the const prefix, as seen
below.
Example:
#import <Foundation/Foundation.h>
int main() {
const int LENGTH = 20;
const int WIDTH = 15;
const char NEWLINE = '\n';
int area;
area = LENGTH * WIDTH;
NSLog(@"The value of area : %d", area);
NSLog(@"%c", NEWLINE);
return 0;
}
OPERATORS IN OBJECTIVE-C
An operator in Objective-C is a symbol that instructs the compiler to do
particular mathematical or logical operations. The Objective-C language
has several built-in operators, including the following:
• Arithmetic Operators
• Assignment Operators
• Relational Operators
• Bitwise Operators
• Logical Operators
• Misc Operators
Crash Course in Objective-C ◾ 23
RELATIONAL OPERATORS
The table below lists all the relational operations provided by the
Objective-C programming language. Assume variable C has a value of 20
and variable D has a value of 30, then.
BITWISE OPERATORS
The bitwise operator operates on bits and performs operations bit by bit.
The truth tables for &, |, and are shown below.
C = 0011 1100
D = 0000 1101
-----------------
C&D = 0000 1100
C|D = 0011 1101
C^D = 0011 0001
˜C = 1100 0011
ASSIGNMENT OPERATORS
The Objective-C language supports the following assignment operators:
(Continued)
26 ◾ Objective-C
LOOPS IN OBJECTIVE-C
There may be events when we need to execute a code block numerous times.
In general, statements are performed in the following order: the first state-
ment in a function is executed first, then the second, and so on. Control
structures in programming languages allow for more sophisticated execu-
tion routes. A loop statement allows us to run a statement or collection of
statements many times. The Objective-C programming language includes
the following loop types to address looping needs.
Loop in Objective-C.
28 ◾ Objective-C
INFINITE LOOP
If condition never becomes false, loop becomes endless. Traditionally, the
for loop is used for this purpose. Because none of the three for loop expres-
sions are necessary, we may create an infinite loop by leaving the condi-
tional expression empty.
#import <Foundation/Foundation.h>
int main () {
for( ; ; ) {
NSLog(@"loop will run forever.\n");
}
return 0;
}
Crash Course in Objective-C ◾ 29
“Well, you can stay back in camp, and have the wood all
cut and the dinner cooked for us when we get back,”
said his father.
“Ho, that’s no hike at all, if you take three days for it!”
Bennie said. “I been looking on the map. It’s less ’n ten
miles from here to the top of the mountain, and the top
is only 8,938 feet high, so it’s only a 2,000-foot climb.”
139
“How much better you know this country than I do,”
said his uncle, quietly, “and how skilfully you can read
the contour intervals on a map. Well, you may go over
and back the same day, if you want to. The rest of us
will take three, however.”
Spider, meanwhile, had gone to his pack and got out the
government topographical survey map of Crater Lake
Park.
“Suits me fine.”
But everybody dove, with another groan, into the tents, 141
to get their dirty clothes.
“Try rubbing ’em with a little fish oil, Bennie,” Spider put 142
in.
“We were all much obliged to you for what you did
today. Never mind the joshing.”
144
CHAPTER XV
The Long Hike—The Scouts Find Packing
Grub and Blanket Rolls Up and Down Cliffs
is Hard Work
Each member of the party put in his shoulder pack his 145
own food ration, consisting of tea (because it is lighter
than coffee), some bacon, powdered egg, a little
dehydrated vegetables, a small bag of flour, a small bag
of sugar, a package of bouillon cubes, a can of
preserved fruit, a small can of condensed milk, two
pounds of raisins, two boiled potatoes, and several
cakes of sweet chocolate. In addition, each person put
in two extra pairs of wool socks, and a set of
underclothes. Then, out of their sleeping bags, they
each took a double blanket, and made a blanket roll,
fastening the ends with straps from the motors. Bennie
and Spider each had a boy scout individual cook-kit, in a
khaki case with a shoulder strap. These two kits, with a
tin cup and plate and spoon for the others, and one,
larger frying-pan and kettle carried by Uncle Billy, was
all the cooking outfit they carried. However, the doctor
made everybody carry a canteen, and Bennie, Spider
and Mr. Stone each carried a camera. Everybody had a
sweater, also, and two belt axes were taken. The doctor
had his rope.
When the shoulder packs were on, and the blanket rolls,
and the canteens, and the cameras and camp kits,
everybody was glad enough of the alpenstocks which
the doctor handed around.
146
“Wonder what makes people ask foolish questions?”
Dumplin’ mused.
For the first half mile, they had a trail, the trail they had
already taken up Garfield Peak. But half-way up, they
left the trail, and struck right out, without any path at
all, around the tumbled crags of broken lava, and over
the snow-fields and patches of soft pumice soil that
crown this part of the rim on the southeastern side of
the lake. The going was very slow and difficult, up hill
and down, in and out among the rises and dips, with
the sun beating down upon them till their packs and hot
blankets seemed almost unbearable. At first, they could
see the blue lake almost 2,000 feet below them, while
they worked along the crest of Eagle Crags, but after a
while they had to drop down behind the rim to avoid a
climb up Dyar Rock, and lost all sight of it.
“Mine, too.”
“Mine, too.”
“Mine, too.”
“Wait till they get really heavy before you kick,” said
Uncle Billy. “Forward, march!”
150
“You’re too hot to go in that ice water,” the doctor said,
grabbing Bennie. “Wash your feet all you want to, and
splash yourselves.”
“And it’s against you all the time,” said Mr. Stone.
Uncle Billy smiled. “We may get a little exploring yet, 153
before we get back to Portland. You never can tell. Well,
who’s going to sleep tonight?”
“I guess we all are.”
154
CHAPTER XVI
The Climb Up Scott Peak—Bennie Begins
Work for a Merit Badge for Hiking
When they were warmed up again, they lay down once 156
more, and managed to doze off. But long before
morning, Bennie woke to see first Mr. Stone and then
his uncle putting more wood on the fire. It wasn’t yet
dawn—just the first hint of lightness in the sky—when
Bennie finally woke up so cold and so stiff and
uncomfortable from the hard ground, that further sleep
seemed impossible. He was just rousing himself to put
on more wood when he heard Spider stir, and then sit
up.
ebookbell.com