Object Oriented Programming with Swift 2 1st Edition Gastón C Hillar - The ebook in PDF format with all chapters is ready for download
Object Oriented Programming with Swift 2 1st Edition Gastón C Hillar - The ebook in PDF format with all chapters is ready for download
com
https://ebookmeta.com/product/object-oriented-programming-
with-swift-2-1st-edition-gaston-c-hillar/
OR CLICK HERE
DOWLOAD EBOOK
https://ebookmeta.com/product/real-time-c-efficient-object-oriented-
and-template-microcontroller-programming-christopher-kormanyos/
ebookmeta.com
https://ebookmeta.com/product/swift-3-protocol-oriented-programming-
hoffman-jon/
ebookmeta.com
https://ebookmeta.com/product/dominant-desire-decadent-sins-2-1st-
edition-linzi-basset/
ebookmeta.com
The Portrait and the Book Illustration and Literary
Culture in Early America 1st Edition Walsh
https://ebookmeta.com/product/the-portrait-and-the-book-illustration-
and-literary-culture-in-early-america-1st-edition-walsh/
ebookmeta.com
https://ebookmeta.com/product/practical-channel-aware-resource-
allocation-with-matlab-and-python-code-michael-ghorbanzadeh/
ebookmeta.com
https://ebookmeta.com/product/the-tiger-s-mail-order-bride-shifter-
mail-order-bride-agency-5-1st-edition-ruby-knoxx/
ebookmeta.com
https://ebookmeta.com/product/sapientia-naturae-the-wisdom-of-nature-
cory-edmund-endrulat/
ebookmeta.com
Physically Based Rendering fourth edition From Theory to
Implementation Matt Pharr
https://ebookmeta.com/product/physically-based-rendering-fourth-
edition-from-theory-to-implementation-matt-pharr/
ebookmeta.com
Table of Contents
Object–Oriented Programming with Swift 2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
eBooks, discount offers, and more
Questions
1. Objects from the Real World to Playground
Installing the required software
Capturing objects from the real world
Generating classes to create objects
Recognizing variables and constants to create properties
Recognizing actions to create methods
Organizing classes with UML diagrams
Working with API objects in the Xcode Playground
Exercises
Test your knowledge
Summary
2. Structures, Classes, and Instances
Understanding structures, classes, and instances
Understanding initialization and its customization
Understanding deinitialization and its customization
Understanding automatic reference counting
Declaring classes
Customizing initialization
Customizing deinitialization
Creating the instances of classes
Exercises
Test your knowledge
Summary
3. Encapsulation of Data with Properties
Understanding the elements that compose a class
Declaring stored properties
Generating computed properties with setters and getters
Combining setters, getters, and a related property
Understanding property observers
Transforming values with setters and getters
Using type properties to create values shared by all the instances of a
class
Creating mutable classes
Building immutable classes
Exercises
Test your knowledge
Summary
4. Inheritance, Abstraction, and Specialization
Creating class hierarchies to abstract and specialize behavior
Understanding inheritance
Declaring classes that inherit from another class
Overriding and overloading methods
Overriding properties
Controlling whether subclasses can or cannot override members
Working with typecasting and polymorphism
Taking advantage of operator overloading
Declaring operator functions for specific subclasses
Exercises
Test your knowledge
Summary
5. Contract Programming with Protocols
Understanding how protocols work in combination with classes
Declaring protocols
Declaring classes that adopt protocols
Taking advantage of the multiple inheritance of protocols
Combining inheritance and protocols
Working with methods that receive protocols as arguments
Downcasting with protocols and classes
Treating instances of a protocol type as a different subclass
Specifying requirements for properties
Specifying requirements for methods
Combining class inheritance with protocol inheritance
Exercises
Test your knowledge
Summary
6. Maximization of Code Reuse with Generic Code
Understanding parametric polymorphism and generic code
Declaring a protocol to be used as a constraint
Declaring a class that conforms to multiple protocols
Declaring subclasses that inherit the conformance to protocols
Declaring a class that works with a constrained generic type
Using a generic class for multiple types
Combining initializer requirements in protocols with generic types
Declaring associated types in protocols
Creating shortcuts with subscripts
Declaring a class that works with two constrained generic types
Using a generic class with two generic type parameters
Inheriting and adding associated types in protocols
Generalizing existing classes with generics
Extending base types to conform to custom protocols
Test your knowledge
Exercises
Summary
7. Object-Oriented Programming and Functional Programming
Refactoring code to take advantage of object-oriented programming
Understanding functions as first-class citizens
Working with function types within classes
Creating a functional version of array filtering
Writing equivalent closures with simplified code
Creating a data repository with generics and protocols
Filtering arrays with complex conditions
Using map to transform values
Combining map with reduce
Chaining filter, map, and reduce
Solving algorithms with reduce
Exercises
Test your knowledge
Summary
8. Extending and Building Object-Oriented Code
Putting together all the pieces of the object-oriented puzzle
Adding methods with extensions
Adding computed properties to a base type with extensions
Declaring new convenience initializers with extensions
Defining subscripts with extensions
Working with object-oriented code in apps
Adding an object-oriented data repository to a project
Interacting with an object-oriented data repository through Picker View
Exercises
Test your knowledge
Summary
A. Exercise Answers
Chapter 1, Objects from the Real World to Playground
Chapter 2, Structures, Classes, and Instances
Chapter 3, Encapsulation of Data with Properties
Chapter 4, Inheritance, Abstraction, and Specialization
Chapter 5, Contract Programming with Protocols
Chapter 6, Maximization of Code Reuse with Generic Code
Chapter 7, Object-Oriented Programming and Functional Programming
Chapter 8, Extending and Building Object-Oriented Code
Index
Object–Oriented
Programming with Swift 2
Object–Oriented
Programming with Swift 2
Copyright © 2016 Packt Publishing All rights reserved.
No part of this book may be reproduced, stored in a
retrieval system, or transmitted in any form or by any
means, without the prior written permission of the
publisher, except in the case of brief quotations
embedded in critical articles or reviews.
Livery Place
35 Livery Street
ISBN 978-1-78588-569-3
www.packtpub.com
Credits
Author
Vinod Madigeri
Hugo Solis
Commissioning Editor
Nadeem Bagban
Reshma Raman
Divij Kotian
Technical Editor
Parag Topre
Copy Editor
Shruti Iyer
Project Coordinator
Nikhil Nair
Proofreader
Safis Editing
Indexer
Disha Haria
Production Coordinator
Nilesh Mohite
Cover Work
Nilesh Mohite
About the Author
Gastón C. Hillar is an Italian and has been working with
computers since he was 8 years old. In the early 80s, he
began programming with the legendary Texas TI-99/4A
and Commodore 64 home computers. Gaston has a
bachelor's degree in computer science and graduated
with honors. He also holds an MBA in which he
graduated with an outstanding thesis. At present, Gaston
is an independent IT consultant and a freelance author
who is always looking for new adventures around the
world.
He lives with his wife, Vanesa, and his two sons, Kevin
and Brandon.
About the Reviewers
Vinod Madigeri is a curious developer with a particular
interest in object-oriented programming. He has worked
in different industries (telecommunication, game
technologies, and consumer electronics) writing software
in C, C++, Objective-C, Swift, and C#.
https://www2.packtpub.com/books/subscription/packtlib
Why subscribe?
Fully searchable across every book published by Packt
Animal created
Mammal created
DomesticMammal created
Dog created
TerrierDog created
SmoothFoxTerrier created
I am 7 years old.
I am 14 years old.
I am 21 years old.
I am 4 years old.
I am 5 years old.
NOTE
Warnings or important notes appear in a box like this.
TIP
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us
know what you think about this book—what you liked or
disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.
Errata
Although we have taken every care to ensure the
accuracy of our content, mistakes do happen. If you find
a mistake in one of our books—maybe a mistake in the
text or the code—we would be grateful if you could
report this to us. By doing so, you can save other
readers from frustration and help us improve subsequent
versions of this book. If you find any errata, please report
them by visiting http://www.packtpub.com/submit-errata,
selecting your book, clicking on the Errata Submission
Form link, and entering the details of your errata. Once
your errata are verified, your submission will be accepted
and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of
that title.
Piracy
Piracy of copyrighted material on the Internet is an
ongoing problem across all media. At Packt, we take the
protection of our copyright and licenses very seriously. If
you come across any illegal copies of our works in any
form on the Internet, please provide us with the location
address or website name immediately so that we can
pursue a remedy.
Questions
If you have a problem with any aspect of this book, you
can contact us at <questions@packtpub.com>, and
we will do our best to address the problem.
Chapter 1. Objects from the
Real World to Playground
Whenever you have to solve a problem in the real world,
you use elements and interact with them. For example,
when you are thirsty, you take a glass, you fill it up with
water, soda, or your favorite juice, and then you drink.
Similarly, you can easily recognize elements, known as
objects, from real-world actions and then translate them
into object-oriented code. In this chapter, we will start
learning the principles of object-oriented programming to
use them in the Swift programming language to develop
apps and applications.
TIP
In case you want to work with the Swift open source release, you can download the latest
development snapshot in the Downloads section at http://swift.org. You can run all the
code examples included in the book in the Swift Read Evaluate Print Loop command-line
environment instead of working with Xcode Playground. The Swift Read Evaluate Print
Loop command-line environment is also known as Swift REPL.
The perimeter
The area
Squares
Equilateral triangles
Rectangles
Circles
Ellipses
Regular hexagons
calculateSquareArea
calculateEquilateralTriangleArea
calculateRectangleArea
calculateCircleArea
calculateEllipseArea
calculateRegularHexagonArea
calculateSquarePerimeter
calculateEquilateralTrianglePerimeter
calculateRectanglePerimeter
calculateCirclePerimeter
calculateEllipsePerimeter
calculateRegularHexagonPerimeter
Equilateral triangles
Rectangles
Circles
Ellipses
Regular hexagons
Now, let's move to the real world and think about each of
the previously enumerated six shapes. Imagine that we
have to draw each of the shapes on paper and calculate
their areas and perimeters. After we draw each shape,
which values will we use to calculate their areas and
perimeters? Which formulas will we use?
TIP
We started working on an object-oriented design before we started coding, and therefore,
we will work as if we didn't know many concepts of geometry. For example, we can easily
generalize the formulas that we use to calculate the perimeters and areas of regular
polygons. However, we will analyze the requirements in most cases; we still aren't experts
on the subject, and we need to dive deeper into the subject before we can group classes
and generalize their behavior.
Language: English
CHRONICLES
OF
ENGUERRAND DE MONSTRELET.
CHRONICLES
OF
ENGUERRAND DE MONSTRELET;
CONTAINING
AND OF OTHER
FRENCH,
Beginning at the Year MCCCC. where that of Sir JOHN FROISSART finishes, and
ending
at the Year MCCCCLXVII. and continued by others to the Year MDXVI.
TRANSLATED
LONDON:
1810.
CONTENTS
OF
HERE BEGINNETH
CHRONICLES
OF
ENGUERRAND DE MONSTRELET.
[A.D. 1431.]
CHAP. I.
SOME CAPTAINS ATTACHED TO SIR JOHN DE LUXEMBOURG
SURPRISE THE CASTLE OF ST MARTIN, WHEREIN THEY ARE ALL
TAKEN AND SLAIN.
At the commencement of this year, some of the captains attached to
sir John de Luxembourg, such as sir Simon de Lalain, Bertrand de
Manicain, Enguerrand de Crequi, Enguerrand de Gribauval marched
from the borders of the Laonnois with four hundred combatants to
the abbey of St Vincent, near Laon, wherein were a body of French.
They gained it by surprise, and on their entrance they set up a loud
shout, which awakened part of the enemy within a strong gateway,
who instantly defended themselves with vigour; and, during this, the
lord de Pennesac, then in Laon, was told what had happened. He
immediately collected a force to succour those in the gate, who were
gallantly defending themselves; and his men at arms, enraged to
find the enemy so near, lost no time in putting on their armour.
They soon marched out of Laon to the assistance of their friends
then fighting; but a part of the Burgundians, without finishing their
enterprise, or providing for what might happen, had quitted the
combat to plunder the abbey. They were, therefore, unexpectedly
attacked by these men at arms, and with such vigour that they were
totally defeated, and sixty of the principal were left dead on the
spot: in the number were Bertrand de Manicain and Enguerrand de
Gribauval. The last offered a large ransom for his life; but it was
refused, by reason of the great hatred the common people bore him
for the very many mischiefs he had long before done them.
Sir Simon de Lalain was made prisoner, and had his life spared
through the means of a gallant youth of the garrison named
Archanciel, who was much beloved by the commonalty. Enguerrand
de Crequi was taken at the same time with sir Simon and a few
others; but the remainder, witnessing their ill success, retreated to
the places whence they had come.
Sir John de Luxembourg was much afflicted at this event, and not
without cause, for he had lost in the affair some of his ablest
captains. The brother of the lord de Pennesac, called James, was
killed.
At the same time, the castle of Rambures, belonging to the lord de
Rambures, then a prisoner in England, was won by the French,
under the command of Charles des Marests, who took it by scalado.
Ferry de Mailly was the governor of it for king Henry. The French, by
this capture, opened a free communication with the country of
Vimeu and those adjoining, as shall hereafter be shewn.
CHAP. II.
POTON DE SAINTRAILLES AND SIR LOUIS DE VAUCOURT ARE
MADE PRISONERS BY THE ENGLISH.
In this year, the marshal de Bousac, Poton de Saintrailles, sir Louis
de Vaucourt, and others of king Charles's captains, set out from
Beauvais with about eight hundred combatants to seek adventures,
and to forage the country near to Gournay. With them was a very
young shepherd's boy, who was desirous to raise his name in the
same way that the Maid had done.
The earl of Warwick had notice of their march, and collected with all
haste about six hundred fighting men, whom he led toward Beauvais
to meet the enemy. He came up with them, unexpectedly, near to
Gournay, and commenced a sharp conflict, in which so little
resistance was made by the French that they were soon put to the
rout, and Poton de Saintrailles, sir Louis de Vaucourt, and about sixty
combatants, were made prisoners. The rest, with the exception of
eight or ten who were slain, made their escape with the marshal to
Beauvais.
The English pursued them to the walls of that town, when the earl of
Warwick, assembling his men, returned to Gournay, happy at his
good success; and thence he went to the duke of Bedford in Rouen,
by whom he was joyfully congratulated on his victory.
CHAP. III.
MAILLOTIN DE BOURS AND SIR HECTOR DE FLAVY FIGHT
TOGETHER IN THE TOWN OF ARRAS.
On the 20th day of June in this year, a combat took place in the
town of Arras, and in the presence of the duke of Burgundy,
between Maillotin de Bours, appellant, and sir Hector de Flavy,