tag:blogger.com,1999:blog-12664800153457888922024-03-13T15:00:19.138-07:00Mastering SwiftJonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.comBlogger39125tag:blogger.com,1999:blog-1266480015345788892.post-45888726562639535832020-11-26T15:48:00.008-08:002020-11-26T15:52:41.685-08:00Mastering Swift 5.3<div class="separator" style="clear: both; text-align: left;"><a href="https://amzn.to/36a22XL" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="500" data-original-width="406" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjtpt0FNLIKlxt4GXG9NT1FGUcLH-7w4WoxAzpvcCi5bMf6dqzyPFmStHzWVCpaJ_ZHda4p6PlxdyRvLABob8JV7xyrTRoh8qKmXk5qXAVTg9wjfiRerQcGBwRo4UtMBL5dhELohix9TI9/w163-h200/cover.jpg" width="163" /></a></div>The latest edition in my Mastering Swift series has just been released. It has been updated for the latest release of Swift and has two new chapters.<div><p class="paragraph" style="font-family: "Times New Roman", serif; margin-left: 0in; margin-right: 0in; text-align: justify; vertical-align: baseline;"><span style="font-family: Cambria, serif;">Over the years, Mastering Swift has proved itself among developers as a popular choice as an in-depth and practical guide to the Swift programming language. This sixth edition comes with the latest features, overall revision to align with Swift 5.3, and two new chapters on building swift from source and advance operators. <o:p></o:p></span></p><p class="paragraph" style="font-family: "Times New Roman", serif; margin-left: 0in; margin-right: 0in; text-align: justify; vertical-align: baseline;"><span style="font-family: Cambria, serif;">From the basics of the language to popular features such as concurrency, generics, and memory management, this in-depth guide will help you develop your expertise and mastery in the language.<o:p></o:p></span></p><p class="paragraph" style="font-family: "Times New Roman", serif; margin-left: 0in; margin-right: 0in; text-align: justify; vertical-align: baseline;"><span style="font-family: Cambria, serif;">As you progress, you will gain practical insights into some of the most sophisticated elements in Swift development, including protocol extensions, error handling, and closures. The book will also show you how to use and apply them in your own projects. In later chapters, you will understand how to use the power of protocol-oriented programming to write flexible and easier-to-manage code. Finally, you will learn how to add the copy-on-write feature to your custom value types, along with understanding how to avoid memory management issues caused by strong reference cycles.<o:p></o:p></span></p><p class="paragraph" style="font-family: "Times New Roman", serif; margin-left: 0in; margin-right: 0in; text-align: justify; vertical-align: baseline;"><span style="font-family: Cambria, serif;">By the end of this book, you will have mastered the Swift 5.3 language and developed the skills you need to effectively use its features to build robust applications.</span><span style="font-family: Cambria, serif;"><o:p></o:p></span></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 1</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Taking the first steps with Swift</span></span>, will introduce you to the Swift programming language and discuss what inspired Apple to create Swift. We'll also go over the basic syntax of Swift and how to use Playgrounds to experiment and test Swift code.<o:p></o:p></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 2</span>,<span style="color: red;"> <span class="ItalicsPACKT" style="font-style: italic;">Swift documentation and installation</span></span>, will introduce the user to the swift.org and swiftdoc.org sites and how the swift development process works. We will go through the complete process of building swift from source and installing it on both the Linux and Mac platforms.<o:p></o:p></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 3</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Learning about variables, constants, strings and operators</span></span>, will introduce variables and constants in Swift and when to use them. There will be brief overviews of the most common variable types with examples on how to use them. We'll conclude this chapter by showing examples of how to use the most common operators in the Swift language<o:p></o:p></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 4</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Optional Types</span></span>, will explain what optional types really are, what are the various ways to unwrap them. For a developer who is just learning Swift, optional types can be one of the more confusing items to learn.<o:p></o:p></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 5</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Using Swift collections</span></span>, will explain Swift's array, set, and dictionary collection types and show examples on how to use them.<span face="Roboto-Bold" style="color: #262626; font-size: 16pt;"><o:p></o:p></span></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 6</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Control Flow</span></span>, will show you how to use Swift's control flow statements. These include looping, conditional, and control transfer statements.<o:p></o:p></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 7</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Functions</span></span>, This chapter is all about functions in Swift. We will show how to define and properly use them<o:p></o:p></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 8</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Classes, Structures and Protocols</span></span>, This chapter is dedicated to Swift's classes, structures and protocols. We'll look at what makes them similar and what makes them different.<o:p></o:p></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 9</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Protocol and Protocol Extensions</span></span>, will cover both protocols and protocol extensions in detail since protocols are very important to the Swift language, and having a solid understanding of them will help us write flexible and reusable code<o:p></o:p></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 10</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Protocol Oriented Design</span></span>, will cover the best practices of Protocol Oriented Design with Swift.<span face="Roboto-Regular" style="color: #262626; font-size: 16pt;"> <o:p></o:p></span></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 11</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Generics</span></span>, will explain how Swift implements generics. Generics allow us to write very flexible and reusable code that avoids duplication <o:p></o:p></p><p class="MsoNormal" style="font-family: Arial, sans-serif; font-size: 10pt; margin: 3pt 0in;"><span class="ChapterrefPACKT" style="color: olive; font-family: "Times New Roman", serif; font-style: italic; vertical-align: baseline;"><span style="font-size: 11pt;">Chapter 12</span></span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Availability and Error Handling</span></span>, <span class="NormalPACKTChar" style="font-family: "Times New Roman", serif;"><span style="font-size: 11pt;">will cover error handling in depth as well as the availability feature.</span></span><span face="Roboto-Regular" style="color: #262626; font-size: 16pt;"><o:p></o:p></span></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 13</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Custom Subscripting</span></span><span class="ItalicsPACKT" style="color: #ff99cc; font-style: italic;">,</span> will discuss how we can use custom subscripts in our classes, structures, and enumerations. <span face="Roboto-Regular" style="color: #262626; font-size: 16pt;"><o:p></o:p></span></p><p class="MsoNormal" style="font-family: Arial, sans-serif; font-size: 10pt; margin: 3pt 0in;"><span class="ChapterrefPACKT" style="color: olive; font-family: "Times New Roman", serif; font-style: italic; vertical-align: baseline;"><span style="font-size: 11pt;">Chapter 14</span></span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Working with Closures</span></span>, <span class="NormalPACKTChar" style="font-family: "Times New Roman", serif;"><span style="font-size: 11pt;">will show how to define and use closures in our code. This chapter concludes with a section on how to avoid strong reference cycles with closures<o:p></o:p></span></span></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 15</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Advanced and Custom Operators</span></span>, will show how to use bitwise and overflow operators. We will also look at how we can create custom operators<o:p></o:p></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 16</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Concurrency and Parallelism</span></span>, will show how to use both Grand Central Dispatch and Operation Queues to add concurrency and parallelism to our applications<i><span style="color: #ff99cc;"><o:p></o:p></span></i></p><p class="MsoNormal" style="font-family: Arial, sans-serif; font-size: 10pt; margin: 3pt 0in;"><span class="ChapterrefPACKT" style="color: olive; font-family: "Times New Roman", serif; font-style: italic; vertical-align: baseline;"><span style="font-size: 11pt;">Chapter 17</span></span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Custom Value Types</span></span>, <span class="NormalPACKTChar" style="font-family: "Times New Roman", serif;"><span style="font-size: 11pt;">will cover some advance techniques that the reader can use in their applications like copy-on-write and implementing the equatible protocol.</span></span><span face="Roboto-Regular" style="color: #262626; font-size: 16pt;"><o:p></o:p></span></p><p class="MsoNormal" style="font-family: Arial, sans-serif; font-size: 10pt; margin: 3pt 0in;"><span class="ChapterrefPACKT" style="color: olive; font-family: "Times New Roman", serif; font-style: italic; vertical-align: baseline;"><span style="font-size: 11pt;">Chapter 18</span></span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Memory Management</span></span>, <span class="NormalPACKTChar" style="font-family: "Times New Roman", serif;"><span style="font-size: 11pt;">will cover items like how Automatic Reference Counting (ARC) works, how much faster value types are as compared to reference types, strong retain cycles, weak vs strong references</span></span><span style="font-family: "Times New Roman", serif; font-size: 11pt;"><o:p></o:p></span></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 19</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Swift Formatting</span></span>, will define a style guide for the Swift language that can be used as a template for enterprise developers who need to create a style guide<span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;"><o:p></o:p></span></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;"><span class="ChapterrefPACKT" style="color: olive; font-style: italic; vertical-align: baseline;">Chapter 20</span>, <span class="ItalicsPACKT" style="font-style: italic;"><span style="color: red;">Adopting Design Patterns with Swift</span></span>, will show you how to implement some of the more common design patterns in Swift. A design pattern identifies a common software development problem and provides a strategy for dealing with it<o:p></o:p></p><p class="NormalPACKT" style="font-family: "Times New Roman", serif; font-size: 11pt; margin: 0in 0in 6pt;">You can purchase a copy of my book from <a href="https://amzn.to/2Jly75G" target="_blank">Amazon</a> or from Packt Publishing.</p></div>Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-7991287179979372812020-04-30T13:46:00.000-07:002020-04-30T13:46:28.159-07:00Compile Swift for Linux with its Toolchain and Package Manager<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
If you are unable to install Swift with pre-built binaries, you can compile it instead. Compiling is a lot more complex and confusing than simply installing prebuilt binaries and I found that a lot of instructions do not build the Swift package manager which I consider to be a necessity when build anything more complex than a simple hello world application. In this post we look at how we can build Swift with its full toolchain and package manager.<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<h1 style="break-after: avoid; color: #2f5496; font-family: "Calibri Light", sans-serif; font-size: 16pt; font-weight: normal; margin: 12pt 0in 0.0001pt;">
Install Dependencies<o:p></o:p></h1>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
The first thing we need to do is to make sure we have all of the dependencies required installed. The following command includes all dependencies I have needed to install on different flavors of Linux. You will find that your distribution probably already has a lot of these preinstalled but to make sure you have everything, run this command.<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 1pt 1pt 4pt;">
<div class="Code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libcurl4-openssl-dev systemtap-sdt-dev tzdata rsync python-pip<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
If you want to build the documentation, you will need to install Sphinx as well. This can be done with the following command:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 1pt 1pt 4pt;">
<div class="Code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
pip install Sphinx<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now that we have all of the dependencies installed, we need to get the swift source code.</div>
<h1 style="break-after: avoid; color: #2f5496; font-family: "Calibri Light", sans-serif; font-size: 16pt; font-weight: normal; margin: 12pt 0in 0.0001pt;">
Swift Source<o:p></o:p></h1>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<a href="https://www.blogger.com/blogger.g?blogID=1266480015345788892" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a>To download the Swift source code, we will want to create a directory to download it too, change to that directory and then run the <b>git</b> command to get the source. The following commands will download the swift source to a directory name <b>swift-source</b>.<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 1pt 1pt 4pt;">
<div class="Code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
mkdir swift-source<o:p></o:p></div>
<div class="Code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
cd swift-source<o:p></o:p></div>
<div class="Code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
<span style="font-family: AppleSystemUIFont;">git clone <a href="https://github.com/apple/swift.git"><span style="color: #dca10d;">https://github.com/apple/swift.git</span></a></span><span style="font-family: AppleSystemUIFont;"><o:p></o:p></span></div>
<div class="Code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
<span style="font-family: AppleSystemUIFont;">./swift/utils/update-checkout --clone</span><span style="font-family: AppleSystemUIFont;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<span style="font-family: AppleSystemUIFont;">Now that we have the source and cloned everything we need, lets build swift.<o:p></o:p></span></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<h1 style="break-after: avoid; color: #2f5496; font-family: "Calibri Light", sans-serif; font-size: 16pt; font-weight: normal; margin: 12pt 0in 0.0001pt;">
Build Swift <o:p></o:p></h1>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<span style="font-family: AppleSystemUIFont;">Before you begin building Swift, know that it is going to take hours to build. The exact time will depend on the type of system you are building it on. The following command will build Swift, its toolchain and the package manager:<o:p></o:p></span></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<span style="font-family: AppleSystemUIFont;"><br /></span></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 1pt 1pt 4pt;">
<div class="Code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
./swift/utils/build-script --preset=buildbot_swiftpm_linux_platform,tools=RA,stdlib=RA<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<span style="font-family: AppleSystemUIFont;">Once this has built everything, which could take several hours, we will want to install it similar to what we did with the pre-built binaries in this post: <o:p></o:p></span></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<h1 style="break-after: avoid; color: #2f5496; font-family: "Calibri Light", sans-serif; font-size: 16pt; font-weight: normal; margin: 12pt 0in 0.0001pt;">
Installing Swift<o:p></o:p></h1>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now that we have built Swift from source, we are ready to install it and put it in our path so we can execute them easily. I like to install the under the <b>/opt</b> directory, others prefer installing it under the <b>/usr/local/share</b>directory. What directory you put it under is totally up to you. I will walk you through installing it under the <b>/opt</b>directory, if you would like to put it someplace else simply replace the “/opt” in the paths with your install directory. <o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now let’s change to the <b>/opt</b> directory and create a directory named <b>swift</b>. Once the <b>swift</b> directory is created, we will also need to change the permissions for the directory so we can read, write and execute files. The following commands will do this:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
cd /opt<o:p></o:p></div>
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo mkdir swift<o:p></o:p></div>
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo chmod 777 swift<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
The command chmod 777 swift will add read, write and execute permissions for all users of this computer. I like to use this mode because then any user on the system can use it, however this can be considered a security issue because it also means anyone can modify the files. Use this at your own risk and for production systems I would really look at who needs permissions for this directly and lock it down more.<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now we will need to move the Swift binaries that we downloaded to the <b>swift</b> directory. To do this we will change to the swift directory, create a new directory for our build, change to the directory and copy the files over. For this article I am building the 5.3-dev version of swift therefore I am using that for my directory name. The following commands will do this:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
cd swift<o:p></o:p></div>
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
mkdir swift-5.3-dev<o:p></o:p></div>
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
cd swift-5.3-dev<o:p></o:p></div>
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
cp -R ~/swift-source/build/buildbot_incremental/toolchain-linux-x86_64/* ./<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now we will want to make a symlink to this directory called <b>swift-current</b>. The reason for this is we will want to add an entry to our PATH environmental variable so the operating system can find the Swift executables without us needing to enter the full path. If we set up this entry using the <b>swift-current</b> path rather than the <b>swift.5.3-dev</b> path. This will allow us, when we install new versions of Swift, to simply change where the <b>swift-current</b> symlink points to and have everything work. We will do this with the following command:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo ln -s /opt/swift/ swift-5.3-dev swift-current<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now we will need to create the entry in our PATH variable. To do this you will want add the add <b>/opt/swift/swift-current/usr/bin</b>/ directory to the PATH variable in our <b>.profile</b> file located in your home directory. Then update the environment The following commands will do this:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
cd ~<o:p></o:p></div>
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
echo 'export PATH=$PATH:/opt/swift/swift-current/usr/bin' >> .profile<o:p></o:p></div>
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
source ~/.profile<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
The last thing we need to do is to verify swift has been successfully installed. To do this, we can run the following command:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
swift –version<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
The output should look something like this but with the version of swift that you installed<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Swift version 5.2.2 (swift-5.2.2-RELEASE)<o:p></o:p></div>
<div class="code0" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Target: x86_64-unknown-linux-gnu<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Congratulations, you have now successfully installed Swift.<o:p></o:p></div>
<br />
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-56636393599194123112020-04-30T13:40:00.002-07:002020-04-30T13:43:04.352-07:00Installing Swift for Linux with Pre-built Binaries<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
The easiest and quickest way to install Swift for Linux is by installing pre-built binaries. If you are using a LTS branch for Ubuntu, you can find links to download these binaries by going to the following page: <a href="https://swift.org/download/" style="color: #954f72;">https://swift.org/download/</a>. In this post we will look at how we can install Swift using these binaries however before we do that lets look at the possibility of installing Swift with pre-built packages on non-Ubuntu systems.<o:p></o:p></div>
<h1 style="break-after: avoid; color: #2f5496; font-family: "Calibri Light", sans-serif; font-size: 16pt; font-weight: normal; margin: 12pt 0in 0.0001pt;">
Install using a Linux package manger<o:p></o:p></h1>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
If you are not using Ubuntu, you may still be able to install pre-built binaries through the package manager that comes with your system. As an example, with CentOS you can very easily install swift with the following command:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 1pt 1pt 4pt;">
<div class="MsoNormal" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo yum install swift-lang swift-lang-runtime.<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Installing with the binaries from these package managers will be the easiest way to install Swift however what version is installed and if they stay up to date is dependent on the person that build these binaries. To find out if your flavor of Linux has a Swift package, you will first have to determine which package manager is used by your system. You will probably have either <b>apt</b> or <b>yum</b> as your package manager. The easy way to determine which package manager you have installed is to run both the <b>apt</b> and the <b>yum</b> command. After you run the command, you will see either the help message for the command if it is installed or a command not found error if the command is not installed.<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Once you determine which package manager is installed, you can run one of the following commands to see if there are Swift packages for you flavor of Linux:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="MsoNormal" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
apt search swift-lang<o:p></o:p></div>
<div class="MsoNormal" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
yum search swift-lang<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
If no results are found, you could try searching for <b>swift</b> rather than <b>swift-lang</b> however you will find numerous results that are not the Swift language. If you do have results from your search, you can install the package by using one of the following commands (Note: replace {package name} with the name of the package returned from the search):<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="MsoNormal" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo apt install {package name}<o:p></o:p></div>
<div class="MsoNormal" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo yum install {package name}<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
To verify that Swift is properly installed once the packages are installed, look at the verifying installations section at the end of this chapter.<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
If swift is properly installed, then you should see the version number of the installed version of Swift. I wish I could make these instructions were more specific however there is no way we could cover all flavors of Linux here and even if we were able to, there would be no guarantee that packages would not change tomorrow. <o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now let’s look at how we can download and install the Ubuntu binaries from the swift.org site. <o:p></o:p></div>
<h1 style="break-after: avoid; color: #2f5496; font-family: "Calibri Light", sans-serif; font-size: 16pt; font-weight: normal; margin: 12pt 0in 0.0001pt;">
<a href="https://www.blogger.com/blogger.g?blogID=1266480015345788892" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a>
Installing using the swift.org binaries<o:p></o:p></h1>
<div>
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
If you ae using an LTS version of Ubuntu, the easiest way to install Swift is to install the pre-built binary, for your version of Ubuntu, from the swift.org site. These are official release binaries built by the Swift community itself. They release pre-binaries for Ubuntu with all official releases of Swift and also for the latest development branch if you want to try the latest and greatest. <o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
To install Swift with these binaries, the first thing we need to do is to download them from the swift.org site. In your favorite browser go to the following URL, <a href="https://swift.org/download/" style="color: #954f72;">https://swift.org/download/</a> and you should see a screen similar to this:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt; text-align: center;">
<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt; text-align: center;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjODAwq-tM7tRtp2azY5DYiX0EjLqYaAQUXLseu8GeREJ_m3XLyL96iGO-Qyieebna41oBRsGkvOXILK1rDrac8DzW40TzHEfMLcgsCFTn0wMiNh3Vbh5GMehGHUeef_ekw7FBJ3-bERhgn/s1600/Screenshot+2020-04-25+15.24.02.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1339" data-original-width="1600" height="333" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjODAwq-tM7tRtp2azY5DYiX0EjLqYaAQUXLseu8GeREJ_m3XLyL96iGO-Qyieebna41oBRsGkvOXILK1rDrac8DzW40TzHEfMLcgsCFTn0wMiNh3Vbh5GMehGHUeef_ekw7FBJ3-bERhgn/s400/Screenshot+2020-04-25+15.24.02.png" width="400" /></a></div>
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
As you can see from this screenshot, that the latest official released version of Swift, at the time this book was written, is 5.2.2. To download the pre-built binaries for Swift, you simply need to click on the version of Ubuntu that you are using and it will start the download. In this case I would download a file named <b>swift-5.2.2-RELEASE-ubuntu18.04.tar.gz</b>. <o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
The name starts off with the word <b>swift</b> because it contains the pre-built binaries for the Swift language, followed by the version number. Next we see the word <b>RELEASE</b> because this is an official release version of Swift. If it wasn’t an official release version, we would see the word <b>DEVELOPMENT</b> instead. The end of the name tells us what platform the pre-built binaries are built for. In this case they are built for Ubuntu 18.04.<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now we will need to unzip and untar the file. To do this we need to run the following command:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="MsoNormal" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
tar -xzf swift-5.2.2-RELEASE-ubuntu18.04.tar.gz<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
You will want to substitute the file name in the previous command with the name of the file that you downloaded. Once this command has finished, you should have a directory with the same name as the original file except it will not have the <b>.tar.gz</b> suffix. <o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Before we install these binaries and set up our path, we will want to install the dependencies. The following command will install the required dependencies:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="MsoNormal" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo apt-get install clang libicu-dev<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
The required dependencies may change with future releases of Swift. The same page that you downloaded Swift from also contains the list of dependencies. You can verify that no additional dependencies are needed by referring to that page.<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now that the dependencies are installed, we are ready to install the Swift binaries and put them in our path so we can execute them easily. I like to install the under the <b>/opt</b> directory, others prefer installing it under the <b>/usr/local/share</b> directory. What directory you put it under is totally up to you. I will walk you through installing it under the <b>/opt</b> directory, if you would like to put it someplace else simply replace the “/opt” in the paths with your install directory. <o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now let’s change to the <b>/opt</b> directory and create a directory named <b>swift</b>. Once the <b>swift</b> directory is created, we will also need to change the permissions for the directory so we can read, write and execute files. The following commands will do this:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
cd /opt<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo mkdir swift<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo chmod 777 swift<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
The command chmod 777 swift will add read, write and execute permissions for all users of this computer. I like to use this mode because then any user on the system can use it, however this can be considered a security issue because it also means anyone can modify the files. Use this at your own risk and for production systems I would really look at who needs permissions for this directly and lock it down more.<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now we will need to move the Swift binaries that we downloaded to the <b>swift</b> directory. To do this we will change to the swift directory and then move the untarred binaries, that should be located in the <b>Downloads</b>directory, to the <b>swift</b> directory. The following commands will do this:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
cd swift<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
mv ~/Downloads/swift-5.2.2-RELEASE-ubuntu18.04 ./<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now we will want to make a symlink to this directory called <b>swift-current</b>. The reason for this is we will want to add an entry to our PATH environmental variable so the operating system can find the Swift executables without us needing to enter the full path. If we set up this entry using the <b>swift-current</b> path rather than the <b>swift.5.2.2-RELEASE-ubuntu18.04</b> path. This will allow us, when we install new versions of Swift, to simply change where the <b>swift-current</b> symlink points to and have everything work. We will do this with the following command:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
sudo ln -s /opt/swift/ swift-5.2.2-RELEASE-ubuntu18.04 swift-current<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Now we will need to create the entry in our PATH variable. To do this you will want add the add <b>/opt/swift/swift-current/usr/bin</b>/ directory to the PATH variable in our <b>.profile</b> file located in your home directory. Then update the environment variables The following commands will do this:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
cd ~<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
echo 'export PATH=$PATH:/opt/swift/swift-current/usr/bin' >> .profile<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
source ~/.profile<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
The last thing we need to do is to verify swift has been successfully installed. To do this, we can run the following command:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
swift –version<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
The output should look something like this but with the version of swift that you installed<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Apple Swift version 5.3-dev (LLVM a60975d8a4, Swift afe134eb2e)<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Target: x86_64-unknown-linux-gnu<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
Congratulations, you have now successfully built and installed Swift. Now to verify that the package manager was successfully built and installed, run the following commands:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
mkdir test<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
cd test<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
swift package init<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
If everything was successfully built you should see out similar to this:<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div style="background-color: #d9d9d9; border: 1pt solid windowtext; margin-left: 0.5in; margin-right: 0in; padding: 1pt 4pt;">
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating library package: test<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating Package.swift<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating README.md<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating .gitignore<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating Sources/<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating Sources/test/test.swift<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating Tests/<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating Tests/LinuxMain.swift<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating Tests/testTests/<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating Tests/testTests/testTests.swift<o:p></o:p></div>
<div class="code" style="border: none; font-family: Calibri, sans-serif; font-size: 12pt; margin: 0in 0in 0.0001pt; padding: 0in;">
Creating Tests/testTests/XCTestManifests.swift<o:p></o:p></div>
</div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
You are now ready to go.<o:p></o:p></div>
<div class="MsoNormal" style="font-family: Calibri, sans-serif; margin: 0in 0in 0.0001pt;">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-40862034785701185132017-10-24T14:41:00.000-07:002017-10-24T14:42:12.768-07:00Why you should learn Generics<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKoxure7hvgeuz_3Lo-S8SHLSs5r0W1wWno9ob0bBph3cnwkYZS3EdG5lDYF0XtARNNKhZkQbG6aapaXUAN7jfv24RiPEmy5GN7KzEqJCg_MLHzBDi0Rd0RWoBW1RpG62PnJZjYsHlvTwK/s1600/SwiftyGenerics.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="406" data-original-width="507" height="160" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKoxure7hvgeuz_3Lo-S8SHLSs5r0W1wWno9ob0bBph3cnwkYZS3EdG5lDYF0XtARNNKhZkQbG6aapaXUAN7jfv24RiPEmy5GN7KzEqJCg_MLHzBDi0Rd0RWoBW1RpG62PnJZjYsHlvTwK/s200/SwiftyGenerics.png" width="200" /></a></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT">
Over the
past couple of years, I have been surprised with the number of senior level
developers that I have meet that do not use Generics.<span style="mso-spacerun: yes;"> </span>Not only do they not use generics but they
actually have very little understanding of them.<span style="mso-spacerun: yes;"> </span>In this article, I would like to explain why all
developers should not only learn generics but use them regularly.<span style="mso-spacerun: yes;"> </span>While this article focuses on the Swift
programming language, the concepts of why you should learn and use generics will
apply to almost any language that have generics similar to Swift.</div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">I will
start off by demonstrating the problem that generics solve.<span style="mso-spacerun: yes;"> </span>Let’s say we are developing a new application
and within this application we have the need to swap the value of two integer
variables.<span style="mso-spacerun: yes;"> </span>To meet this need, in Swift, we
could very easily write a function like this:<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><span class="s1"><span style="color: black; mso-themecolor: text1;">func</span></span><span style="color: black; mso-themecolor: text1;"> swapInt(_ a: <span class="s1"><span style="color: black; mso-themecolor: text1;">inout</span></span> <span class="s2"><span style="color: black; mso-themecolor: text1;">Int</span></span>, _ b: <span class="s1"><span style="color: black; mso-themecolor: text1;">inout</span></span> <span class="s2"><span style="color: black; mso-themecolor: text1;">Int</span></span>) {</span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><span class="apple-converted-space"><span style="color: black; mso-themecolor: text1;"> </span></span><span class="s1"><span style="color: black; mso-themecolor: text1;">let</span></span><span style="color: black; mso-themecolor: text1;"> tmp = a<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><span class="apple-converted-space"><span style="color: black; mso-themecolor: text1;"> </span></span><span style="color: black; mso-themecolor: text1;">a = b<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><span class="apple-converted-space"><span style="color: black; mso-themecolor: text1;"> </span></span><span style="color: black; mso-themecolor: text1;">b = tmp<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">}</span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">This
function could then be used like this:<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">var one = 1<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">var two = 2<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">swapInt(&one,
&two)</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">Now, a
few days or weeks later, as we continue to write the application, we discover a
need to swap the values of two string variables.<span style="mso-spacerun: yes;"> </span>We could then add another function to do this. The following code shows this new function:<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><span class="s1"><span style="color: black; mso-themecolor: text1;">func</span></span><span style="color: black; mso-themecolor: text1;"> swapInt(_ a: <span class="s1"><span style="color: black; mso-themecolor: text1;">inout</span></span> <span class="s2"><span style="color: black; mso-themecolor: text1;">String</span></span>, _ b: <span class="s1"><span style="color: black; mso-themecolor: text1;">inout</span></span> <span class="s2"><span style="color: black; mso-themecolor: text1;">String</span></span>) {</span><span style="color: black;"><o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><span class="apple-converted-space"><span style="color: black; mso-themecolor: text1;"> </span></span><span class="s1"><span style="color: black; mso-themecolor: text1;">let</span></span><span style="color: black; mso-themecolor: text1;"> tmp = a<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><span class="apple-converted-space"><span style="color: black; mso-themecolor: text1;"> </span></span><span style="color: black; mso-themecolor: text1;">a = b<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><span class="apple-converted-space"><span style="color: black; mso-themecolor: text1;"> </span></span><span style="color: black; mso-themecolor: text1;">b = tmp<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">}</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">As time
goes by we may end up with several functions like the previous swap functions but with different
parameter types.<span style="mso-spacerun: yes;"> </span>Instead of having all
of these different functions, in the beginning we could have created one generic swap function
that looked like this:'<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">func
swapGeneric<T>(_ a: inout T, _ b: inout T) {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
let tmp = a<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
a = b<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
b = tmp<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">}</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">Notice
that the generic version of the swap function uses a placeholder, capital T,
rather than the actual parameter type.<span style="mso-spacerun: yes;"> </span>This
placeholder tells the compiler that we will define the type to use at runtime.<span style="mso-spacerun: yes;"> </span>Since the T placeholder is used for both
parameters, they are required to be of the same type.<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">We would
use this generic function exactly like we would use the non-generic swap functions.<span style="mso-spacerun: yes;"> </span>The following code illustrates this:<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">var one = 1<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">var two = 2<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">swapGeneric(&one,
&two)</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">Now the
parameters can be instances of any type as long as they are instances of the same type.<span style="mso-spacerun: yes;"> </span>We could swap the values of two string types
like this:<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">var one =
“one”<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">var two =
“two”<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">swapGeneric(&one,
&two)</span><o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">Swapping
values isn’t too exciting so let’s look at something that does a bit more by
seeing how we could use generics to create a very basic queue type.<span style="mso-spacerun: yes;"> </span>The following code shows how to do this.<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">struct
Queue<T> {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> private var items = [T]()<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> <o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> public mutating func push(_ item: T) {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> items.append(item)<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> }<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> public mutating func pop() -> T? {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> if (items.count > 0) {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> return
items.remove(at: 0)<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> } else {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> return nil<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> }<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> }<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">}</span><span style="font-family: "menlo"; font-size: 8.5pt;"><o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; font-family: "menlo"; font-size: 8.5pt;"><br /></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">We would use this queue type like this:<o:p></o:p></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">var queue =
Queue<Int>()<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">queue.push(1)<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">queue.push(2)<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">print(<u>q</u>ueue.pop())<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">print(<u>q</u>ueue.pop())</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><br /></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">One of the best things about this queue type is
it is ready to accept any type.<span style="mso-spacerun: yes;"> </span>We could
very easily create an instance of the Queue type that would store String values
like this:<o:p></o:p></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">var queue =
Queue<String>()</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><br /></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">One of the questions that someone new to generics
may ask is: Why don’t we just use the Any type rather than generics?<span style="mso-spacerun: yes;"> </span>In Swift, the Any type allows us to use instances
of any type.<span style="mso-spacerun: yes;"> </span>The following code shows
how we could create a Queue type that used the Any type:<o:p></o:p></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">struct
QueueAny {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
private var items = [Any]()<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
public mutating func push(_ item: Any) {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
items.append(item)<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
}<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
public mutating func pop() -> Any? {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
if (items.count > 0) {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
return items.remove(at: 0)<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
} else {<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
return nil<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
}<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">
}<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">}</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><br /></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">The QueueAny type lets us create a queue that
can contain any type similar to the previous generic queue however there are
several disadvantages to this method.<span style="mso-spacerun: yes;">
</span>The one disadvantage that we will focus on here is the ability to add
any type to the queue.<span style="mso-spacerun: yes;"> </span>For example this
code would be perfect ok with the QueueAny queue:<o:p></o:p></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">var queueAny
= QueueAny()<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">queueAny.push(2)<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">queueAny.push("Hi")</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="color: black; mso-themecolor: text1;"><br /></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">Notice how we are able to add both an integer
and a string to the same queue.<span style="mso-spacerun: yes;"> </span>The
QueueAny type functions similar to how Arrays worked in Objective-C.<span style="mso-spacerun: yes;"> </span>Now if we popped an item off the queue we
would need to typecast it before we used any of the methods or properties of
the type.<span style="mso-spacerun: yes;"> </span>This does not allow us to have any
compile time checks to make sure we are using the correct types in our queue
and is prone to error, as any Objective-C developer can tell you.<o:p></o:p></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">With the generic Queue type, since we
explicitly define the type of items stored in the queue, we are able to use the
properties and methods of that type without the need to typecast.<span style="mso-spacerun: yes;"> </span>This gives us the compile time checks that
ensures we are using the correct types.<o:p></o:p></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">The answer to the question about why you should
learn generics is:<span style="mso-spacerun: yes;"> </span>Generics enable us to
write very flexible and reusable code that is also very safe.<span style="mso-spacerun: yes;"> </span>In this article we only scratched the surface
of generics.<span style="mso-spacerun: yes;"> </span>If you are unfamiliar with
generics I would recommend taking the time to learn more about them. <o:p></o:p></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">In my <a href="http://amzn.to/2ySTN2E">Mastering Swift 4 book</a></span><span lang="EN-GB" style="mso-ansi-language: EN-GB;"> there is a chapter dedicated to generics
that gives the reader a good introduction to generics which shows how to create
generic functions, types and protocols.<span style="mso-spacerun: yes;">
</span>We also look at using type constraints with generics and the new generic
subscripting feature that was introduced in Swift 4.<o:p></o:p></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">In my <a href="http://amzn.to/2gOt5xP">Swift 4 Protocol Oriented Programmingbook</a></span><span lang="EN-GB" style="mso-ansi-language: EN-GB;"> we also have a chapter dedicated to
generics.<span style="mso-spacerun: yes;"> </span>In that chapter, we briefly
cover generic types, protocols, type constraints and generic subscripting.<span style="mso-spacerun: yes;"> </span>We also include more advance topics like how
generics are used in the Swift standard library and how to use generics to
implement the Copy-on-Write feature for custom value types.<o:p></o:p></span></div>
<div class="NormalPACKT" style="tab-stops: 54.4pt;">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><o:p> </o:p></span> </div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-20304224316183415422017-10-05T16:27:00.002-07:002017-10-05T16:27:44.131-07:00Announcing Two New Swift Programming Books<br />
<div>
Swift is the definitive language of Apple development today. It’s a vital part of any iOS and OS X developer’s skillset, helping them to build the most impressive and popular apps on the App Store—the sort of apps that are essential to iPhone and iPad users every day. With version 4.0, the Swift team has added new features to improve the development experience—making it easier to get the results you want and customers expect.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://images-na.ssl-images-amazon.com/images/I/51oipuznYvL._SX404_BO1,204,203,200_.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="500" data-original-width="406" height="200" src="https://images-na.ssl-images-amazon.com/images/I/51oipuznYvL._SX404_BO1,204,203,200_.jpg" width="161" /></a></div>
<div>
The first book that was released in the <a href="http://amzn.to/2fVALB8">Mastering Swift 4 book</a>. Inside this book, you’ll find the key features of Swift 4.0 and quickly learn how to use the newest updates to your development advantage. From Objective-C interoperability to ARC, to closures and concurrency, this advanced Swift guide will develop your expertise and make you more fluent in this vital programming language.</div>
<div>
<br /></div>
<div>
<a href="http://amzn.to/2fVALB8">Mastering Swift 4 </a>will give you in-depth knowledge of some of the most sophisticated elements of Swift development including protocol extensions, error-handling, design patterns, and concurrency, and guide you on how to use and apply them in your own projects. You'll see how to leverage the power of Protocol-Oriented program to write cleaner and easier to manage code. We will also show you how Apple uses Protocol-Oriented programming techniques in the Swift standard library.</div>
<div>
<br /></div>
<div>
Some key areas that are covered are:</div>
<div>
* Dive into the core components of Swift 4.0, including operators, collections, control flow, and functions</div>
<div>
* Create and use classes, structures, and enums</div>
<div>
* Understand protocol-oriented design and see how it can help you write better code</div>
<div>
* Develop a practical understanding of subscripts, optionals, and closures</div>
<div>
* Add concurrency to your applications using Grand Central Dispatch and Operation Queues</div>
<div>
* Implement Generics and Closures to write very flexible and reusable codes </div>
<div>
* Make use of error handling and the availability feature to write safer code</div>
<div>
<br /></div>
<div>
This book is for developers who want to dive into the newest version of Swift. If you are a developer that learns best by looking at, and working with code, then this book is for you. A basic understanding of Apple's tools is beneficial but not mandatory.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://images-na.ssl-images-amazon.com/images/I/511I0uOlCnL._SX404_BO1,204,203,200_.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="500" data-original-width="406" height="200" src="https://images-na.ssl-images-amazon.com/images/I/511I0uOlCnL._SX404_BO1,204,203,200_.jpg" width="161" /></a></div>
<div style="text-align: left;">
The second book that is released in <a href="http://amzn.to/2xYv89W">Swift 4 Protocol Oriented Programming</a>. With this edition, we did a complete re-write and added a lot of new content. </div>
<div>
<br /></div>
<div>
The Swift standard library is developed using protocol-oriented programming techniques, generics, and first-class value semantics; therefore, every Swift developer should understand these powerful concepts and how to take advantage of them in their application design.</div>
<div>
<br /></div>
<div>
This book will help you understand the differences between object-oriented programming and protocol-oriented programming. It will demonstrate how to work with protocol-oriented programming using real-world use cases. You will gain a solid knowledge of the various types that can be used in Swift and the differences between value and reference types. You will be taught how protocol-oriented programming techniques can be used to develop very flexible and easy-to-maintain code.</div>
<div>
<br /></div>
<div>
By the end of the book, you will have a thorough understanding of protocol- oriented programming and how to utilize it to build powerful and practical applications.</div>
<div>
<br /></div>
<div>
Some of the key areas covered is:</div>
<div>
* Understand the differences between object-oriented programming and protocol-oriented programming</div>
<div>
* Explore the different types that Swift offers and what pitfalls to avoid</div>
<div>
* How Protocols and Generics are used in the Swift Standard library</div>
<div>
* Delve into generics and see how to use them in a Protocol-Oriented design</div>
<div>
* Learn how to implement Copy-On-Write within your custom types</div>
<div>
* Implement several design patterns in a protocol-oriented way</div>
<div>
* Design applications by prioritizing the protocol first and the implementation types second</div>
<div>
<br /></div>
<div>
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-24969070977873893192017-02-02T15:14:00.002-08:002017-02-02T15:14:24.429-08:00Getting started with the Kitura Stencil framework<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG3nS4L8zuAcZQGPywhKxMPWqEeFF3aH9CSw43oK4_5a5Z2V_iIeR47seYZ0tcJwbWUkUd9zAn_Sge4Gqi_fpEFMy1hjW-qkPehhIUDMEBx3qH3fP6ffuNBexehasA2jUgsz2LvDww6AmK/s1600/Kitura.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG3nS4L8zuAcZQGPywhKxMPWqEeFF3aH9CSw43oK4_5a5Z2V_iIeR47seYZ0tcJwbWUkUd9zAn_Sge4Gqi_fpEFMy1hjW-qkPehhIUDMEBx3qH3fP6ffuNBexehasA2jUgsz2LvDww6AmK/s1600/Kitura.png" /></a></div>
<div class="Standard">
In our <a href="http://masteringswift.blogspot.com/2017/01/building-web-services-with-swift-and.html">last post</a> we showed how to create REST based web services using Swift and IBM’s
Kitura framework.<span style="mso-spacerun: yes;"> </span>In this post we will
show how to serve both static and dynamic web pages with Swift using the Kitura
and the Kitura Stencil frameworks. <o:p></o:p><span style="background-color: white; color: #222222; font-family: inherit;">The Kitura framework, developed by IBM, is a light-weight, high-performance, web framework and server written in the Swift language.</span><span style="color: #222222; font-family: inherit;"> The Kitura stencil framework allows us to separate our view component from the controller code when we are serving web pages.</span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
If you are not familiar with what IBM is doing with server
side Swift, I would recommend you visit their web site at <span style="color: #5dc2c0;"><a href="https://developer.ibm.com/swift/">https://developer.ibm.com/swift/</a>. </span>One note, all<span style="background-color: white;"> code for this post was written and tested on an Ubuntu 16.10 laptop. The code should also work on macOS but you may need to install other dependencies. </span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span style="color: #222222;">We will start off by creating the
project using the Swift Package Manager. To do this we will create</span><span style="color: #222222;"> a
directory named </span><b style="color: #222222;">kitura_web_page_sample</b><b style="color: #222222;"> </b><span style="color: #222222;">and then initialize the project with the Swift package manager:</span></div>
<div class="Standard">
<br /></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">mkdir kitura_web_page_sample<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">cd kitura_web_page_sample<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">swift package init<o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span style="color: #222222;">The first thing we need to do is
add the Kitura framework as a dependency for our project. We do this by adding
the dependency to the <b style="mso-bidi-font-weight: normal;">Package.swift </b>file.<span style="mso-spacerun: yes;"> </span>The <b style="mso-bidi-font-weight: normal;">Package.swift
</b>file should have the following code in it:<o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">import PackageDescription<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<br /></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">let package = Package(<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>name: "kitura_web_page_sample",<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>dependencies: [<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>.Package(url:
"https://github.com/IBM-Swift/Kitura.git", majorVersion: 1, minor: 4)<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>]<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span style="color: #222222;">Before we show how to use
stencils and properly serve both static and dynamic web pages with Kitura, we
will start off by showing what NOT to do.<span style="mso-spacerun: yes;">
</span>Let’s create the <b style="mso-bidi-font-weight: normal;">main.swift </b>file
under the <b style="mso-bidi-font-weight: normal;">Sources </b>directory and put
the following code in it:<o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">import Kitura<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<br /></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">// Create a new router<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">let router = Router()<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<br /></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">router.get("/dontdo") {<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>request, response, next in<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>response.send("<html><body>")<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>response.send("<h1>Don't do
this</h1>'")<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>response.send("</body></html>")<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>next()<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<br /></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">// Add an HTTP server and connect
it to the router<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">Kitura.addHTTPServer(onPort:
8090, with: router)<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<br /></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">// Start the Kitura runloop (this
call never returns)<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt;">Kitura.run()<o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span style="color: #222222;">The first line imports the Kitura
framework so we can use it in our code.<span style="mso-spacerun: yes;">
</span>Next, we create an instance of the <b style="mso-bidi-font-weight: normal;">Router
</b>class.<span style="mso-spacerun: yes;"> </span>The <b style="mso-bidi-font-weight: normal;">Router </b>class provides an interface for routing the incoming
requests to the correct code.<span style="mso-spacerun: yes;"> </span>This class
lets us handle all standard REST request types. You can find the reference page
for the <b style="mso-bidi-font-weight: normal;">Router </b>class here:<span style="mso-spacerun: yes;"> </span></span><a href="http://ibm-swift.github.io/Kitura/Classes/Router.html#/s:FC6Kitura6Router3getFtGSqSS_7handlerGSaFzTCS_13RouterRequestCS_14RouterResponseFT_T__T___S0_"><span style="color: #7c93a1; text-decoration: none; text-underline: none;">http://ibm-swift.github.io/Kitura/Classes/Router.html#/s:FC6Kitura6Router3getFtGSqSS_7handlerGSaFzTCS_13RouterRequestCS_14RouterResponseFT_T__T___S0_</span></a><span style="color: #222222;"><o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span style="color: #222222;">We use the <b style="mso-bidi-font-weight: normal;">get </b>method to set up a router handler that will be invoked when an
HTTP GET request comes in with a path pattern that matches the supplied
path.<span style="mso-spacerun: yes;"> </span>In this example, the path that we
are matching against is “/donotdo” because we should not be serving web pages
this way.<span style="mso-spacerun: yes;"> </span>If a request does come in with
the correct path, the code in the closure is called.<span style="mso-spacerun: yes;"> </span>In our service, we send back a HTML page that
displays the text “Don’t do this”.<o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span style="color: #222222;">We use the </span><b style="mso-bidi-font-weight: normal;"><span style="color: #333f50;">addHTTPServer(onPort:with:)
</span></b><span style="color: #222222;">to register the router.<span style="mso-spacerun: yes;"> </span>The </span><b style="mso-bidi-font-weight: normal;"><span style="color: #333f50;">onPort </span></b><span style="color: #222222;">parameter
is the port number to bind the server too.<span style="mso-spacerun: yes;">
</span>In this example, we will bind to port 8090.<span style="mso-spacerun: yes;"> </span>This call only registers the server, it does
not start listening until we call the </span><b style="mso-bidi-font-weight: normal;"><span style="color: #333f50;">run()<span style="mso-spacerun: yes;">
</span></span></b><span style="color: #222222;">method in the last line.<o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span style="color: #222222;">Now let’s save the file and run </span><b style="mso-bidi-font-weight: normal;"><span style="color: black;">Swift build </span></b><span style="color: #222222;">from our project’s root directory.<o:p></o:p></span></div>
<div class="Standard">
<br /></div>
<div style="background: white; border: solid windowtext 1.0pt; margin-left: .5in; margin-right: .5in; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 6.0pt 4.0pt 9.0pt 4.0pt;">
<div class="InformationBoxPACKT" style="background: white; margin-bottom: 9.0pt; margin-left: 0in; margin-right: 0in; margin-top: 9.0pt;">
<span style="background: white;">If you receive an error that the compile could not find curl/curl.h, you
will need to install the libcurl4-openssl-dev package (or any of the other
three packages that provide the curl.h header file). To do this run
the following command:<o:p></o:p></span></div>
<div class="InformationBoxPACKT" style="background: white; margin-bottom: 9.0pt; margin-left: 0in; margin-right: 0in; margin-top: 9.0pt;">
<span style="background: white;">sudo apt-get install libcurl4-openssl-dev<o:p></o:p></span></div>
</div>
<div class="Standard">
<br /></div>
<div class="Standard">
<span style="color: #222222;">If everything compiles correctly
we can run the application with the following command from the project’s root
directory:<o:p></o:p></span></div>
<div class="Standard" style="margin-left: 35.45pt;">
<br /></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: "Courier 10 Pitch"; font-size: 9.0pt; line-height: 120%;">.</span><span style="color: #222222; font-family: 'Courier 10 Pitch'; line-height: 120%;">/.build/debug/kitura_web_page_sample<span style="font-size: 9pt;"><o:p></o:p></span></span></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="color: #222222; font-family: 'Courier 10 Pitch'; line-height: 120%;"><br /></span></div>
<div class="Textbody">
If everything starts up correctly, we can open any web
browser and see the page by going to <a href="http://localhost:8090/donotdo"><span style="color: windowtext; text-decoration: none; text-underline: none;">http://localhost:8090/donotdo</span></a>.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
Now the question may be, why shouldn’t we do this.<span style="mso-spacerun: yes;"> </span>It is good practice to always try to separate
the view component from the controller.<span style="mso-spacerun: yes;">
</span>With the previous code our view (HTML code) is embedded within our
controller which means we will have to update the code every time the view
changes.<span style="mso-spacerun: yes;"> </span>This is definitely not ideal
especially since the person that creates the view can be different from the
person that writes the controller.<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
To separate the view from the controller we can use Kitura
templates.<span style="mso-spacerun: yes;"> </span>The Kitura template engine allows
us to render web pages from static templates.<span style="mso-spacerun: yes;">
</span>This allows us to update the view by updating the template rather than
the controller code.<span style="mso-spacerun: yes;"> </span>Let’s see how we
can use the Kitura template engine.<span style="mso-spacerun: yes;"> </span>The
first thing we need to do is to update the dependencies for our project.<span style="mso-spacerun: yes;"> </span>The following code shows the new <b style="mso-bidi-font-weight: normal;">Package.swift</b> file with the updated
dependencies.<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="line-height: 120%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import PackageDescription<o:p></o:p></span></span></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<br /></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="line-height: 120%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">let package = Package(<o:p></o:p></span></span></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="line-height: 120%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>name: "kitura_web_page_sample",<o:p></o:p></span></span></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="line-height: 120%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>dependencies: [<o:p></o:p></span></span></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="line-height: 120%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>.Package(url: "https://github.com/IBM-Swift/Kitura.git",
majorVersion: 1, minor: 4),<o:p></o:p></span></span></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="line-height: 120%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>.Package(url:
"https://github.com/IBM-Swift/Kitura-StencilTemplateEngine.git",
majorVersion: 1, minor: 4)<o:p></o:p></span></span></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="line-height: 120%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>]<o:p></o:p></span></span></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">)</span></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
Now let’s create a template.<span style="mso-spacerun: yes;">
</span>Templates reside in a directory called <b>Views</b> off of the project’s
root directory. The following command will create this directory:<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="line-height: 120%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">mkdir Views</span><span style="font-family: 'Courier 10 Pitch'; font-size: 9pt;"><o:p></o:p></span></span></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
The stencil files use a file extension of <b>.stencil</b>.<span style="mso-spacerun: yes;"> </span>Let’s create a stencil file named <b>home.stencil</b>
and put the following code in it.<o:p></o:p></div>
<div class="Textbody" style="line-height: 70%; margin-left: 35.45pt;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><html><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: 35.45pt;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><body><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: 35.45pt;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><h2>Hello Turtles</h1><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: 35.45pt;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><p><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: 35.45pt;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span></body><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: 35.45pt;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></html><o:p></o:p></span></span></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
Notices that this stencil file contains standard HTML at this
point.<span style="mso-spacerun: yes;"> </span>To use this template, we need to
import the Kitura Stencil framework into our code.<span style="mso-spacerun: yes;"> </span>Add the following import to the main.swift
file:<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody" style="margin-left: .5in;">
<span style="font-family: "Courier New"; font-size: 9.0pt; line-height: 120%;">Import KituraStencil<o:p></o:p></span></div>
<div class="Textbody" style="margin-left: .5in;">
<span style="font-family: "Courier New"; font-size: 9.0pt; line-height: 120%;"><br /></span></div>
<div class="Textbody">
Now we need to set the stencil engine right after we create
the router.<span style="mso-spacerun: yes;"> </span>The following code shows how
to do this:<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="p1" style="margin-left: .5in;">
<span class="s1"><span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">// Create a
new router</span></span><span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"><o:p></o:p></span></div>
<div class="p2" style="margin-left: .5in;">
<span class="s2"><span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">let</span></span><span class="s1"><span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> router = Router()</span></span><span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"><o:p></o:p></span></div>
<div class="p3" style="margin-left: .5in;">
<br /></div>
<div class="p1" style="margin-left: .5in;">
<span class="s1"><span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">//Setup
Stencil</span></span><span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"><o:p></o:p></span></div>
<div class="p2" style="margin-left: .5in;">
<span class="s1"><span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">router.setDefault(templateEngine:
StencilTemplateEngine())</span></span><span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"><o:p></o:p></span></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
Finally we will create a router handler that will use the
stencil.<span style="mso-spacerun: yes;"> </span>Put the following code in the <b>main.swift</b>
file right below the other router handler:<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">router.get("/home")
{<o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>request, response, next in<o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>defer { next() }<o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>try response.render("home",
context: [:])<o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><span style="font-family: 'Courier 10 Pitch'; font-size: 9pt;"><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="font-family: 'Courier 10 Pitch'; line-height: 90%;"><span style="font-size: x-small;"><br /></span></span></div>
<div class="Textbody">
Notice the try <b>response.render(“home”, context: [:])</b>
line in the router handler.<span style="mso-spacerun: yes;"> </span>This line
will look in the <b>Views</b> directory for a file named <b>home.stencil </b>and
render the page from the template.<span style="mso-spacerun: yes;"> </span>The
context parameter is used to pass data to the template.<span style="mso-spacerun: yes;"> </span>We will see how to use the context parameter
a little later in this post but before we do that let’s see how we can use a
template within another template.<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
There are times when we would like to use a standard header
or footer for all web pages.<span style="mso-spacerun: yes;"> </span>We really
do not want to put this code in each template because then when someone wants
to changes the header or footer we would have to make the changes to each
template.<span style="mso-spacerun: yes;"> </span>With the Kitura stencil
framework we can embed one stencil within another.<span style="mso-spacerun: yes;"> </span>Let’s see how this works by creating a simple
header named <b>header.stencil</b> in the <b>Views</b> directory and put this
single line of code in it:<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="font-size: 9pt; line-height: 120%;"><span style="font-family: Courier New, Courier, monospace;"><h1>Mega
Turtles</h1></span><span style="font-family: Courier 10 Pitch;"><o:p></o:p></span></span></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; line-height: 120%;"><br /></span></div>
<div class="Textbody">
We can now update the <b>home.stencil</b> file so it contains
the following code:<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody" style="line-height: 70%; margin-left: .5in;">
<span style="line-height: 70%;"><span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;"><html></span><span style="font-family: Courier 10 Pitch;"><o:p></o:p></span></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: .5in;">
<span style="line-height: 70%;"><span style="font-size: x-small;"><span style="font-family: 'Courier 10 Pitch';"> </span><span style="font-family: Courier New, Courier, monospace;"><body><o:p></o:p></span></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: .5in;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{% include "header.stencil" %}<o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: .5in;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><h2>Hello Turtles</h1><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: .5in;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><p><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: .5in;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span></body><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 70%; margin-left: .5in;">
<span style="line-height: 70%;"><span style="font-family: Courier New, Courier, monospace;"><span style="font-size: x-small;"></html></span><span style="font-size: 9pt;"><o:p></o:p></span></span></span></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
Notice that we added the <b>{% include “header.stencil” %}</b>
line to the file.<span style="mso-spacerun: yes;"> </span>This line will search
the Views directory for a file named <b>header.stencil</b> and embed the code
from that file into this page.<span style="mso-spacerun: yes;"> </span>If we
build and run the application we will see that the Mega Turtles header is now
at the top of the page.<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
When we refer to these files we refer to them as templates
however you may be wondering why we use the .stencil extension.<span style="mso-spacerun: yes;"> </span>This is because we are using the <a href="https://github.com/kylef/Stencil">Stenciltemplate engine</a>.<span style="mso-spacerun: yes;"> </span>This stencil engine allows us to
substitute template variables with actual values at runtime.<span style="mso-spacerun: yes;"> </span>This allows us to create dynamic web
pages.<span style="mso-spacerun: yes;"> </span>We saw a basic example of this in
the previous post where we added the header template to the page.<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody">
Let’s see how we can use the template engine to create
dynamic pages.<span style="mso-spacerun: yes;"> </span>The first thing we need
to do is to create a new template.<span style="mso-spacerun: yes;"> </span>Let’s
create a template named <b>list.stencil</b> in the <b>Views</b> directory and
put the following code in it.<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><html><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><body><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{% include "header.stencil" %}<o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>There are {{ turtles.count }} turtles.<o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span></body><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="line-height: 90%;"><span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace;"></html></span><span style="font-family: Courier 10 Pitch;"><o:p></o:p></span></span></span></div>
<div class="Textbody" style="line-height: 90%; margin-left: 35.45pt;">
<span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; line-height: 90%;"><br /></span></div>
<div class="Textbody">
Notice the new line in this file.<span style="mso-spacerun: yes;"> </span>Before we explain this line, let’s look at
the router handler that will use this template.<o:p></o:p></div>
<div class="Textbody" style="line-height: 70%;">
<br /></div>
<span style="font-variant-ligatures: no-common-ligatures;"> <span style="font-family: Courier New, Courier, monospace;"> <span style="font-size: x-small;">router.get(</span></span></span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="font-variant-ligatures: no-common-ligatures;">"/list"</span><span style="font-variant-ligatures: no-common-ligatures;">) {</span><span style="font-variant-ligatures: no-common-ligatures;"> request, response, next </span><span style="font-variant-ligatures: no-common-ligatures;">in</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures;">defer</span><span style="font-variant-ligatures: no-common-ligatures;"> { next() }</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures;">var</span><span style="font-variant-ligatures: no-common-ligatures;"> context = [String: </span><span style="font-variant-ligatures: no-common-ligatures;">Any</span><span style="font-variant-ligatures: no-common-ligatures;">]()</span><span style="font-variant-ligatures: no-common-ligatures;"> context[</span><span style="font-variant-ligatures: no-common-ligatures;">"turtles"</span><span style="font-variant-ligatures: no-common-ligatures;">] = turtleNames</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures;">try</span><span style="font-variant-ligatures: no-common-ligatures;"> response.render(</span><span style="font-variant-ligatures: no-common-ligatures;">"list"</span><span style="font-variant-ligatures: no-common-ligatures;">, context: context)</span><span style="font-variant-ligatures: no-common-ligatures;"> }</span></span><br />
<div class="Textbody" style="line-height: 70%; margin-left: 35.45pt;">
</div>
<div class="Textbody" style="line-height: 70%; margin-left: 35.45pt;">
<br /></div>
<div class="Textbody">
Within this router handler, we define an array named <b>turtleNames</b>
with four elements.<span style="mso-spacerun: yes;"> </span>We also create a
dictionary object named <b>context</b>.<span style="mso-spacerun: yes;">
</span>This dictionary will contain the data for the template to use.<span style="mso-spacerun: yes;"> </span>We add the <b>turtleNames</b> array to the <b>context</b>
dictionary with a key of <b>turtles</b> and then include the <b style="mso-bidi-font-weight: normal;">context</b> dictionary when we render the
list template.<o:p></o:p></div>
<div class="Textbody">
If we look back at the list template, we see that we use the
turtle array like this:<b> {{ turtles.count }}</b>.<span style="mso-spacerun: yes;"> </span>This code calls the <b>count</b> property on
the array to print out the number 4 since there are four elements in our <b>turtleNames</b>
array.<o:p></o:p></div>
<div class="Textbody">
Now let’s change the list.stencil file so we will print out
the list of turtle names.<o:p></o:p></div>
<div class="Textbody">
<br /></div>
<div class="Textbody" style="margin-left: 35.45pt;">
<span style="line-height: 120%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><html><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 80%; margin-left: 35.45pt;">
<span style="line-height: 80%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><body><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 80%; margin-left: 35.45pt;">
<span style="line-height: 80%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>There are {{ turtles.count }} turtles.<o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 80%; margin-left: 35.45pt;">
<span style="line-height: 80%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><ul><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 80%; margin-left: 35.45pt;">
<span style="line-height: 80%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>{%
for turtle in turtles %}<o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 80%; margin-left: 35.45pt;">
<span style="line-height: 80%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><li> {{ turtle }} </li><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 80%; margin-left: 35.45pt;">
<span style="line-height: 80%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{% endfor %}<o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 80%; margin-left: 35.45pt;">
<span style="line-height: 80%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span></ul><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 80%; margin-left: 35.45pt;">
<span style="line-height: 80%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span></body><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 80%; margin-left: 35.45pt;">
<span style="line-height: 80%;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></html></span><span style="font-family: Courier 10 Pitch; font-size: 9pt;"><o:p></o:p></span></span></div>
<div class="Textbody" style="line-height: 80%;">
<br /></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="382">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Mention"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Smart Hyperlink"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<div class="Textbody" style="line-height: normal;">
Notice the new code that is within
the <b>{%</b> and <b>%}</b>. The line
with the <b>for turtle in turtles</b> creates a <b>for</b> loop to iterate
though the <b>turtles</b> array. We then
display each element in the array with the {<b>{ turtle }}</b> line and end the
for loop with the <b>{% endfor %}</b> line.<o:p></o:p></div>
<div class="Textbody" style="line-height: normal;">
<br /></div>
<!--EndFragment--><div class="Textbody" style="line-height: 80%;">
Here is the full listing of the
main.swift file:<o:p></o:p></div>
<div class="Textbody" style="line-height: 80%;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">import Kitura<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">import
KituraStencil<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">// Create a new
router<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">let router =
Router()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">//Setup Stencil<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">router.setDefault(templateEngine:
StencilTemplateEngine())<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">router.get("/dontdo")
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> request,
response, next in<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> response.send("<html><body>")<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> response.send("<h1>Don't
do this</h1>'")<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> response.send("</body></html>")<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> next()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">router.get("/list")
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> request,
response, next in<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> defer
{ next() }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> var
context = [String: Any]()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"><span style="mso-spacerun: yes;"> </span>let turtleNames = [<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> <span style="mso-spacerun: yes;"> </span>"Donetello", "Leonardo",
"Michelangelo","Raphael"<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"><span style="mso-spacerun: yes;"> </span>]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> context["turtles"]
= turtleNames<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;"> try
response.render("list", context: context)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">// Add an HTTP
server and connect it to the router<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">Kitura.addHTTPServer(onPort:
8090, with: router)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">// Start the Kitura
runloop (this call never returns)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-themecolor: text1;">Kitura.run()<o:p></o:p></span></div>
<div class="Textbody" style="line-height: 80%;">
<br /></div>
<div class="Textbody" style="line-height: 80%;">
It is pretty easy to use the Kitura
Stencil framework.<span style="mso-spacerun: yes;"> </span>In future posts well
will be expanding on this knowledge.<o:p></o:p></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="382">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Mention"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Smart Hyperlink"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="Textbody" style="line-height: 80%;">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-25570780552190208772017-01-22T10:24:00.000-08:002017-01-22T10:25:52.973-08:00Building Web Services with Swift and the Kitura framework<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikRPn22IH1hYgUrgJ_F2zeSZHyi53bxhFG9oJOkqNiDMiDNYvnaZhA5t51uNpfiJNYSwkSQwatMvZF268MRiI_tAjy9H-f-CMW_ss0MridpsSp61CwOr9tOEXRrDIwYJAqYUc8pow2SXSf/s1600/Kitura.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikRPn22IH1hYgUrgJ_F2zeSZHyi53bxhFG9oJOkqNiDMiDNYvnaZhA5t51uNpfiJNYSwkSQwatMvZF268MRiI_tAjy9H-f-CMW_ss0MridpsSp61CwOr9tOEXRrDIwYJAqYUc8pow2SXSf/s1600/Kitura.png" /></a></div>
<div class="NormalPACKT">
The Kitura framework, developed by IBM, is a light-weight,
high-performance, web framework and server written in the Swift language.<span style="mso-spacerun: yes;"> </span>This framework allows us to very quickly
develop complex web services using the Swift language and Swift’s standard Foundation
APIs. <span style="mso-spacerun: yes;"> </span>This allows us to use our existing
Swift knowledge to very easily create server-side services.<span style="mso-spacerun: yes;"> </span>We can run our Kitura based services as stand-alone
applications, deploy them to IBM’s Bluemix cloud or use IBM’s pre-build Docker
image.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<span style="mso-spacerun: yes;"><br /></span></div>
<div class="NormalPACKT">
If you are not familiar with what IBM is doing with Swift
on the Server, you should check out their site:<span style="mso-spacerun: yes;">
</span><a href="https://developer.ibm.com/swift/">https://developer.ibm.com/swift/</a>.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<span style="mso-spacerun: yes;"><br /></span></div>
<div class="NormalPACKT">
In the next few posts we will be looking at how we can use
Kitura to develop web services with Swift.<span style="mso-spacerun: yes;">
</span>For this first post, we will create some very basic web services to show
how to setup a project that uses the Kitura framework and also how easy it is
to use.<span style="mso-spacerun: yes;"> </span>We will start off by creating
the project using the Swift Package Manager.<span style="mso-spacerun: yes;">
</span><o:p></o:p></div>
<div class="NormalPACKT">
<span style="mso-spacerun: yes;"><br /></span></div>
<div style="background: white; border: solid windowtext 1.0pt; margin-left: .5in; margin-right: .5in; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 6.0pt 4.0pt 9.0pt 4.0pt;">
<div class="InformationBoxPACKT" style="background: white; margin-bottom: 9.0pt; margin-left: 0in; margin-right: 0in; margin-top: 9.0pt;">
All the code for this
post was written and tested on an Ubuntu 16.10 laptop.<span style="mso-spacerun: yes;"> </span>The code should also work on macOS but you
may need to install other dependencies.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
</div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Let’s start off by creating a directory named <b style="mso-bidi-font-weight: normal;">hello</b> and then initialize the project
with the Swift package manager:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> mkdir hello<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> cd hello<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> swift package init<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><br /></span></div>
<div class="NormalPACKT">
The first thing we need to do is add the Kitura framework as
a dependency for our project.<span style="mso-spacerun: yes;"> </span>We do this
by adding the dependency to the <b style="mso-bidi-font-weight: normal;">Package.swift</b>
file.<span style="mso-spacerun: yes;"> </span>The <b style="mso-bidi-font-weight: normal;">Package.swift</b> file should have the following code in it:<o:p></o:p></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> import
PackageDescription<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> let package =
Package(<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>name: "hello",<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>dependencies: [<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>.Package(url:
"https://github.com/IBM-Swift/Kitura.git", majorVersion: 1, minor: 4)<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>]<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> )<o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Now let’s create the <b style="mso-bidi-font-weight: normal;">main.swift</b>
file under the <b style="mso-bidi-font-weight: normal;">Sources</b> directory and
add the following code to it:<o:p></o:p></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> import Kitura<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> let router =
Router()<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> router.get("/hello")
{<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>request, response, next in<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>response.send("Hello World!")<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>next()<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> }<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> Kitura.addHTTPServer(onPort:
8090, with: router)<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> Kitura.run()<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><br /></span></div>
<div class="NormalPACKT">
The first line imports the Kitura framework so we can use
it.<span style="mso-spacerun: yes;"> </span>Next, we create an instance of the <b style="mso-bidi-font-weight: normal;">Router</b> class.<span style="mso-spacerun: yes;"> </span>The <b style="mso-bidi-font-weight: normal;">Router</b>
class provides an interface for routing the incoming requests.<span style="mso-spacerun: yes;"> </span>This class lets us handle all the REST
request types, Get, Post, Put and Delete. You can find the reference page for
the <b style="mso-bidi-font-weight: normal;">Router</b> class here:<span style="mso-spacerun: yes;"> </span><a href="http://ibm-swift.github.io/Kitura/Classes/Router.html#/s:FC6Kitura6Router3getFtGSqSS_7handlerGSaFzTCS_13RouterRequestCS_14RouterResponseFT_T__T___S0_">http://ibm-swift.github.io/Kitura/Classes/Router.html#/s:FC6Kitura6Router3getFtGSqSS_7handlerGSaFzTCS_13RouterRequestCS_14RouterResponseFT_T__T___S0_</a>
<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
We use the <b style="mso-bidi-font-weight: normal;">get</b>
method to set up a router handler that will be invoked when an HTTP GET request
comes in with a path pattern that matches the supplied path.<span style="mso-spacerun: yes;"> </span>In this example, the path that we are
matching against is “/hello”.<span style="mso-spacerun: yes;"> </span>If a
request does come in with the correct path, the code in the closure is
called.<span style="mso-spacerun: yes;"> </span>In our service, we send back a response
that simply contains “Hello World!”.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
We use the <b style="mso-bidi-font-weight: normal;"><span style="color: #333f50; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #333F50; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themeshade: 191;">addHTTPServer(onPort:with:)</span></b><span style="color: #333f50; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #333F50; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themeshade: 191;"> </span>to register the
router.<span style="mso-spacerun: yes;"> </span>The <b style="mso-bidi-font-weight: normal;"><span style="color: #333f50; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #333F50; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themeshade: 191;">onPort</span></b><span style="color: #333f50; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #333F50; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themeshade: 191;"> </span>parameter is the port number to bind the server too.<span style="mso-spacerun: yes;"> </span>In this example, we will bind to port 8090.<span style="mso-spacerun: yes;"> </span>This call only registers the server, it does
not start listening until we call the <b style="mso-bidi-font-weight: normal;"><span style="color: #333f50; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #333F50; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themeshade: 191;">run</span></b><span style="color: #333f50; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #333F50; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: text2; mso-themecolor: text2; mso-themeshade: 191;"> </span>method in
the last line.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Now let’s save the file and run <b style="mso-bidi-font-weight: normal;"><span style="color: black; mso-themecolor: text1;">Swift build</span></b><span style="color: black; mso-themecolor: text1;"> </span>from our project’s root
directory.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div style="background: white; border: solid windowtext 1.0pt; margin-left: .5in; margin-right: .5in; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 6.0pt 4.0pt 9.0pt 4.0pt;">
<div class="InformationBoxPACKT" style="background: white; margin-bottom: 9.0pt; margin-left: 0in; margin-right: 0in; margin-top: 9.0pt;">
If you receive an error
that the compile could not find curl/curl.h, you will need to install the
libcurl4-openssl-dev package (or any of the other three packages that provide
the curl.h header file).<span style="mso-spacerun: yes;"> </span>To do this run
the following command:<o:p></o:p></div>
<div class="InformationBoxPACKT" style="background: white; margin-bottom: 9.0pt; margin-left: 0in; margin-right: 0in; margin-top: 9.0pt;">
sudo apt-get install libcurl4-openssl-dev<o:p></o:p></div>
</div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
If everything compiles correct we can run the application with
the following command from the project’s root directory:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> ./.build/debug/hello<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="NormalPACKT">
We can verify that the application is running correctly
but opening a web browser and putting <b style="mso-bidi-font-weight: normal;">127.0.0.1:8090</b>
in the address bar.<span style="mso-spacerun: yes;"> </span>The screen that
comes up should look something like this:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicWNQgatMUjmS2D_lpIODCfC-vbBPsKxKWDauftbHYix-mNc4D-uh9BL-GAKD05JxygmZt0RSaYx8mDHtayilcxAiQvMlhgdffQ3-MpZElSNCuwf0ZW5_2Y-ywqZka5dVh8Z_CL8mYRWef/s1600/Screen+Shot+2017-01-21+at+7.04.21+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="255" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicWNQgatMUjmS2D_lpIODCfC-vbBPsKxKWDauftbHYix-mNc4D-uh9BL-GAKD05JxygmZt0RSaYx8mDHtayilcxAiQvMlhgdffQ3-MpZElSNCuwf0ZW5_2Y-ywqZka5dVh8Z_CL8mYRWef/s400/Screen+Shot+2017-01-21+at+7.04.21+PM.png" width="400" /></a></div>
<br />
<div class="NormalPACKT">
Now that we know Kitura is running, let’s test our
service.<span style="mso-spacerun: yes;"> </span>On Linux we have a command line
tool called <b style="mso-bidi-font-weight: normal;"><span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;">curl</span></b><span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;"> </span>that can be
used to make http requests.<span style="mso-spacerun: yes;"> </span>To test our
service run the following command:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> curl <a href="http://localhost:8090/hello">http://localhost:8090/hello</a><o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
If everything is running correctly we should receive the “Hello
World!” message back from the server.<span style="mso-spacerun: yes;"> </span>Getting
back static messages isn’t that exciting but it does illustrate how to setup a
project with Kitura and run it.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<span style="mso-spacerun: yes;"><br /></span></div>
<div class="NormalPACKT">
Now let’s see how we could handle both path and request
parameters with our GET requests.<span style="mso-spacerun: yes;"> </span>A path
parameter is a parameter that is part of the URL.<span style="mso-spacerun: yes;"> </span>An example of a path parameter is:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<i style="mso-bidi-font-style: normal;"> <a href="http://127.0.0.1/hello/jon">http://127.0.0.1/hello/jon</a></i><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
where <i style="mso-bidi-font-style: normal;"><span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;">jon</span></i><span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;"> </span>may be a
parameter.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
An example of a request parameter is:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<i style="mso-bidi-font-style: normal;"> <a href="http://127.0.0.1/hello?name=jon">http://127.0.0.1/hello?name=jon</a><o:p></o:p></i></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
where we have a parameter named “name” with a value of “<i style="mso-bidi-font-style: normal;"><span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;">jon</span></i>”<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Let’s look at how we would use path parameters first.<span style="mso-spacerun: yes;"> </span>The only thing in our code that will change
is the router’s get method and the closure.<span style="mso-spacerun: yes;">
</span>The following code shows how we would handle path parameters:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> router.get("/hello/:name")
{<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>request, response, next in<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>let name =
request.parameters["name"] ?? ""<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>response.send("Hello,
\(name)")<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>next()<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> }<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><br /></span></div>
<div class="NormalPACKT">
The path that we provide for the get method changed from “<span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;">/hello</span>” to “<span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;">hello/:name</span>”.<span style="mso-spacerun: yes;"> </span>The “<span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;">:name</span>” part of the path defines the parameter.<span style="mso-spacerun: yes;"> </span>We then use the coalescing operator to check
the request to see if there is a parameter named “name”.<span style="mso-spacerun: yes;"> </span>The line that does this is:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<span style="font-family: "courier new";"> let name = request.parameters["name"] ??
""</span><br />
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Finally we send back a personalized response saying hello
to the person whose name was provided in the path parameter.<span style="mso-spacerun: yes;"> </span>We can build our project and test it with the
following curl command:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> curl <a href="http://127.0.0.1:8090/hello/jon">http://127.0.0.1:8090/hello/jon</a><o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
Now let’s see how we can handle a request parameter.<span style="mso-spacerun: yes;"> </span>The following code shows how we would handle
request parameters:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> router.get("/hello")
{<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>request, response, next in<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>let name =
request.queryParameters["name"] ?? ""<o:p></o:p></span></div>
<div class="CodePACKT" style="margin-left: .5in;">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>response.send("-Hello, \(name)")<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><span style="mso-spacerun: yes;"> </span>next()<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> }<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><br /></span></div>
<div class="NormalPACKT">
In this example the path that we provide for the get
method is “<span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;">/hello</span>” which is the same as the path we provided in our
original example.<span style="mso-spacerun: yes;"> </span>We check the <b style="mso-bidi-font-weight: normal;"><span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;">queryParameters</span></b><span style="color: #2e75b6; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #2E75B6; mso-style-textfill-fill-colortransforms: lumm=75000; mso-style-textfill-fill-themecolor: accent5; mso-themecolor: accent5; mso-themeshade: 191;"> </span>property to see if we have a parameter named “name”.<span style="mso-spacerun: yes;"> </span>The line that does this is:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span style="font-family: "courier new";"> let name =
request.queryParameters["name"] ?? ""</span><span style="font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="NormalPACKT">
<span style="font-family: "courier new"; font-size: 9.0pt;"><br /></span></div>
<div class="NormalPACKT">
We can build our project and test it with the following
curl command:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"> curl <a href="http://127.0.0.1:8090/hello">http://127.0.0.1:8090/hello</a>?name=jon<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: "courier new";"><br /></span></div>
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves>false</w:TrackMoves>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="382">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Mention"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Smart Hyperlink"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="NormalPACKT">
As we can see, from this brief introduction, Kitura is
very easy to use.<span style="mso-spacerun: yes;"> </span>IBM offers a number of
frameworks that go along with Kitura, you can see the list here:<span style="mso-spacerun: yes;"> </span><a href="https://github.com/IBM-Swift/Kitura/wiki/Kitura-repositories">https://github.com/IBM-Swift/Kitura/wiki/Kitura-repositories</a>.<span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>In
future posts, we will look at how we can use the projects to add logging to our
Kitura services, use POST request, serialize and deserialize JSON and how to
add a database for our services to use.<o:p></o:p></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com1tag:blogger.com,1999:blog-1266480015345788892.post-48299047854492622242017-01-15T10:50:00.003-08:002017-01-15T10:53:14.375-08:00Multi-Client echo server with the BlueSocket framework and libdispatch<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhqJ21-kHvlhka_nV07iC6jvmIiYyIqgYd8ZJqUQgIZGZ7ZsP2Xfke2XyhmHNHO2fnukNgsgOIIa2YzECxak9vy_vqJftzjyBhyrN2dW3ha3CBWgjZRTvIcg-zEJ9ebq3_K7vqsjJsSE_m/s1600/pict.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="218" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhqJ21-kHvlhka_nV07iC6jvmIiYyIqgYd8ZJqUQgIZGZ7ZsP2Xfke2XyhmHNHO2fnukNgsgOIIa2YzECxak9vy_vqJftzjyBhyrN2dW3ha3CBWgjZRTvIcg-zEJ9ebq3_K7vqsjJsSE_m/s320/pict.png" width="320" /></a></div>
<div class="NormalPACKT">
In a <a href="http://masteringswift.blogspot.com/2017/01/using-bluesocket-framework-to-create.html">previous post</a> we showed how to create an echo server using IBM’s BlueSocket framework.<span style="mso-spacerun: yes;"> </span>This server was single threaded therefore it could
only communicate with one client at a time.<span style="mso-spacerun: yes;">
</span>In this post we will show how we can add libdispatch (GCD) to our code
to create a multi-client server.<o:p></o:p></div>
<div class="NormalPACKT">
To read an explanation on how the server itself was
written, please refer to the previous post <a href="http://masteringswift.blogspot.com/2017/01/using-bluesocket-framework-to-create.html">Using the BlueSocket framework tocreate an echo server</a>.<span style="mso-spacerun: yes;"> </span>The complete code for this project
can be found in the <a href="https://github.com/hoffmanjon/MasteringSwift/tree/master/Networking/echoServerGCD">Mastering Swift github repository</a><span style="mso-field-code: " HYPERLINK \\h ";">.</span><o:p></o:p></div>
<div class="NormalPACKT">
The first thing we need to do is add the dispatch
framework to the import list.<span style="mso-spacerun: yes;"> </span>We should
now have the following imports: <o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;">#if os(Linux)<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>import Glibc<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;">#else<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>import Darwin<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;">#endif<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;">import Foundation<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;">import Socket<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="color: #cc0000; font-family: "courier 10 pitch"; font-size: 9.0pt;">import Dispatch<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="color: #cc0000; font-family: "courier 10 pitch"; font-size: 9.0pt;"><br /></span></div>
<div class="NormalPACKT">
Now we will need to change the <b><span style="color: #330099;">start()</span></b>
method a little bit so when it calls the <b><span style="color: #330099;">newConnection(socket:)</span></b>
method it uses a separate thread.<span style="mso-spacerun: yes;"> </span>The
new<b><span style="color: #330099;"> start()</span></b> method looks like this:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="MsoNoSpacing">
<span style="mso-spacerun: yes;"> </span><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>func start() throws {</span><o:p></o:p></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let socket = try Socket.create() <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>listenSocket = socket<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>try socket.listen(on: port)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>print("Listening port:
\(socket.listeningPort)")<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><span style="color: #cc3300;">let queue =
DispatchQueue(label: "clientQueue.hoffman.jon", attributes:
.concurrent)</span><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>repeat {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let connectedSocket = try
socket.acceptClientConnection()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>print("Connection from:
\(connectedSocket.remoteHostname)")<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><span style="color: #cc3300;">queue.async{self.newConnection(socket:
connectedSocket)}</span><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>} while acceptNewConnection<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
There are two parts of this code that changed.<span style="mso-spacerun: yes;"> </span>The first is the <span style="color: #cc3300; font-family: "courier 10 pitch"; font-size: 9.0pt;">let </span><span style="color: #009900; font-family: "courier 10 pitch"; font-size: 9.0pt;">queue =
DispatchQueue(label: "clientQueue.hoffman.jon", attributes:
.concurrent)</span> line which was added to our code.<span style="mso-spacerun: yes;"> </span>This line creates a new concurrent dispatch
queue.<span style="mso-spacerun: yes;"> </span>The second change is we used the <span style="color: #009900;">queue.async()</span> method to submit the <b><span style="color: #330099;">newConnection(socket:) </span></b>call to the dispatch
queue. You can use the EchoServer class exactly they same way as we did in the previous post.<br />
<br /></div>
<div class="NormalPACKT">
Those are the only changes you need to make the code a
multi-client server.<span style="mso-spacerun: yes;"> </span>Here is the full
code for the multi-client EchoServer class :<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;">class EchoServer {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<br /></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let
bufferSize = 1024<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let
port: Int<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>var
listenSocket: Socket? = nil<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>var
connected = [Int32: Socket]()<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>var
acceptNewConnection = true<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<br /></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>init(port: Int) {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>self.port = port<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<br /></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>deinit {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>for socket in connected.values {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>socket.close()<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>listenSocket?.close()<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<br /></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>func
start() throws {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>let socket = try Socket.create() <o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<br /></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>listenSocket = socket<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>try socket.listen(on: port)<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>print("Listening port: \(socket.listeningPort)")<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>let queue = DispatchQueue(label: "clientQueue.hoffman.jon",
attributes: .concurrent)<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>repeat {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>let connectedSocket = try socket.acceptClientConnection()<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>print("Connection from:
\(connectedSocket.remoteHostname)")<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>queue.async{self.newConnection(socket: connectedSocket)}<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}
while acceptNewConnection<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<br /></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>func
newConnection(socket: Socket) {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>connected[socket.socketfd]
= socket<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<br /></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>var cont = true<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>var dataRead = Data(capacity: bufferSize)<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>repeat {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>do {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>let bytes = try socket.read(into: &dataRead)<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>if bytes > 0 {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>if let readStr =
String(data: dataRead, encoding: .utf8) {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>print("Received:
\(readStr)")<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>try socket.write(from:
readStr)<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>if
readStr.hasPrefix("quit") {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span><span style="mso-spacerun: yes;"> </span>cont = false<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>socket.close()<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>dataRead.count = 0<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>}<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>} catch let error {<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>print("error: \(error)")<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}
while cont<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>connected.removeValue(forKey: socket.socketfd)<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>socket.close()<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin-left: .5in;">
<span style="font-family: "courier 10 pitch"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
You can download the full code listing from the <a href="https://github.com/hoffmanjon/MasteringSwift">MasteringSwift github repository</a>.<o:p></o:p></div>
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="382">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Mention"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Smart Hyperlink"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
mso-bidi-font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNoSpacing">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com1tag:blogger.com,1999:blog-1266480015345788892.post-34875014904910689482017-01-14T11:26:00.000-08:002017-01-14T11:26:50.387-08:00Using the BlueSocket framework to create an Echo client<div style="line-height: 100%; margin-bottom: 0in;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZXSfzaVxs1ZR3yKRBNfJCawNpk4Va-uWpwqB2JZCAokYBuJfqEU0OJeTWOLjvmGLwmNUsN48URrmpAjd1LC5i5JfcuKB5wfbE9Himc0nmIRz7DTk9Z1N3oLrCg32EvUBgAXXUaY3Rnkn6/s1600/client.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZXSfzaVxs1ZR3yKRBNfJCawNpk4Va-uWpwqB2JZCAokYBuJfqEU0OJeTWOLjvmGLwmNUsN48URrmpAjd1LC5i5JfcuKB5wfbE9Himc0nmIRz7DTk9Z1N3oLrCg32EvUBgAXXUaY3Rnkn6/s1600/client.png" /></a></div>
In our <a href="http://masteringswift.blogspot.com/2017/01/using-bluesocket-framework-to-create.html">last post</a> we showed how to use the BlueSocket framework from IBM to create an
echo server. In this post we will show how to use the same
BlueSocket framework to create a client application that can
communicate with the echo server from the previous post.</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br /></div>
<div style="line-height: 100%; margin-bottom: 0in;">
The echo client will
first connect to the server to make sure it is running and then ask
the user for input. When the user inputs a line of text and presses
enter, the text will be sent to the server which should “echo”
that text back to the client.
</div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br /></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;"><span style="font-family: "liberation" serif;"><span style="font-size: small;">Whatever
system you will be developing your application for, the <a href="https://github.com/IBM-Swift/BlueSocket">BlueSocket github repository</a></span></span></span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;">
</span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;"><span style="font-family: "liberation" serif;"><span style="font-size: small;">has instructions on how to include it with your project. The
sample project on the <a href="https://github.com/hoffmanjon/MasteringSwift">Mastering Swift github repository</a> uses Swift’s Package Manager to include the framework. The
project, in the github repository is titled <a href="https://github.com/hoffmanjon/MasteringSwift/tree/master/Networking/echoClient">echo</a></span></span></span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;"><span style="font-family: "liberation" serif;"><span style="font-size: small;"><a href="https://github.com/hoffmanjon/MasteringSwift/tree/master/Networking/echoClient">Client</a>.</span></span></span></span></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<br /></div>
<div style="line-height: 100%; margin-bottom: 0in;">
<span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;"><span style="font-family: "liberation" serif;"><span style="font-size: small;">We
will start by creating an </span></span></span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;"><span style="color: #000099;"><span style="font-family: "liberation" serif;"><span style="font-size: small;"><b>EchoClient</b></span></span></span></span></span><span style="font-family: "times new roman" , serif;"><span style="font-size: x-small;"><span style="font-family: "liberation" serif;"><span style="font-size: small;">
class and importing the frameworks that we need.</span></span></span></span></div>
<div style="line-height: 100%; margin-bottom: 0in; margin-left: 0.49in;">
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;">#if os(Linux)</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>import Glibc</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;">#else</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>import Darwin</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;">#endif</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;">import Socket</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;">import Foundation</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<br /></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;">class EchoClient {</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<br /></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;">}</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">In this code we import
the <b><span style="color: #000099;">Glibc</span></b> or <b><span style="color: #000099;">Darwin</span></b> frameworks depending on the system we are
running on.<span style="mso-spacerun: yes;"> </span>We then import both the <b><span style="color: #000099;">Socket</span></b> and <b><span style="color: #000099;">Foundation</span></b>
frameworks.<span style="mso-spacerun: yes;"> </span>Now we need to define a
couple of properties for our class.</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>let bufferSize = 1024</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>let port: Int</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>let server: String</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>var listenSocket: Socket? = nil</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">In this code we define
four properties.<span style="mso-spacerun: yes;"> </span>The first is the <b><span style="color: #000099;">bufferSize</span></b> property that defines the maximum
number of characters that we can receive from the echo server at one time.<span style="mso-spacerun: yes;"> </span>The <b><span style="color: #000099;">port</span></b>
and <b><span style="color: #000099;">server</span></b> properties will define the
server and port number that the echo server is running on.<span style="mso-spacerun: yes;"> </span>The <b><span style="color: #000099;">listenSocket</span></b>
property is the socket that we will listen to in order to receive the response
back form the server.</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">Now we will create an
initializer and a deinitializer for the <b><span style="color: #000099;">EchoClient</span></b>
class.</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span></span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>init(port: Int, server: String) {</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>self.port = port</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>self.server = server</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span></span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>deinit {</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>listenSocket?.close()</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">The initializer
requires that the code calling it to provide both the port and server that we
are connecting too.<span style="mso-spacerun: yes;"> </span>We will see how to
call this initializer at the end of the post.<span style="mso-spacerun: yes;">
</span>The deinitializer disconnects the client from the server.</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">Now lets create the
method that will connect to the server.<span style="mso-spacerun: yes;">
</span>We will call this method <b><span style="color: #000099;">start()</span></b>.</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span></span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>func start() throws {</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>let socket = try Socket.create() </span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>listenSocket = socket</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>try socket.connect(to: server, port:
Int32(port))</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>var dataRead = Data(capacity: bufferSize)</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>var cont = true</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>repeat {</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>print("Enter Text:")</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>if let entered = readLine(strippingNewline:
true) {</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>try socket.write(from: entered)</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>if
entered.hasPrefix("quit") {</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>cont = false</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>let bytesRead = try
socket.read(into: &dataRead)</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>if bytesRead > 0 {</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>if let readStr = String(data:
dataRead, encoding: .utf8) {</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>print("Received:
'\(readStr)'")</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>}<span style="mso-spacerun: yes;"> </span></span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>dataRead.count = 0</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>} while cont</span></span><o:p></o:p></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">This code starts off
by using the <b><span style="color: #000099;">create()</span></b> method to
create a socket and then uses the <b><span style="color: #000099;">connect(to:port:)
</span></b>method of the socket to connect to the server.<span style="mso-spacerun: yes;"> </span>We create a <b><span style="color: #000099;">dataRead</span></b>
variable that will contain the text that is echoed back from the server.<span style="mso-spacerun: yes;"> </span>The capacity of the <b><span style="color: #000099;">dataRead</span></b> variable is the size defined by the <b><span style="color: #000099;">bufferSize</span></b> constant.</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">We now create a repeat
loop that will repeat as long as the <b><span style="color: #000099;">cont</span></b>
variable is true.<span style="mso-spacerun: yes;"> </span>We use the <b><span style="color: #000099;">readLine(strippingNewLine:)</span></b> method to read the
input from the user.<span style="mso-spacerun: yes;"> </span>Once the user
enters the text we use the <b><span style="color: #000099;">write(from:)</span></b>
method to send the text to the server.<span style="mso-spacerun: yes;">
</span>We also check to see if the users entered “quit” and if so we set the <b><span style="color: #000099;">cont</span></b> variable to false to end the repeat loop
after this iteration.</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">Next we use the <b><span style="color: #000099;">read(into:)</span></b> method of the socket to read the
response from the server.<span style="mso-spacerun: yes;"> </span>The <b><span style="color: #000099;">read(into:)</span></b> method returns the number of bytes
read.<span style="mso-spacerun: yes;"> </span>If the number is greater than
zero, we convert the response to a string and print it to the console.<span style="mso-spacerun: yes;"> </span>That is all there is to it.</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">We would use this
class like this:</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;">do {</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>var echoClient =
EchoClient(port: 3333, server: "127.0.0.1")</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>try echoClient.start()</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;">} catch let error {</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;"><span style="mso-spacerun: yes;"> </span>print("Error:
\(error)")</span></span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 35.45pt;">
<span class="IconPACKT"><span style="font-family: "Courier 10 Pitch"; font-size: 9.0pt; mso-bidi-font-family: FreeSans;">}</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">In this code we
connect to the server running on the localhost (127.0.0.1) on port 3333.</span></span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">As we can see with
this post and the post where we created the <a href="http://masteringswift.blogspot.com/2017/01/using-bluesocket-framework-to-create.html">echo server</a></span></span><span class="IconPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: FreeSans; mso-bidi-font-size: 12.0pt;">, using IBM’s
BlueSocket library makes it very easy to create client and server applications
with Swift.<span style="mso-spacerun: yes;"> </span>In the next post we will add
concurrency to the echo server so it can communicate with multiple servers at
the same time.</span></span><o:p></o:p></div>
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="382">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Mention"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Smart Hyperlink"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Liberation Serif","serif";
mso-fareast-language:ZH-CN;
mso-bidi-language:HI;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNormal">
<br /></div>
</div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com2tag:blogger.com,1999:blog-1266480015345788892.post-70775839849141640122017-01-12T04:50:00.001-08:002017-01-12T04:51:47.902-08:00Using the BlueSocket framework to create an echo server<div align="left" style="line-height: 100%; margin-bottom: 0.08in; orphans: 2; widows: 2;">
<div class="NormalPACKT">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbsuka66ccR90l3RkTySR-9mswJzcjK4-EyMONzhhnCIXAekfjmnVzIikAfkRB-m-KG493f4ltJhrO7LSP5pk_Vr8CSie0La_dz5oG5TwoRDEc-HGb0a9ixqZ-cCAw9e2MuNfeBDlkSlWr/s1600/echoImage.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="177" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbsuka66ccR90l3RkTySR-9mswJzcjK4-EyMONzhhnCIXAekfjmnVzIikAfkRB-m-KG493f4ltJhrO7LSP5pk_Vr8CSie0La_dz5oG5TwoRDEc-HGb0a9ixqZ-cCAw9e2MuNfeBDlkSlWr/s320/echoImage.png" width="320" /></a></div>
<span class="IconPACKT">In this post we will create an echo
server using the BlueSocket framework developed by IBM.<span style="mso-spacerun: yes;"> </span>An echo server is a server application that
“echoes” back to the client any text that it sends to the server.<span style="mso-spacerun: yes;"> </span>We will be using the BlueSocket framework
because it makes it very easy to develop cross-platform client and server
applications, using Swift, that connect using standard sockets.<span style="mso-spacerun: yes;"> </span>The BlueSocket framework works with
applications developed for iOS, macOS and Linux systems.<span style="mso-spacerun: yes;"> </span>We will start this post off by explaining
what Berkeley sockets are and give a real brief introduction to network
addressing.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">The Berkeley Socket API (Application
Programming Interface) is a set of standard functions for creating Internet and
Unix domain sockets that are used for inter-process communications.<span style="mso-spacerun: yes;"> </span>Other socket APIs exists however Berkeley
Sockets are generally regarded as the standard.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">The Berkeley Socket API was
originally introduced in 1983 when 4.2BSD was released. <span style="mso-spacerun: yes;"> </span>The API has evolved, with very little
modification, into part of the Portable Operating System Interface (POSIX)
specification. Today, all modern operating systems have some implementation of
the Berkeley Socket Interface for connecting devices to the Internet.<span style="mso-spacerun: yes;"> </span>Even Winsock (Windows Sockets) which was
developed in 1993,<span style="mso-spacerun: yes;"> </span>is based on the
Berkeley standards. </span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">BSD Sockets generally rely on
client/server architecture.<span style="mso-spacerun: yes;">
</span>Client/Server architecture is an approach where a host is assigned
either a client or a server role.<span style="mso-spacerun: yes;"> </span>We
define these roles like this:</span><o:p></o:p></div>
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; tab-stops: list 0in; text-indent: -.25in;">
</div>
<ul>
<li><span class="IconPACKT" style="text-indent: -0.25in;"><b>Server</b>: A server is a device
that selectively shares resources with other devices.</span></li>
<li><span class="IconPACKT" style="text-indent: -0.25in;"><b>Client</b>: A client is a device
that connects to a server to make use of the shared resources.</span></li>
</ul>
<!--[if !supportLists]--><o:p></o:p><br />
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; tab-stops: list 0in; text-indent: -.25in;">
<o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT">An example of the client/server architecture
is the Internet.<span style="mso-spacerun: yes;"> </span>When we open a web page
in our favorite browser, like </span><a href="https://www.packtpub.com/">https://www.google.com</a><span class="IconPACKT">, the browser (and therefore our device) becomes the client and
the web server that we connected to become the server.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div style="background: white; border-bottom: double #00000A 1.5pt; border-left: none black 1.0pt; border-right: none black 1.0pt; border-top: double #00000A 1.5pt; margin-left: .5in; margin-right: .5in; mso-border-bottom-alt: double #00000A 1.5pt; mso-border-left-alt: none black 0in; mso-border-right-alt: none black 0in; mso-border-top-alt: double #00000A 1.5pt; mso-element: para-border-div; padding: 6.0pt 0in 9.0pt 0in;">
<div class="TipPACKT" style="background: white; margin-bottom: 9.0pt; margin-left: 0in; margin-right: 0in; margin-top: 9.0pt;">
<span class="IconPACKT">It is important to note
that any device can be a server, a client or both.<span style="mso-spacerun: yes;"> </span>As an example, our e-mail client may be
connecting to a mail server, which makes us a client and at the same time we
have file sharing enabled which also makes our device a server.</span><o:p></o:p></div>
</div>
<div class="MsoNormal">
<span class="IconPACKT"><br /></span></div>
<div class="MsoNormal">
<span class="IconPACKT">The Socket API generally makes use of
two core protocols:<span style="mso-spacerun: yes;"> </span></span></div>
<ul><span class="KeyWordPACKT" style="text-indent: -0.25in;">
<li><span class="KeyWordPACKT" style="text-indent: -0.25in;"><b>TCP (Transmission
Control Protocol)</b></span><span class="IconPACKT" style="text-indent: -0.25in;"> – TCP provides a reliable,
ordered and error checked delivery of a stream of data between two devices on
the same network. TCP is generally used
when we need to ensure that all packets are correctly received and in the
correct order (Example: Web Pages or
E-Mail).</span></li>
<li><span class="IconPACKT" style="text-indent: -0.25in;"><b>UDP
(User Datagram Protocol)</b></span><span class="IconPACKT" style="text-indent: -0.25in;"></span>– UDP
does not provide any of the error checking or reliability of TCP but offers
much less overhead. UDP is generally
used when sending the information to the client quickly is more important then
missing a small percentage of packets (Example:
Streaming video).</li>
</span></ul>
</div>
<div class="NormalPACKT">
<span class="IconPACKT">Darwin, which is an open source
POSIX compliant operating system, forms the core set of components upon which
Mac OS X and iOS are based.<span style="mso-spacerun: yes;"> </span>This means
that both OS X AND iOS contains the BSD Socket Library.<span style="mso-spacerun: yes;"> </span>Most version of Linux are also very compliant
with POSIX however they are not officially certified.<span style="mso-spacerun: yes;"> </span>We will find that all Linux distributions
also contain the BSD Socket Library.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">BSD sockets can be used to build
both client and server applications.<span style="mso-spacerun: yes;"> </span>In
this post we will be building an echo server.<span style="mso-spacerun: yes;">
</span>An echo server is a server that simply “echoes” back the text that it
received.<span style="mso-spacerun: yes;"> </span>Before we look building this
server, lets take a quick look at network addressing work.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">Every device on an Internet Protocol
(IP) network has a unique identifier know as an IP Address.<span style="mso-spacerun: yes;"> </span>The IP Address serves two basic
purposes:<span style="mso-spacerun: yes;"> </span>host and location
identification. There are currently two IP address formats known as IPv4 and
IPv6</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">The IPv4 format is currently the
standard for the Internet and most internal intranets.<span style="mso-spacerun: yes;"> </span>This format stores the address as a 32 bit
number An IPv4 address looks like this 83.166.169.231.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">The IPv6 format is the latest
revision of the Internet Protocol (IP) and stores the address using 128
bits.<span style="mso-spacerun: yes;"> </span>It was developed to eventually
replace IPv4 and to address the long anticipated problem of running out of IPv4
addresses.<span style="mso-spacerun: yes;"> </span>An IPv6 address looks like
this:<span style="mso-spacerun: yes;"> </span>2001:0db8:0000:0000:0000:ff00:0042:8329.<span style="mso-spacerun: yes;"> </span>An IPv6 can be shortened where consecutive
all zero fields can be replaced by two colons.<span style="mso-spacerun: yes;">
</span>The previous address could be rewritten to:<span style="mso-spacerun: yes;"> </span>2001:0db8::ff00:0042:8329.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
An IP address only identifies the device itself however
any device may have multiple applications running on it that needs to
communicate over the network.<span style="mso-spacerun: yes;"> </span>These
applications may be server applications like a web server or a client
application like a web browser.<span style="mso-spacerun: yes;"> </span>Ports
are used to identify the application to communicate with.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span class="IconPACKT">A port is an application or process
specific software construct serving as a communications endpoint on a device
connected to an IP network.<span style="mso-spacerun: yes;"> </span>Where an IP
Address identifies the device to connect too the port number identifies the
specific application to connect too.<span style="mso-spacerun: yes;"> </span></span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><span style="mso-spacerun: yes;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">The best way to think of network
addressing is to think about how you mail a letter.<span style="mso-spacerun: yes;"> </span>In order for a letter to reach its
destination you must put the complete address on the envelope.<span style="mso-spacerun: yes;"> </span>For example, if you were going to send a letter
to friend that lived at the following address:</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span class="IconPACKT"> Jon Hoffman</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"> 123 Main St</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"> San Francisco CA, 94123</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span class="IconPACKT">If I were to translate that into
network addressing, the IP Address would be equal to the street, city, state
and zip code (Main St, San Francisco CA, 94123) and the street address (123)
would be equal to port number.<span style="mso-spacerun: yes;"> </span>So the IP
address will get you to the exact location of the device, and the port number
will tell you what door to knock on.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">A devices has 65,536 available ports
with the first 1024 being reserved for common protocols like HTTP, HTTPS, SSH,
SMTP……</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">While it is pretty straight forward
to create a socket server using the standard libraries that come with Darwin
and Linux, there are minor differences with these libraries that can make it a
challenge to write code that work on iOS, macOS and Linux systems.<span style="mso-spacerun: yes;"> </span>Luckily we have a couple really good
frameworks to help us create BSD socket clients and servers.<span style="mso-spacerun: yes;"> </span>In this post we will be using IBM’s
BlueSocket framework.<span style="mso-spacerun: yes;"> </span></span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><span style="mso-spacerun: yes;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">Whatever system you will be developing
your application for, the <a href="https://github.com/IBM-Swift/BlueSocket">BlueSocket github</a> page has instructions on how to include it
with your project.<span style="mso-spacerun: yes;"> </span>The sample project on
the <a href="https://github.com/hoffmanjon/MasteringSwift">Mastering Swift github page</a> </span><span class="IconPACKT">uses Swift’s Package Manager to include the framework.<span style="mso-spacerun: yes;"> </span>The project, in the github repository is
titled <a href="https://github.com/hoffmanjon/MasteringSwift/tree/master/Networking/echoServerSingleThread">echoServerSingleThread</a></span><span class="IconPACKT"> because it is a single threaded server so we can show how the BlueSocket
framework works.<span style="mso-spacerun: yes;"> </span>We will be creating a
multi-threaded server that can handle multiple connections in
a future post.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">Lets start off by importing the
frameworks needed:</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 8.0pt;">#if os(Linux)</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 8.0pt;"><span style="mso-spacerun: yes;"> </span>import
Glibc</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 8.0pt;">#else</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 8.0pt;"><span style="mso-spacerun: yes;"> </span>import
Darwin</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 8.0pt;">#endif</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 8.0pt;">import Foundation</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 8.0pt;">import Socket</span></span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span class="IconPACKT">Now lets create a class called <span style="color: #000099;"><b>EchoServer</b></span> and add a couple of properties to it:</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;">class EchoServer {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let
bufferSize = 1024</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let
port: Int</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>var
listenSocket: Socket? = nil</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>var
connected = [Int32: Socket]()</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>var
acceptNewConnection = true</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;">}</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 35.45pt; margin-right: 0in; margin-top: 0in;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">The <span style="color: #000099;"><b>bufferSize</b></span>
property defines the maximum number of characters that our server can read at
one time.<span style="mso-spacerun: yes;"> </span>The <span style="color: #000099;"><b>port</b></span>
property is the port number that the server will bind too.<span style="mso-spacerun: yes;"> </span>The <span style="color: #000099;"><b>listenSocket</b></span>
property is the listening socket for the server.<span style="mso-spacerun: yes;"> </span>The <span style="color: #000099;"><b>connected</b></span>
property holds the list of client sockets.<span style="mso-spacerun: yes;">
</span>Since this server will be single threaded, only one client can be
connected at a time but we still made this an array so we can easily turn this
code into a multi-client server in the future.<span style="mso-spacerun: yes;">
</span>Finally the <span style="color: #000099;"><b>acceptNewConnection</b></span>
property will be true when our server is accepting new connections.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT">Next we will create an initializer
and deinitializer.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>init(port:
Int) {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>self.port
= port</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<br /></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>deinit
{</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>for
socket in connected.values {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>socket.close()</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>listenSocket?.close()</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt; margin-left: 0in; margin-right: 0in; margin-top: 2.85pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">When we initialize the <span style="color: #000099;"><b>EchoServer</b></span> type we will need to provide the port
number that our server will bind to.<span style="mso-spacerun: yes;">
</span>The deinitializer will close all client connections to the server and
also the listening socket.<span style="mso-spacerun: yes;"> </span>Now we are
going to create the method that will start our sever.<span style="mso-spacerun: yes;"> </span></span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><span style="mso-spacerun: yes;"><br /></span></span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>func start() throws {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let socket = try Socket.create() </span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>listenSocket = socket</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>try socket.listen(on: port)</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>print("Listening port: \(socket.listeningPort)")</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>repeat {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let connectedSocket = try
socket.acceptClientConnection()</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>print("Connection from:
\(connectedSocket.remoteHostname)")</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>newConnection(socket:
connectedSocket)</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>} while acceptNewConnection<span style="mso-spacerun: yes;"> </span></span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">Rather than trying to catch and
respond to errors setting up the server, this method will throw any errors back
to the code that called it if there is a problem.<span style="mso-spacerun: yes;"> </span>This way the code that called the function
will know that there was a problem setting up the server and respond
appropriately.<span style="mso-spacerun: yes;"> </span></span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span>
<span class="IconPACKT">Next we use the <span style="color: #0b5394;"><b>create()</b></span> class
method to create the socket.<span style="mso-spacerun: yes;"> </span>This method
is defined like this:</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>public class func create(family:
ProtocolFamily = .inet, type: SocketType = .stream,</span> </span><span style="font-family: "courier 10 pitch"; font-size: 9pt;">proto: SocketProtocol = .tcp) throws ->
Socket</span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">As we can see this method takes three
arguments.<span style="mso-spacerun: yes;"> </span>Each of these arguments have
default values.<span style="mso-spacerun: yes;"> </span>The <span style="color: #000099;"><b>family</b></span> argument can contain three possible values:</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>Socket.ProtocolFamily.inet - IPv4</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>Socket.ProtocolFamily.inet6 – IPv6</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>Socket.ProtocolFamily.unix – UNIX</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">The <span style="color: #000099;"><b>type</b></span>
property can have two possible types:</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>Socket.SocketType.stream<span style="mso-spacerun: yes;"> </span>-<span style="mso-spacerun: yes;">
</span>Stream (generally for TCP)</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>Socket.SocketType.datagram<span style="mso-spacerun: yes;"> </span>-<span style="mso-spacerun: yes;">
</span>Datagram (generally for UDP)</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">Finally the <span style="color: #000099;"><b>proto</b></span>
property can have three possible values:</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>Socket.SocketProtocol.tcp<span style="mso-spacerun: yes;"> </span>-<span style="mso-spacerun: yes;"> </span>TCP</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>Socket.SocketProtocol.udp<span style="mso-spacerun: yes;"> </span>-<span style="mso-spacerun: yes;"> </span>UDP</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>Socket.SocketProtocol.unix<span style="mso-spacerun: yes;"> </span>-<span style="mso-spacerun: yes;"> </span>UNIX</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">We use the <span style="color: #000099;"><b>listen(on:)
</b></span>method to bind the server to the port we wish the server to listen
too.<span style="mso-spacerun: yes;"> </span></span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT">We set up a repeat loop and within
the loop we use the <span style="color: #000099;"><b>acceptClientConnection()</b> </span>method
to accept the next available client connection when it is available.<span style="mso-spacerun: yes;"> </span>Once the client connection is available we
call the <span style="color: #000099;"><b>newConnection(socket:)</b></span> method which
we will see next.<span style="mso-spacerun: yes;"> </span>The repeat loop
continues as long as the <span style="color: #000099;"><b>acceptNewConnection</b></span>
variable is true.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">Now lets see what the <span style="color: #000099;"><b>newConnection(socket:)</b></span> method looks like.<span style="mso-spacerun: yes;"> </span>This method will be called when a new
connection is established.<span style="mso-spacerun: yes;"> </span>With our
single threaded server we really did not need to create a separate method for
new connections but to make it easier to create a multi-threaded server that
will respond to multiple clients we went ahead and separated the functionality
in the beginning.<span style="mso-spacerun: yes;"> </span>Here is the code for
the <span style="color: #000099;"><b>newConnection(socket:)</b></span> method.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>func newConnection(socket: Socket) {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>connected[socket.socketfd] = socket</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>var cont = true</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>var dataRead = Data(capacity:
bufferSize)</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>repeat {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>do {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let bytes = try socket.read(into:
&dataRead)</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>if bytes > 0 {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>if let readStr =
String(data: dataRead, encoding: .utf8) {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>print("Received:
\(readStr)")</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>try socket.write(from:
readStr)</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>if readStr.hasPrefix("quit")
{</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>cont = false</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>socket.close()</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>dataRead.count = 0</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>} catch let error {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>print("error:
\(error)")</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>} while cont</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>connected.removeValue(forKey:
socket.socketfd)</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>socket.close()</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">This method starts off by adding the
socket to the <span style="color: #000099;"><b>connected[]</b></span> array which holds
the list of connected clients.<span style="mso-spacerun: yes;"> </span>We then
configure the <span style="color: #000099;"><b>dataRead</b></span> variable with a
capacity equal to the <span style="color: #000099;"><b>bufferSize</b></span> property
which is the maximum number of characters the server will read at once.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">Next there is a repeat loop that
will continue to repeat until the client sends a message that starts with “<i>quit</i>”.<span style="mso-spacerun: yes;"> </span>Within the repeat loop we have a do-catch
block that will catch any errors in the communication.<span style="mso-spacerun: yes;"> </span></span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><span style="mso-spacerun: yes;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">Within the do-catch block we use the<b>
<span style="color: #000099;">read(into:)</span></b> method to read the next message
from the client.<span style="mso-spacerun: yes;"> </span>We put that message in
the <span style="color: #000099;"><b>dataRead</b></span> variable.<span style="mso-spacerun: yes;"> </span>The method itself returns the total number of
bytes read.<span style="mso-spacerun: yes;"> </span>In the next line we verify
that the total number of bytes read is greater than zero.<span style="mso-spacerun: yes;"> </span>If it is greater than zero we convert the
message to a string and use the <span style="color: #000099;"><b>write(from:)</b></span>
method to echo it back to the client.<span style="mso-spacerun: yes;"> </span></span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><span style="mso-spacerun: yes;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">We check to see if the message has a
prefix of “<i>quit</i>” and if so we close the socket and set the <span style="color: #000099;"><b>cont</b></span> variable to false to exit out of the repeat
loop.<span style="mso-spacerun: yes;"> </span>This will close the connection
between the client and the server.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">Now in order to create the socket we
need to create an instance of the <span style="color: #000099;"><b>EchoServer</b></span>
class and call the <span style="color: #000099;"><b>start()</b></span> method.<span style="mso-spacerun: yes;"> </span>The following code shows how to do this:</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let server = EchoServer(port: 3333)</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>do {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>try server.start()</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>} catch let error {</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>print("Error: \(error)")</span></span><o:p></o:p></div>
<div class="NormalPACKT" style="margin-bottom: 3.15pt;">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}</span></span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">With this code we bind the server to
port 3333.<span style="mso-spacerun: yes;"> </span>We can now build our project
and run it.<span style="mso-spacerun: yes;"> </span>If it starts up without any
errors we can use telnet to test it.<span style="mso-spacerun: yes;"> </span>On
the same device that the echo server is running on we can test the server using
telnet like this:</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT"><span style="font-family: "courier 10 pitch"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>telnet
127.0.0.1 3333</span></span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">If all is well, telnet will connect
to the echo server and we can not type in a message and hit the enter key.<span style="mso-spacerun: yes;"> </span>Whatever message was typed in should be
echoed back.<span style="mso-spacerun: yes;"> </span>In the next couple of posts
we will be creating a client application that will connect to our echo server
and also a server that can handle multiple clients at once.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">If you use Google Plus, you can
become a member of the <a href="https://plus.google.com/communities/109923914684962504380">Swift Linux community</a></span><span class="IconPACKT"> that I just set up.<span style="mso-spacerun: yes;"> </span>Hopefully this
community will grow and will become a good resource for the Swift Linux
community.</span><o:p></o:p></div>
<div class="NormalPACKT">
<span class="IconPACKT">I will begin putting source code for
my blog posts in my <a href="https://github.com/hoffmanjon/MasteringSwift">Mastering Swift github page</a>.</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<br /></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="382">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" Priority="0" SemiHidden="true"
UnhideWhenUsed="true" Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="0" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Mention"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Smart Hyperlink"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="NormalPACKT">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-23359382123434843832017-01-08T07:18:00.000-08:002017-01-08T07:19:00.393-08:00Determine the byte order using Swift<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUWBb6Ejbr50QvtUQx8WmcRZkXI9ebdiFT-8u5vWn23fVg-gzIR8_za0NT6VnzldrLLEMXJYvUxsmg0ILOwV1svz6bECKYUxEjoNDscxyr7mRzpeZUyaLEM9Tl6vWjrjUPzGrVQvMKaaJs/s1600/Diagram.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="148" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUWBb6Ejbr50QvtUQx8WmcRZkXI9ebdiFT-8u5vWn23fVg-gzIR8_za0NT6VnzldrLLEMXJYvUxsmg0ILOwV1svz6bECKYUxEjoNDscxyr7mRzpeZUyaLEM9Tl6vWjrjUPzGrVQvMKaaJs/s320/Diagram.png" width="320" /></a></div>
<div class="NormalPACKT">
<span class="IconPACKT">As humans, when we look at a number,
we put the most significant number first and the least significant number
last.<span style="mso-spacerun: yes;"> </span>As an example when we look at the
number 123 we know that the number 1 represents 100 which is the most
significant digit while 3 is the least significant digit.<span style="mso-spacerun: yes;"> </span>For computers, the byte order refers to the
order that data is stored in memory.<span style="mso-spacerun: yes;">
</span>Some computers store the most significant bytes first (at the lowest
byte address), while others store the most significant bytes last (highhest
byte address).<span style="mso-spacerun: yes;"> </span></span><span style="mso-no-proof: yes;"><o:p></o:p></span></div>
<div class="NormalPACKT">
<span class="IconPACKT"><span style="mso-spacerun: yes;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">If a device stores the most
significant bytes first, it is known big-endian while a device that stores the
most significant bytes last is knows as little-endian.<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="NormalPACKT">
<span class="IconPACKT"><span style="mso-spacerun: yes;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="IconPACKT">The order of how data is stored in
memory is of great importance when doing network development because RFC1700
states that the byte order for Internet Protocols must be big-endian. If the
device that our application is running on stores data in little-endian order
than we need to convert it.<span style="mso-spacerun: yes;"> </span>We can use
the Network-to-Host and Host-to-Network functions to convert between the byte
order of your device and the byte order of the network.<span style="mso-spacerun: yes;"> </span>These function, will take into account the
byte order of the device the application is running on (host) and will convert
the data to big-endian (network) byte order if necessary.<span style="mso-spacerun: yes;"> </span>These functions are:<o:p></o:p></span></div>
<div class="NormalPACKT">
<span class="IconPACKT"><br /></span></div>
<div class="NormalPACKT" style="margin-left: .5in; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span class="IconPACKT"><span style="font-family: "symbol"; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt "Times New Roman";"> </span></span></span></span><!--[endif]--><b style="mso-bidi-font-weight: normal;">htons()</b><span class="IconPACKT"> – Host to
network short<o:p></o:p></span></div>
<div class="NormalPACKT" style="margin-left: .5in; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span class="IconPACKT"><span style="font-family: "symbol"; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt "Times New Roman";"> </span></span></span></span><!--[endif]--><b style="mso-bidi-font-weight: normal;">htonl()</b><span class="IconPACKT"> – Host to
network long<o:p></o:p></span></div>
<div class="NormalPACKT" style="margin-left: .5in; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span class="IconPACKT"><span style="font-family: "symbol"; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt "Times New Roman";"> </span></span></span></span><!--[endif]--><b style="mso-bidi-font-weight: normal;">ntohs()</b><span class="IconPACKT"> – Network
to host short<o:p></o:p></span></div>
<div class="NormalPACKT" style="margin-left: .5in; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span class="IconPACKT"><span style="font-family: "symbol"; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt "Times New Roman";"> </span></span></span></span><!--[endif]--><b style="mso-bidi-font-weight: normal;">ntohl()</b><span class="IconPACKT"> – Network
to host long<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="NormalPACKT">
<span class="IconPACKT">By using these functions we
generally to not need to worry about the endianess of the device we are running
on however there are times we will want to know.</span><span style="mso-spacerun: yes;"> </span>In this post we will look at how we can
determine the byte order of the device our application is running on. <span style="mso-no-proof: yes;"><o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">It is a
good idea to import the Foundation framework and either Glibc or Darwin
framework depending on the operating system the application is running on therefore
we will start off by importing these frameworks.<span style="mso-spacerun: yes;"> </span>Here is our import statement.<o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br />
</span><span class="s1"><span style="font-family: "courier new"; font-size: 9.0pt;"> import</span></span><span class="s2"><span style="font-family: "courier new"; font-size: 9.0pt;"> Foundation</span></span><span style="font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span class="s2"><span style="font-family: "courier new"; font-size: 9.0pt;"> #if</span></span><span class="s3"><span style="font-family: "courier new"; font-size: 9.0pt;"> </span></span><span class="s2"><span style="font-family: "courier new"; font-size: 9.0pt;">os</span></span><span class="s3"><span style="font-family: "courier new"; font-size: 9.0pt;">(</span></span><span class="s2"><span style="font-family: "courier new"; font-size: 9.0pt;">Linux</span></span><span class="s3"><span style="font-family: "courier new"; font-size: 9.0pt;">)</span></span><span style="font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span class="apple-converted-space"><span style="font-family: "courier new"; font-size: 9.0pt;"> </span></span><span class="s1"><span style="font-family: "courier new"; font-size: 9.0pt;">import</span></span><span class="s2"><span style="font-family: "courier new"; font-size: 9.0pt;"> Glibc</span></span><span style="font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span class="s2"><span style="font-family: "courier new"; font-size: 9.0pt;"> #else</span></span><span style="font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span class="apple-converted-space"><span style="font-family: "courier new"; font-size: 9.0pt;"> </span></span><span class="s1"><span style="font-family: "courier new"; font-size: 9.0pt;">import</span></span><span class="s2"><span style="font-family: "courier new"; font-size: 9.0pt;"> Darwin</span></span><span style="font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span class="s2"><span style="font-family: "courier new"; font-size: 9.0pt;"> #endif<o:p></o:p></span></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<br /></div>
<div class="NormalPACKT">
In this code we import the Glibc framework if we are
building for a Linux system otherwise we import the Darwin framework.<span style="mso-spacerun: yes;"> </span>We import the Foundation framework for both
platforms.<o:p></o:p></div>
<div class="NormalPACKT">
Now that we have imported the frameworks needed, lets
determine the byte order for the device.<span style="mso-spacerun: yes;">
</span><o:p></o:p></div>
<div class="CodeWithinTableColumnContentPACKT">
<br /></div>
<div class="CodeWithinTableColumnContentPACKT">
<span style="font-family: "courier new"; font-size: 9.0pt;"> let number: UInt32 = 0x12345678<o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span style="font-family: "courier new"; font-size: 9.0pt;"> let converted = number.bigEndian<o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span style="font-family: "courier new"; font-size: 9.0pt;"> if number == converted {<o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span style="font-family: "courier new"; font-size: 9.0pt;"> print("Big")<o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span style="font-family: "courier new"; font-size: 9.0pt;"> } else {<o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span style="font-family: "courier new"; font-size: 9.0pt;"> print("Little \(converted)")<o:p></o:p></span></div>
<div class="CodeWithinTableColumnContentPACKT">
<span style="font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br />
In this code we begin by defining a UInt32 number.<span style="mso-spacerun: yes;"> </span>We then convert how it is stored to big
endian.<span style="mso-spacerun: yes;"> </span>When we compare the original
number to the converted one, if the two numbers are equal then the device uses
big endian otherwise we know it uses little endian.<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">The Swift
standard library provides two instance properties that allow us to change the
byte order.<span style="mso-spacerun: yes;"> </span>These properties are
bigEndian and littleEndian.<span style="mso-spacerun: yes;"> </span>The device
that our code is running on probably uses little endian therefore when we use
the bigEndian property the byte order of the number is changed.<span style="mso-spacerun: yes;"> </span>This will give us a different number
therefore when we compare the original number to the converted one the numbers
will not match.<span style="mso-spacerun: yes;"> </span>This tells us that the
device uses little endian to store data.<span style="mso-spacerun: yes;">
</span>If the numbers do match, than we know the device uses big endian.<o:p></o:p></span></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="382">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Mention"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Smart Hyperlink"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNormal">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-36532006916198898332017-01-07T07:54:00.000-08:002017-01-07T07:54:30.940-08:00Creating a Swift module<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL60CzwvpiVSK8kZKRdXCxNhI4LXLyYg58bmwLQMdLGzonxcClKssl6w94tFeAPpwZd1vb1X8cyyk5SMdd4s9qREfBrB7VozU1vdwNtWfSfs0PIuXGi8QWlcFAYcH0VZ81MORuayE1CTig/s1600/puzzle-clip-art-blank-pieces-338542.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL60CzwvpiVSK8kZKRdXCxNhI4LXLyYg58bmwLQMdLGzonxcClKssl6w94tFeAPpwZd1vb1X8cyyk5SMdd4s9qREfBrB7VozU1vdwNtWfSfs0PIuXGi8QWlcFAYcH0VZ81MORuayE1CTig/s1600/puzzle-clip-art-blank-pieces-338542.jpg" /></a></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">When we
develop applications with Swift, for the Linux platform, we are able to use the
Swift package manager to assist us with building our application.<span style="mso-spacerun: yes;"> </span>The package manager is integrated with the
build system to automate the process of downloading, compiling and linking the
dependencies for our project.<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">One of
the ways that we can define a dependency is to create a module.<span style="mso-spacerun: yes;"> </span>Swift organises code into modules and each
module uses access controls to determine which parts of its code can be
accessed outside of the module.<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">For
several projects in this blog we will be using modules to link external C
libraries to our project.<span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>We will refer to this post when we need to
create these modules.<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="mso-spacerun: yes;"><br /></span></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">To create
a module we need to start off my creating a separate directory for it.<span style="mso-spacerun: yes;"> </span>If we were creating a module to link the </span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;"><span style="color: #0b5394;">ifaddrs.h</span></span></span><span lang="EN-GB" style="mso-ansi-language: EN-GB;"> header file to our project we would
want to create the directory like this:<o:p></o:p></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> mkdir ifaddrs</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">Within
this directory we need to create two files:<span style="mso-spacerun: yes;">
</span></span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;"><span style="color: #0b5394;">module.modulemap</span></span></span><span lang="EN-GB" style="mso-ansi-language: EN-GB;"> and </span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;"><span style="color: #0b5394;">Package.swift</span></span></span><span lang="EN-GB" style="mso-ansi-language: EN-GB;">.<span style="mso-spacerun: yes;">
</span>The </span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;"><span style="color: #0b5394;">module.modulemap</span></span></span><span style="mso-ansi-language: EN-GB;"> <span lang="EN-GB">file will contain a list of requirements for our
module while the </span></span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;"><span style="color: #0b5394;">Package.swift</span></span></span><span style="mso-ansi-language: EN-GB;"> <span lang="EN-GB">file defines the name of our
module.<span style="mso-spacerun: yes;"> </span>Let’s begin by looking at the </span></span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;"><span style="color: #0b5394;">Package.swift</span></span></span><span style="mso-ansi-language: EN-GB;"> <span lang="EN-GB">file first.<span style="mso-spacerun: yes;"> </span>To define the Ifaddrs module we would create
a </span></span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;"><span style="color: #0b5394;">Package.swift</span></span></span><span style="mso-ansi-language: EN-GB;"> <span lang="EN-GB">file with the following code:<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span style="mso-ansi-language: EN-GB;"><span lang="EN-GB"><br /></span></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> import PackageDescription<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> let package = Package(<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span>name: "Ifaddrs"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> )</span><o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">Now we
need to define the requirements for the Ifaddrs module in the </span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">module.modulemap</span></span><span style="mso-ansi-language: EN-GB;"> <span lang="EN-GB">file.<span style="mso-spacerun: yes;"> </span>For this module we simply want to import the </span></span><span class="CodeHighlightedPACKT"><span style="font-size: 9.0pt;">ifaddrs.h</span></span><span style="mso-ansi-language: EN-GB;"> <span lang="EN-GB">header file therefore we
would put the following code in the this file:<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span style="mso-ansi-language: EN-GB;"><span lang="EN-GB"><br /></span></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> module Ifaddrs [system] {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span>header
"/usr/include/ifaddrs.h"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span>export *<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><o:p></o:p></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">The Swift
package manager is based on the git repository therefore before we can use this
module within any project, we need to create a git repository for it.<span style="mso-spacerun: yes;"> </span>We could put this module in a github repository
but that may be too much for a simple module like this.<span style="mso-spacerun: yes;"> </span>We can create a local repository using the
following commands within the modules directory:<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> git init<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> git add .<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> git commit
–m “Initial Commit”<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> git tag
0.1.0</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">These
four commands will create a local git repository for our module with a major
version number of <b style="mso-bidi-font-weight: normal;">0</b> and a minor
version number of <b style="mso-bidi-font-weight: normal;">1</b>.<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">In the
Ifaddrs module we simply included the </span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;"><span style="color: #0b5394;">ifaddrs.h</span></span></span><span lang="EN-GB" style="mso-ansi-language: EN-GB;"> header file in our project but if
we wanted to include a third-party library, such as the libpcap library, we
would need to link the library to our project as well.<span style="mso-spacerun: yes;"> </span>For this we could link the library as shown
in the following example:<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> module Cpcap [system] {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span>header
"/usr/include/pcap.h"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span>link
"pcap"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span>export *<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-bidi-font-weight: bold;"><span style="mso-spacerun: yes;"> </span></span>}</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">Once we
create a module we can use the Swift package manager to automatically import
and build the module when we build our project.<span style="mso-spacerun: yes;">
</span>To do this, all we need to do is to define a dependency on the module
within the projects </span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">Package.swift</span></span><span style="mso-ansi-language: EN-GB;"> <span lang="EN-GB">file.<span style="mso-spacerun: yes;"> </span>The following example shows how we could
define a dependency on the Ifaddrs module:<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span style="mso-ansi-language: EN-GB;"><span lang="EN-GB"><br /></span></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="s1"> import</span><span class="s2">
PackageDescription</span><o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="s1"> let</span><span class="s2"> package = Package(</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="apple-converted-space"> </span><span class="s2">name: </span><span class="s3">"ipaddr"</span><span class="s2">,</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="apple-converted-space"> </span><span class="s2">dependencies: [</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="apple-tab-span"><span style="mso-tab-count: 1;"> </span></span><span class="apple-converted-space"><span style="mso-spacerun: yes;"> </span></span><span class="s2">.Package(url: </span><span class="s3">"../ifaddrs"</span><span class="s2">, majorVersion: </span><span class="s4">0</span><span class="s2">, minor: </span><span class="s4">1</span><span class="s2">)</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="apple-converted-space"> </span><span class="s2">]</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span class="s2"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> ) </span></span><o:p></o:p></div>
<div class="CodePACKT">
<span class="s2"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">The
dependencies array in the package defines the list of dependencies for our
project.<span style="mso-spacerun: yes;"> </span>The url is an absolute path to
our module.<span style="mso-spacerun: yes;"> </span>In this example the module
is located on our local drive however we can also define modules that should be
downloaded from the internet.<span style="mso-spacerun: yes;"> </span>The
following example shows how we defined the dependency for IBM’s BlueSocket
module:<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> import PackageDescription</span><o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> let package = Package(<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> name: "echoServer",<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> dependencies: [<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span> .Package(url:
"https://github.com/IBM-Swift/BlueSocket", majorVersion: 0, minor:
12)<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> ]<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> )</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">In this
example you will notice that the url defines a github repository rather than a
local repository.<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">Once we
define the dependency for a module we need to import it in our code.<span style="mso-spacerun: yes;"> </span>We would do this by using the import command
to import the namespace define by the module.<span style="mso-spacerun: yes;">
</span><o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="mso-spacerun: yes;"><br /></span></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">In the
beginning of this post we created the Ifaddrs module with the following </span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">Package.swift</span></span><span style="mso-ansi-language: EN-GB;"> <span lang="EN-GB">file:<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> import PackageDescription</span><o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> let package = Package(<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span>name: "Ifaddrs"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> )</span><o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">This
example created a namespace of </span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">Ifaddrs</span></span><span lang="EN-GB" style="mso-ansi-language: EN-GB;"> for the module therefore to use the
functionality provided by the module in our code we need to import the
namespace like this:<o:p></o:p></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> import
Ifaddrs</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;"><br /></span></div>
<div class="NormalPACKT">
<span lang="EN-GB" style="mso-ansi-language: EN-GB;">We will
be using modules extensively in this blog and will refer to this post to show
how to create them.<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:RelyOnVML/>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="382">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Mention"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Smart Hyperlink"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="NormalPACKT">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-90311066442203035762017-01-04T16:03:00.001-08:002017-01-05T17:24:50.578-08:00Mastering Swift 3 for Linux<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTEPW6__ea9nTk4VIjHKdCQc75wOlKNApHDRfKNsAPWLMLuM_xxINa36UE370lyUtOdYfupLU_k_siXc5Ae2tRHoGgpRbA1mSsadeTny1HZ3h2tdBRlKmNKC0UuvJLH-nyYUKpW36SBMWG/s1600/Swift3Linux.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTEPW6__ea9nTk4VIjHKdCQc75wOlKNApHDRfKNsAPWLMLuM_xxINa36UE370lyUtOdYfupLU_k_siXc5Ae2tRHoGgpRbA1mSsadeTny1HZ3h2tdBRlKmNKC0UuvJLH-nyYUKpW36SBMWG/s320/Swift3Linux.jpg" width="269" /></a></div>
<div class="NormalPACKT">
My
new book, <a href="http://amzn.to/2iR8yrQ">Mastering Swift 3 for Linux</a> has just been released. While most books on Swift are written to introduce the language using Apple’s development tools, this book is written for the developer that wants to use Swift on the Linux platform.</div>
<div class="NormalPACKT">
<span class="ChapterrefPACKT"><span style="font-style: normal;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="s1">I have always thought that a developer
cannot master a programming language without a good understanding of the
basics. With that philosophy in mind this book starts with the basics of
the Swift language before moving into more advance features and concepts. The
first five chapters will introduce the Swift programming language and will give
the reader a good understanding of the Swift programming language. The
second half of the book will cover more advance topics such as concurrency, network development,
using C libraries with Swift and memory management including strong reference
cycles.<o:p></o:p></span></div>
<div class="NormalPACKT">
<span class="s1"><br /></span></div>
<div class="NormalPACKT">
<span class="s1">This book also has a chapter
dedicated to using Swift on Single-Board Computers.<span style="mso-spacerun: yes;"> </span>The first half of this chapter will show the
reader how they can use Swift to interact with external devices like LEDs,
buttons and temperature sensors. The second half of the chapters shows the
reader how they can build and program an autonomous robot using Swift and the
BeagleBone Black.<o:p></o:p></span></div>
<div class="NormalPACKT">
<span class="s1"><br /></span></div>
<div class="NormalPACKT">
<span class="s1">Here is a description of what is covered in
each chapter of the book:</span><span class="MsoSubtleReference"><span style="font-family: "times"; font-size: 10.0pt; font-variant: normal; text-decoration: none;"><o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="s1"><br /></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 1</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Taking the First Steps
with Swift</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, gives a brief introduction to the Swift language. </span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">It</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"> also
cover</span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">s</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"> the
basic Swift language syntax and discuss proper language styles.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 2</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Learning About Variables,
Constants, Strings, and</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"> Operators, will show how to use
variables and constants in Swift. </span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">It will also discuss</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"> the
various data types and how to use operators in Swift.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 3</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Using Swift Collections
and the Tuple Type</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will look at how we can use the
Swift collection types to store related data. These collection types are the array</span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">, set and dictionay</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"> types. <o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 4</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Control Flow and Functions</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will
cover control flow and functions in Swift. It is essential to understand the concepts
in this chapter before going on. Every application that we write, beyond the
simple Hello World applications, will rely very heavily on the control flow
statements and functions.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 5</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Classes and Structures</span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">, will </span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">look at
what makes </span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">Class and Structures</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"> similar and what makes them
different. We'll also look at access controls and object-oriented design. </span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">The chapter also covers </span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">memory
management in Swift.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 6</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Using Protocols and
Protocol Extensions</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will cover both protocols and
protocol extensions in detail since protocols are very important to the Swift
language, and having a solid understanding of them will help us write flexible
and reusable code.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 7</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Protocol-Oriented Design</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will
cover the best practices of Protocol-Oriented Design with Swift. It will be a
brief overview of what is covered in my Swift 3 Protocol-Oriented Programming
(POP) book.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 8</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Writing Safer Code with
Error Handling</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will look at Swift’s error- handling features. While
we are not required to use this feature in our custom types, it does give us a
uniform manner to handle and respond to the error. <o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 9</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Custom Subscripting</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will
discuss how we can use custom subscripts in our classes, structures, and
enumerations. Subscripts in Swift can be used to access elements in a
collection. We can also define custom subscripts for our classes, structures,
and enumerations.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 10</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Using Optional Types</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will
explain what optional types </span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">are and</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"> the various ways to unwrap them.
For a developer who is just learning Swift, optional types can be one of the
most confusing items to learn.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 11</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Working with Generics</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will
explain how Swift implements generics. Generics allow us to write very flexible
and reusable code that avoids duplication.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 12</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Working with Closures</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will
teach us how to define and use closures in our code. Closures in Swift are
similar to blocks in Objective-C except that they have a much cleaner and
easier way of using syntax. </span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">This chapter concludes</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"> with a
section on how t</span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">o avoid strong reference cycles.</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"><o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 13</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Using C Libraries with
Swift</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will explain how we can link and use standard C libraries
with our Swift applications.<span style="mso-spacerun: yes;"> </span>This gives
S</span></span><span class="ChapterrefPACKT"><span style="font-style: normal;">wift
developers access to all</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"> the same libraries that Linux C
developers have access too.</span></span><span class="ChapterrefPACKT"><span style="font-style: normal;"><span style="mso-spacerun: yes;"> </span>Knowing how
to use C libraries with Swift is essential for any developer that wants to
develop Linux apps with Swift</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"><o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="ChapterrefPACKT"><b style="mso-bidi-font-weight: normal;"><u><span style="color: windowtext; font-style: normal;">Chapter 14</span></u></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Concurrency and
Parallelism in Swift</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will show how to use Grand Central
Dispatch to add concurrency and parallelism to our applications. Understanding
and knowing how to add concurrency and parallelism to our apps can
significantly enhance the user experience.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 15</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Swift's Core Libraries</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will
be a chapter on using the Swift core libraries, including reading/writing
files, network primitives, and JSON parsing.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 16</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, S</span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">wift on single-board
computers</span>,</span><span class="ChapterrefPACKT"><span style="color: windowtext;">
</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">will show how we can use Swift for</span></span><span class="ChapterrefPACKT"><span style="font-style: normal;"> IoT</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"> and
robotic projects using a single-board computer.</span></span><span class="ChapterrefPACKT"><span style="font-style: normal;"><span style="mso-spacerun: yes;"> </span>This chapter will feature the BeagleBone
Black and the Swifty Bones library.</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;"><o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="MsoSubtleReference"><b style="mso-bidi-font-weight: normal;"><span style="color: windowtext;">Chapter 17</span></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Swift Formatting and Style
Guide</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will define a style guide for the Swift language that can
be used as a template for enterprise developers who need to create a style
guide, since most enterprises have style guides for the various languages that
they develop in.<o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span class="ChapterrefPACKT"><b style="mso-bidi-font-weight: normal;"><u><span style="color: windowtext; font-style: normal;">Chapter 18</span></u></b></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, </span></span><span class="ChapterrefPACKT"><span style="color: windowtext;">Adopting Design Patterns
in Swift</span></span><span class="ChapterrefPACKT"><span style="color: windowtext; font-style: normal;">, will show you how to implement some of the more common
design patterns in Swift. A design pattern identifies a common software
development problem and provides a strategy for dealing with it.</span></span><span class="ChapterrefPACKT"><span style="font-style: normal;"><o:p></o:p></span></span></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="382">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Mention"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Smart Hyperlink"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="NormalPACKT">
<span class="ChapterrefPACKT"><span style="font-style: normal;"><br /></span></span></div>
<div class="NormalPACKT">
<span class="ChapterrefPACKT">
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false"
DefSemiHidden="false" DefQFormat="false" DefPriority="99"
LatentStyleCount="382">
<w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index 9"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" Name="toc 9"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="header"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footer"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="index heading"/>
<w:LsdException Locked="false" Priority="35" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of figures"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="envelope return"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="footnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="line number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="page number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote reference"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="endnote text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="table of authorities"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="macro"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="toa heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Bullet 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Number 5"/>
<w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Closing"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Signature"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="true"
UnhideWhenUsed="true" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="List Continue 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Message Header"/>
<w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Salutation"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Date"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text First Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Heading"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Body Text Indent 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Block Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Hyperlink"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="FollowedHyperlink"/>
<w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Document Map"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Plain Text"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="E-mail Signature"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Top of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Bottom of Form"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal (Web)"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Acronym"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Address"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Cite"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Code"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Definition"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Keyboard"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Preformatted"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Sample"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Typewriter"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="HTML Variable"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Normal Table"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="annotation subject"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="No List"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Outline List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Simple 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Classic 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Colorful 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Columns 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Grid 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table List 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table 3D effects 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Contemporary"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Elegant"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Professional"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Subtle 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Web 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Balloon Text"/>
<w:LsdException Locked="false" Priority="39" Name="Table Grid"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Table Theme"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 1"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 2"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 3"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 4"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 5"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 7"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 8"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Note Level 9"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" SemiHidden="true" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" QFormat="true"
Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" QFormat="true"
Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" QFormat="true"
Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" QFormat="true"
Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" QFormat="true"
Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" QFormat="true"
Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" SemiHidden="true"
UnhideWhenUsed="true" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" SemiHidden="true"
UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/>
<w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/>
<w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/>
<w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/>
<w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/>
<w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/>
<w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/>
<w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="Grid Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="Grid Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="Grid Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/>
<w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/>
<w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 1"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 1"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 2"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 2"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 3"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 3"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 4"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 4"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 5"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 5"/>
<w:LsdException Locked="false" Priority="46"
Name="List Table 1 Light Accent 6"/>
<w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/>
<w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/>
<w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/>
<w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/>
<w:LsdException Locked="false" Priority="51"
Name="List Table 6 Colorful Accent 6"/>
<w:LsdException Locked="false" Priority="52"
Name="List Table 7 Colorful Accent 6"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Mention"/>
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true"
Name="Smart Hyperlink"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--></span></div>
<div class="NormalPACKT">
This book is written in an example-based approach where
each topic covered is backed by examples which are designed to reinforce the
topic covered and show how to implement it within the reader's own code. </div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span class="ChapterrefPACKT"><span style="font-style: normal;">You can purchase the book from <a href="http://amzn.to/2iR8yrQ">Amazon</a>.<o:p></o:p></span></span></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-86425807767086322692016-12-10T07:09:00.001-08:002016-12-10T07:23:51.811-08:00Swift 3, Protocol-Oriented Programming<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1tPLp2ww0vzmEILx4-W-3YhAfNZQFlxoHTyeeX9fUk5_PC4BiIonNj8y04fDuTZs89Ramn-JpHQ_RIYxKngzhi28cMJmoOHsCn9Me1qRDjDQtVpQ-d3R7qQEZt9MVXiW-d0NFO15PFqaf/s1600/POPv2.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1tPLp2ww0vzmEILx4-W-3YhAfNZQFlxoHTyeeX9fUk5_PC4BiIonNj8y04fDuTZs89Ramn-JpHQ_RIYxKngzhi28cMJmoOHsCn9Me1qRDjDQtVpQ-d3R7qQEZt9MVXiW-d0NFO15PFqaf/s320/POPv2.jpg" width="259" /></a></div>
<div class="MsoListParagraphCxSpFirst">
My new book, <a href="http://amzn.to/2gp45Py">Swift 3 Protocol Oriented Programming </a>has been released.<span style="mso-spacerun: yes;"> </span>I wrote
the original Protocol Oriented Programming book when Swift 2 was released and
since then a lot has changed with the language.<span style="mso-spacerun: yes;">
</span>This new book is a major rewrite and includes an additional chapter on
generics.<span style="mso-spacerun: yes;"> </span>The following gives an
overview of each chapter:<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
<span class="ChapterrefPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: Arial;"><span style="color: red;">Chapter 1</span></span></span>,<span class="ItalicsPACKT"><span style="font-family: "arial"; mso-bidi-font-family: "Times New Roman";">
</span></span><span class="ItalicsPACKT"><span style="font-size: small;"><b>Object-Oriented
Programming vs Protocol-Oriented Programming</b></span></span><span style="mso-bidi-font-size: 11.0pt;">,</span><span class="ItalicsPACKT"><span style="font-size: 11.0pt; mso-bidi-font-size: 12.0pt;"> </span></span><span style="font-family: "times new roman"; font-size: 11.0pt;">This chapter will show
the differences between object-oriented programming and protocol-oriented programming
giving the reader a good understanding of the difference paradigms.<span style="mso-spacerun: yes;"> </span>By the end of the chapter the reader should
have a basic understanding of protocol-oriented programming and what it offers.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<span class="ChapterrefPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: Arial;"><span style="color: red;">Chapter 2</span></span></span>,<span class="ItalicsPACKT">
<b><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small;">Our Type Choices</span></b><span style="font-family: "arial";"><span style="font-size: medium;">,</span> </span></span>In this chapter we will look at the different
types that Swift offers (Structs, Classes, Enums and Tuples).<span style="mso-spacerun: yes;"> </span>We will show several examples of when to use
the various types and when not too.<br />
<div class="MsoListParagraphCxSpMiddle">
<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
<span class="ChapterrefPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: Arial;"><span style="color: red;">Chapter 3</span></span></span>,<span class="ItalicsPACKT">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small;"><b>Catching our Errors</b></span></span><span class="ItalicsPACKT"><span style="font-size: large; mso-bidi-font-size: 12.0pt;">, </span></span><span style="font-family: "times new roman"; font-size: 11.0pt;">This chapter will look
at the various ways that we can catch and report errors.<span style="mso-spacerun: yes;"> </span>This chapter will not only cover the new
Swift 2 do-try-catch blocks but also the older error catching patterns<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
<span class="ChapterrefPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: Arial;"><span style="color: red;">Chapter 4</span></span></span>, <span class="ItalicsPACKT"><span style="font-family: "arial"; mso-bidi-font-family: "Times New Roman";"><span style="font-size: small;"><b>It’s
all about the Protocol</b></span></span></span><span class="ItalicsPACKT"><span style="font-size: large; mso-bidi-font-size: 12.0pt;">,</span><span style="font-size: 11.0pt; mso-bidi-font-size: 12.0pt;"> </span></span><span style="font-family: "times new roman"; font-size: 11.0pt;">This chapter will be all
about the protocol.<span style="mso-spacerun: yes;"> </span>We will show the
advantages of using protocols and why, in our design, we should always think
about the protocol first and the actual types that conform to the protocol
second.</span><i style="mso-bidi-font-style: normal;"> <o:p></o:p></i></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
<span class="ChapterrefPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: Arial;"><span style="color: red;">Chapter 5</span></span></span>,<span class="ItalicsPACKT"><span style="font-family: "arial"; mso-bidi-font-family: "Times New Roman";">
<span style="font-size: small;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small;"><b>Lets extend some types</b></span><span style="font-family: "arial"; font-size: large;">, </span></span></span></span>This chapter will cover extensions in
great detail.<span style="mso-spacerun: yes;"> </span>We will look at how to extend
standard Swift types like structures and classes.<span style="mso-spacerun: yes;"> </span>We will also look at protocol extensions and
discuss why they are so important to Protocol-Oriented programming.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
<span class="ChapterrefPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: Arial;"><span style="color: red;">Chapter 6</span></span></span>,<span class="ItalicsPACKT"><span style="font-family: "arial"; mso-bidi-font-family: "Times New Roman";">
<span style="font-size: small;"><b>Working with Generics</b></span></span></span><span style="font-size: large;">,</span> This chapter will cover generics.<span style="mso-spacerun: yes;"> </span>We will look at how we generics can be used
with the protocol-oriented programming paradigm to write flexible and reusable
code.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
<span class="ChapterrefPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: Arial;"><span style="color: red;">Chapter 7</span></span></span>, <span class="ItalicsPACKT"><span style="font-family: "arial"; mso-bidi-font-family: "Times New Roman";"><span style="font-size: xx-small;"><b><span style="font-size: small;">Design
Patterns with Protocol-Oriented programming</span></b></span><span style="font-size: large;">,</span> </span></span>We will be
implementing several design patterns using protocol-oriented programming.<span style="mso-spacerun: yes;"> </span>For each of the design patterns we will look
at the problem they are designed to solve and how to implement the pattern.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="color: red;"><span class="ChapterrefPACKT"><span style="font-size: 11.0pt; mso-bidi-font-family: Arial;">Chapter 8</span></span>,</span> <span style="font-size: small;"><span class="ItalicsPACKT"><span style="font-family: "arial"; mso-bidi-font-family: "Times New Roman";"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small;"><b>Case
Studies</b></span></span></span><span style="font-size: large;">,</span></span> In this chapter we will explore three case studies.<span style="mso-spacerun: yes;"> </span>This chapter is designed to pull everything
from the first six chapters together to show the reader how to use
Protocol-Oriented programming is real world situations. <o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoListParagraphCxSpLast">
This book will guide you through every aspect
of protocol-oriented programming to help you take advantage of it in your
applications. You can purchase a copy of the book on <a href="http://amzn.to/2gp45Py">Amazon</a>.<o:p></o:p></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-42533042646926630382016-11-17T14:42:00.000-08:002016-11-17T14:43:21.564-08:00Mastering Swift 3<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi1iOqQe3DOrjxn9XE-rjkAAAcBzjPDbnzBSCu0qteVlmsB8ait9CavbZ0l19-EzzLYycSfs2nb8nX0NxQHlGvE_9pYyV-0CUa0TjkBkHGhGhafQozOaiCZjt-9hp8ePnrhiZ0I-r_2qyf/s1600/masteringSwift3Apple.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi1iOqQe3DOrjxn9XE-rjkAAAcBzjPDbnzBSCu0qteVlmsB8ait9CavbZ0l19-EzzLYycSfs2nb8nX0NxQHlGvE_9pYyV-0CUa0TjkBkHGhGhafQozOaiCZjt-9hp8ePnrhiZ0I-r_2qyf/s320/masteringSwift3Apple.jpg" width="259" /></a></div>
<div class="MsoNormal">
Mastering Swift 3 has been released<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
I wrote the original Mastering Swift book in 2015 and have
updated it for each major release of the Swift language.<span style="mso-spacerun: yes;"> </span>Today I would like to announce the release of
my new book titled Mastering Swift 3.<span style="mso-spacerun: yes;">
</span>Mastering Swift 3 has been updated to reflex the changes in Swift with
the third release of the language.<span style="mso-spacerun: yes;"> </span>You
can purchase the book from <a href="http://amzn.to/2g0qDkV">Amazon</a>.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The following gives an overview of what is covered in
Mastering Swift 3:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 1</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Taking the
First Steps with Swift</span></b>, will introduce you to the Swift programming
language and discuss what inspired Apple to create Swift. We'll also go over
the basic syntax of Swift and how to use Playgrounds to experiment and test
Swift code.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 2</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Learning about
Variables, Constants, Strings, and Operators</span></b>, will introduce you to
variables and constants in Swift and when to use them. There will be brief
overviews of the most common variable types with examples on how to use them.
We'll conclude this chapter by showing examples of how to use the most common
operators in the Swift language.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 3</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Using
Collections and the Tuple type</span></b>, will explain Swift's array, set, and
dictionary collection types and show examples on how to use them. We'll also
show how to use the Tuple type in Swift.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 4</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Control Flow and
Functions</span></b>, will show you how to use Swift's control flow statements.
These include loops, conditional, and control transfer statements. The second
half of the chapter is all about functions.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 5</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Classes and
Structures</span></b>, is dedicated to Swift's classes and structures. We'll
look at what makes them similar and what makes them different. We'll also look
at access controls. We'll close this chapter out by looking at memory
management in Swift so you will understand how ARC works and how to avoid Strong
Reference Cycles.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 6</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Using
Protocols and Protocol Extensions</span></b>, will cover both protocols and
protocol extensions in detail since protocols are very important to the Swift
language, and having a solid understanding of them will help us write flexible
and reusable code.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 7</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Protocol
Oriented Design</span></b>, will cover the best practices of Protocol Oriented
Design with Swift.<span style="mso-spacerun: yes;"> </span>It will be a brief
overview of what is covered in my POP book (which will soon be updated for
Swift 3).<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 8</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Writing Safer
Code with Availability and Error Handling</span></b>, will cover error handling
in depth as well as the new availability feature. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 9</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Custom
Subscripting</span></b>, will discuss how we can use custom subscripts in our
classes, structures, and enumerations. Subscripts in Swift can be used to
access elements in a collection. We can also define custom subscripts for our
classes, structures, and enumerations.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 10</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Using Optional
Types</span></b>, will explain what optional types really are, what are the
various ways to unwrap them, and optional chaining. For a developer who is just
learning Swift, optional types can be one of the more confusing items to learn.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 11</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Working with
Generics</span></b>, will explain how Swift implements generics. Generics allow
us to write very flexible and reusable code that avoids duplication.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 12</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Working with
Closures</span></b>, will teach us how to define and use closures in our code.
Closures in Swift are similar to blocks in Objective-C except that they have a
much cleaner and easier way of using syntax. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 13</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Using Mix and
Match</span></b>, will explain mix and match and demonstrate how we can include
Swift code in our Objective-C projects and Objective-C code in our Swift
projects. With all of the apps and frameworks written in Objective-C, it was
important to allow Swift and Objective-C code to work together.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 14</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Concurrency
and Parallelism in Swift</span></b>, will show how to use both Grand Central
Dispatch and Operation Queues to add concurrency and parallelism to our
applications. Understanding and knowing how to add concurrency and parallelism
to our apps can significantly enhance the user experience.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 15</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Swift
Formatting and Style Guide</span></b>, will define a style guide for the Swift
language that can be used as a template for enterprise developers who need to
create a style guide since most enterprises have style guides for the various
languages that they develop in.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 16</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Swift Core
Library</span></b>, will explore some of the functionality in the Swift core
library.<span style="mso-spacerun: yes;"> </span>This will include accessing
REST services, working with JSON data and the formatting framework.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #ca4915;">Chapter 17</span>, <b><span style="font-family: Roboto-Bold; mso-bidi-font-family: Roboto-Bold;">Adopting
Design Patterns in Swift</span></b>, will show you how to implement some of the
more common design patterns in Swift. A design pattern identifies a common
software development problem and provides a strategy for dealing with it.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNormal">
If you are new to the Swift programming language and looking
for a book to teach you the basics of the language or an intermediate level
developer that is looking for a book to teach you some of the advance topics of
the language then Mastering Swift 3 may be the book you are looking for.<span style="mso-spacerun: yes;"> </span>You can purchase the book from Amazon.<o:p></o:p></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com3tag:blogger.com,1999:blog-1266480015345788892.post-47405807352008808632016-05-02T18:11:00.000-07:002016-05-02T18:11:35.232-07:00Swift and the Beaglebone Black – Better together with SwiftyBones<div class="separator" style="clear: both; text-align: center;">
<a href="https://github.com/hoffmanjon/SwiftyBones/raw/master/images/logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="106" src="https://github.com/hoffmanjon/SwiftyBones/raw/master/images/logo.png" width="320" /></a></div>
<div class="MsoNormal">
<a href="https://github.com/hoffmanjon/SwiftyBones">SwiftyBones</a> is a modular Swift library for interacting with both the digital GPIO and Analog pins on the BeagleBone Black. This library is written to make it easy to write Swift applications that run on the Beaglebone Black that interacts with external sensors, LED or any device connected to the Digital GPIO and/or Analog pins. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Since <a href="https://github.com/hoffmanjon/SwiftyBones">SwiftyBones</a> is a modular library you only need to include the functionality required for your projects rather than all of the functionality. Currently <a href="https://github.com/hoffmanjon/SwiftyBones">SwiftyBones</a> supports both digital GPIO and Analog however I need to add PWM support soon for my robotics projects that my daughter and I want to work on this summer so you should hopefully see it supported soon as well.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<a href="https://github.com/hoffmanjon/SwiftyBones">SwiftyBones</a> comes with a script called swiftybuild.sh that will help you build swift projects with multiple files. This script comes in very handy since <a href="https://github.com/hoffmanjon/SwiftyBones">SwiftyBones</a> itself contains multiple files. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
There are several example projects (with Fritzing diagrams) included with SwiftyBones to help you get started using Swift and SwiftyBones with your next IoT, Robotic or any other project you are working on with the Beaglebone Black.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
Please feel free to send me any suggestions that you may have for this project. Also please feel free to contribute code especially if you know how to get PWM working with the 4.1+ kernel.</div>
<br />Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-60339316273207702682016-04-17T09:43:00.001-07:002016-04-17T09:58:21.838-07:00What is Protocol Oriented Programming to me?<div class="MsoNormal">
</div>
<div class="MsoNormal">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDTHuklI8xv-JRiKTFYdRl1C3wv5QCNxVckxm6pMicCALF02V3XUdSqJXL0xJ12p4dlg8gL14-kIlCvKLCc6yjTSkpByN0W09z3chlQ_7XGDFQ1ZIMD2CbY8OpNZhqS9WA0geJCOUxZdL3/s1600/POPcover.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDTHuklI8xv-JRiKTFYdRl1C3wv5QCNxVckxm6pMicCALF02V3XUdSqJXL0xJ12p4dlg8gL14-kIlCvKLCc6yjTSkpByN0W09z3chlQ_7XGDFQ1ZIMD2CbY8OpNZhqS9WA0geJCOUxZdL3/s1600/POPcover.jpg" /></a></div>
I have had numerous conversations about what exactly is
Protocol Oriented Programming since my <a href="http://amzn.to/1qKDwoz">Protocol Oriented Programming with Swift book</a> was released.<span style="mso-spacerun: yes;">
</span>Everyone I spoke to seemed to have his or her own opinion about what POP
is.<span style="mso-spacerun: yes;"> </span>Out of all of those conversations I
think this is the best explanation that I heard “<i>Programming with an
orientation toward the use of protocols for abstraction</i>”.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
So what do we mean when we say that POP is “<i>Programming with
an orientation toward the use of protocols for abstraction</i>”?<span style="mso-spacerun: yes;"> </span>Quite simply my interpretation of this is
with POP we should be programming to a protocol and not to an
implementation.<span style="mso-spacerun: yes;"> </span>This is very similar to
other languages where we use interfaces however Protocols in Swift take a more
predominate role within the language itself where as other languages, like C#
and Java, the interface really takes a back seat to the class hierarchy.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
In my <a href="http://masteringswift.blogspot.com/2016/02/pop-and-oop.html">POP vs OOP post </a>I demonstrated a lot more than just the protocol so you may be asking yourself
what are all of the other features that I talked about.<span style="mso-spacerun: yes;"> </span>This is very similar to saying that Object
Oriented programing is based on the concept of programming with objects.<span style="mso-spacerun: yes;"> </span>Now we all know that good OOP design is about
a lot more than just the object, similarly good POP design is about more than
just the protocol which is why I think Apple introduced Protocol Extensions
during their POP presentation (I could be wrong about and it is just my
opinion).<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
So what makes for a good POP design?<span style="mso-spacerun: yes;"> </span>The post that I wrote that compared OOP to
POP <span style="mso-spacerun: yes;"> </span>really showed what I think is good
<a href="http://masteringswift.blogspot.com/2016/02/pop-and-oop.html">POP design</a>.<span style="mso-spacerun: yes;"> </span>You could also pick up my <a href="http://amzn.to/1qKDwoz">Protocol OrientedProgramming with Swift book</a> on the subject as well
:).<span style="mso-spacerun: yes;"> </span>In this post rather than going in
depth in to POP design I would like to touch on a couple of points that people
have brought up to me based on my book and earlier post.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt;">Protocol Extensions are simply </span></b><b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; mso-bidi-font-family: Helvetica;">syntactic sugar<o:p></o:p></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
When people say that Protocol extensions are simply
syntactic sugar they are absolutely correct however there is nothing wrong with
syntactic sugar.<span style="mso-spacerun: yes;"> </span>There are other ways
that we can avoid duplicate code when using value types however protocol
extensions are very convenient and also gives us good code organization however
for good code organization we do want to avoid having multiple extensions for a
single protocol or type.<span style="mso-spacerun: yes;"> </span>For example we
should avoid this unless each extension has different constraints defined.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">protocol</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> Foo {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> x: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {</span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">get</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">set</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">extension</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Foo</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> add(y: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">x</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> + y<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">extension</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Foo</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> sub(y: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">x</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> - y<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt;">Use Protocol Extensions with caution and use
constraints where necessary<o:p></o:p></span></b></div>
<div class="MsoNormal">
It is very ease to simply add a protocol extension without
thinking too much about the types that conform to the protocol.<span style="mso-spacerun: yes;"> </span>For example in my <a href="http://amzn.to/1qKDwoz">POP book</a> I used the
following example of how to extend the <b style="mso-bidi-font-weight: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">CollectionType</span></b>
protocol.<span style="mso-spacerun: yes;"> </span>I then followed it<span style="mso-spacerun: yes;"> </span>up in my book up by pointing out how this
extension does not work for all types that conform to the <b style="mso-bidi-font-weight: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">CollectionType</span></b>
protocol like the <b style="mso-bidi-font-weight: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Dictionary</span></b>
type therefore we either needed to use a constraint to limit the implementations that received this functionality or only extend the specific
implementation that needs this functionality..<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">extension</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> </span><span style="color: #5c2699; font-family: "menlo regular"; font-size: 11.0pt;">CollectionType</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">func</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">
evenElements() -> [Generator.Element] {<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">var</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> index = </span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">self</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">.</span><span style="color: #5c2699; font-family: "menlo regular"; font-size: 11.0pt;">startIndex</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">var</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> result:
[Generator.Element] = []<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">var</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> i = </span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 11.0pt;">0</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">repeat</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">if</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> i % </span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 11.0pt;">2</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> == </span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 11.0pt;">0</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span>result.</span><span style="color: #2e0d6e; font-family: "menlo regular"; font-size: 11.0pt;">append</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">(</span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">self</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">[index])<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span>index = index.</span><span style="color: #2e0d6e; font-family: "menlo regular"; font-size: 11.0pt;">successor</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">()<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span>i += </span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 11.0pt;">1</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span>} </span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">while</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> (index != </span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">self</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">.</span><span style="color: #5c2699; font-family: "menlo regular"; font-size: 11.0pt;">endIndex</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">return</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> result<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">func</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> shuffle()
-> [</span><span style="color: #3f6e74; font-family: "menlo regular"; font-size: 11.0pt;">Self</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">.Generator.Element] {<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">return</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> </span><span style="color: #2e0d6e; font-family: "menlo regular"; font-size: 11.0pt;">sort</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">(){ left,
right </span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">in</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 11.0pt;">return</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"> </span><span style="color: #2e0d6e; font-family: "menlo regular"; font-size: 11.0pt;">arc4random</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">() < </span><span style="color: #2e0d6e; font-family: "menlo regular"; font-size: 11.0pt;">arc4random</span><span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">()<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 11.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt;">Avoid getting to granular with your protocols<o:p></o:p></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
To me, making smaller more specific protocols and using
protocol inheritance and composition as I illustrated in my <a href="http://masteringswift.blogspot.com/2016/02/pop-and-oop.html">POP vs OOP post</a> is an advantage that POP design has over OOP design however it was pointed out
to me by a very smart person that we need to avoid getting to granular with our
protocol designs.<span style="mso-spacerun: yes;"> </span>In OOP we have the
problem where we get large monolithic super classes and sometimes this can not
be avoided however with POP we as programmers and architects need to avoid
making our protocols to granular.<span style="mso-spacerun: yes;"> </span>The
following code illustrates what we want to avoid.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">protocol</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> FooAdd {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> add(x: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">, y: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">protocol</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> FooSub {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> sub(x: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">, y: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">protocol</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> FooMul {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> mul(x:</span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">, y: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">struct</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> Bar1: </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">FooAdd</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">, </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">FooSub</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">, </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">FooMul</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> add(x: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">, y: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> x + y<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> sub(x: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">, y: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> x - y<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> mul(x:</span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">, y: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> x * y<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;">
</span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
In this example, FooAdd, FooSub and FooMul protocols only
contain one function each and those functions are related (mathematical
operation) therefore it really makes since to put them into a single
protocol.<span style="mso-spacerun: yes;"> </span>If you have multiple protocols
that you are always grouping together, you may want to consider combining them
into a single protocol.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt;">Error Handling in POP<br style="mso-special-character: line-break;" />
<!--[if !supportLineBreakNewLine]--><br style="mso-special-character: line-break;" />
<!--[endif]--><o:p></o:p></span></b></div>
<div class="MsoNormal">
In my <a href="http://amzn.to/1qKDwoz">Protocol Oriented programming with Swift book</a>, I have
a chapter on error handling.<span style="mso-spacerun: yes;"> </span>I have been
questioned about this since error handling is really part of the language
itself and not really part of the POP paradigm.<span style="mso-spacerun: yes;">
</span>These people are absolutely 100% correct however anytime we write or
design an application we need to worry about how we will respond to and recover
from errors therefore to me error-handling needs to be a part of any good
design.<span style="mso-spacerun: yes;"> </span>With this in mind, in my
opinion, a book that talks about design, with a specific language, should include
something on error handling.<span style="mso-spacerun: yes;"> </span>That really
is just my opinion and hopefully explains why I included a chapter on error
handling in my book.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt;">My Books and Posts<o:p></o:p></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
I received a one star review of my Protocol Oriented
Programming with Swift book with a comment about my writing style.<span style="mso-spacerun: yes;"> </span>Another person responded to the comment
saying “<span style="mso-bidi-font-family: Verdana;">The writing style in this
book is actually very good. It is written so even the non-programmer can
understand and grasp the concepts behind POP.</span>”<span style="mso-spacerun: yes;"> </span>That is really my goal not only in my books
but also in this blog.<span style="mso-spacerun: yes;"> </span>I try to write in
a way that everyone can grasp the concepts discussed.<span style="mso-spacerun: yes;"> </span>My favorite review that I have received for
any of my books was one for my Mastering Swift 2 book where the reviewer said,
“<span style="color: #0e0e0e; mso-bidi-font-family: Arial;">This book is simple
enough my 13 years old has started reading it and while I do not anticipate him
reading past chapter 12...it is easy enough for him to follow.</span>”<span style="mso-spacerun: yes;"> </span>I hope that I will always continue that
writing style.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
You see to me programming is something that is fun and
magical.<span style="mso-spacerun: yes;"> </span>I still remember the feeling I
had as a 13 year old kid and writing my first Brickout game on a Commodore
VIC-20.<span style="mso-spacerun: yes;"> </span>Programming does not need to be
overly complicated however we do need to ensure that our code works properly
and can be easily maintained.<span style="mso-spacerun: yes;"> </span>I really
hope my posts and my books have helped.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNormal">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-52214419189609503822016-04-04T06:56:00.000-07:002016-04-04T06:56:31.454-07:00Swift and the BeagleBone Black<br />
<div class="separator" style="clear: both; text-align: left;">
Now that I have completed my three books on Swift (<a href="http://amzn.to/25FsL71">MasteringSwift</a>, <a href="http://amzn.to/1N4vVpm">Mastering Swift 2</a> and <a href="http://amzn.to/25FsG34">Protocol Oriented Programming with Swift</a>), I told
my daughters that I would take a break from writing books for the summer. My oldest told me that she wanted to start
working on robots again. At the age of
ten, She is already a second-degree black belt, and an instructor in Tae Kwon Do so
when she says she wants to do do something I generally listen. So after a little discussion about what she
wanted to do, we decided that we would pull out all of the robot parts and
start working with our <a href="http://amzn.to/25Fggs2">BeagleBone Blacks</a> again.</div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
I had to start off by doing some reading to catch up with everything
that has happened over the past year and a half that spent writing.<span style="mso-spacerun: yes;"> </span>In my reading I happened to stumble on the <a href="http://dev.iachieved.it/iachievedit/debian-packages-for-swift-on-arm/">iacheived.it</a> site
that showed how to install Swift on the BeagleBone Black.
I also found the <a href="https://github.com/uraimo/SwiftyGPIO">SwiftyGPIO package</a>
(control the BeagleBone Black GPIO with Swift) that was featured on <a href="https://swiftpkgs.ng.bluemix.net/">IBM’s Swiftpackage library</a>.<span style="mso-spacerun: yes;"> </span>So this got me thinking about being able to
program our robots with Swift, now that sounds pretty exciting doesn’t it?<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Note: This post and a most of the ones that show how to use
Swift with the <a href="http://amzn.to/25Fggs2">BeagleBone Black</a> will be crossed
posted between my <a href="http://myroboticadventure.blogspot.com/">Robotics Blog</a> and
my <a href="http://masteringswift.blogspot.com/">Swift programming blog</a>.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The first part of this post will walk you through setting up
your <a href="http://amzn.to/25Fggs2">BeagleBone Black</a>.<span style="mso-spacerun: yes;"> </span>After we get the <a href="http://amzn.to/25Fggs2">BeagleBone Black</a> setup we will write some code that will let us control
an LED with a button.<span style="mso-spacerun: yes;"> </span>I know controlling
a led with a button isn’t that exciting but we need to start somewhere and that
really is like a “Hello World” application so lets get started.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Setting up our BeagleBone Black<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The following list will walk you through setting up the
<a href="http://amzn.to/25Fggs2">BeagleBone Black</a>.<span style="mso-spacerun: yes;">
</span>Rather than writing out detail instructions I will provide links to the
pages that I followed when I set up my boards.<span style="mso-spacerun: yes;">
</span>Since I use a Macbook Pro, the instructions are for the Mac.<span style="mso-spacerun: yes;"> </span>Sorry, but I do not have a Windows machine to
mirror the steps on however the only Mac specific areas in these steps in where
we copy the image over to the SD card and the <a href="http://beagleboard.org/getting-started">Beagle Board site </a>has a getting
started page that may help anyone that uses Windows with these steps.<span style="mso-spacerun: yes;"> </span>If you use the Beagle
Board site, once you get the image on the SD card, you can skip to step 4
below.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
1.<span style="mso-spacerun: yes;"> </span>Get the latest
Debian 8.3 image from Beagle Board’s site.<span style="mso-spacerun: yes;">
</span>You can find the image<a href="https://beagleboard.org/latest-images"> here</a>.<o:p></o:p></div>
<div class="MsoNormal">
2.<span style="mso-spacerun: yes;"> </span>We need to unzip
the images.<span style="mso-spacerun: yes;"> </span>We can do this using <a href="https://itunes.apple.com/us/app/the-unarchiver/id425424353?mt=12">TheUnarchiver for Mac</a>.<o:p></o:p></div>
<div class="MsoNormal">
3.<span style="mso-spacerun: yes;"> </span>Now we need to
copy the image over to the SD card.<span style="mso-spacerun: yes;"> </span>I
would recommend using at least a 8 gig SD card.<span style="mso-spacerun: yes;">
</span>Everything needed will take up 3.3 gig which will fit on a 4 gig card
but you are not leaving yourself much extra space.<span style="mso-spacerun: yes;"> </span>I use <a href="http://ivanx.com/raspberrypi/">Pi Filler</a> to copy the image onto the SD card.<span style="mso-spacerun: yes;"> </span>Once
installed, run the Pi Filler app and follow the on screen prompts.<o:p></o:p></div>
<div class="MsoNormal">
4.<span style="mso-spacerun: yes;"> </span>Once you have the
image on the SD Card, go ahead and plug it into your BeagleBone Black and power
it up.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="MsoNormal">
5.<span style="mso-spacerun: yes;"> </span>If you are using a
SD card greater than 4 gig, you will need to manually expand the file system
since the image only uses 4 gig.<span style="mso-spacerun: yes;"> </span>To do
this you can following <a href="http://elinux.org/Beagleboard:Expanding_File_System_Partition_On_A_microSD">these instructions</a>.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="MsoNormal">
6.<span style="mso-spacerun: yes;"> </span>Now we are set to
install Swift.<span style="mso-spacerun: yes;"> </span>The instructions to do
this are on the <a href="http://dev.iachieved.it/iachievedit/debian-packages-for-swift-on-arm/">iachieved.it site</a>.<o:p></o:p></div>
<div class="MsoNormal">
7.<span style="mso-spacerun: yes;"> </span>The last thing we
need to do before we start to code is to get the SwiftyGPIO repository.<span style="mso-spacerun: yes;"> </span>You can find the <a href="https://github.com/uraimo/SwiftyGPIO">repository here</a>.<span style="mso-spacerun: yes;">
</span>Under the Sources directory you will find the file SwiftGPIO.swift
file.<span style="mso-spacerun: yes;"> </span>This is the file we will need to
use with our code.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now that our <a href="http://amzn.to/25Fggs2">BeagleBone black</a> setup, lets get ready to do some coding.<span style="mso-spacerun: yes;">
</span>We will start by writing some code that will cause our LED to blink on
and off.<span style="mso-spacerun: yes;"> </span>We will then write a separate
application to read the state of a button.<span style="mso-spacerun: yes;">
</span>Finally we will combine the code to create an application that will turn
the LED on and off with the button.<span style="mso-spacerun: yes;"> </span>So
lets get started.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<h2>
Turning an LED On and Off</h2>
<div class="MsoNormal">
The first thing we need to do is to wire everything up.<span style="mso-spacerun: yes;"> </span>When you do this wiring you will want to have
the <a href="http://amzn.to/25Fggs2">BeagleBone Black</a> powered
off.<span style="mso-spacerun: yes;"> </span>The following diagram shows how we
would wire a LED to our <a href="http://amzn.to/25Fggs2">BeagleBone Black</a>.<span style="mso-spacerun: yes;"> </span>It is recommended that whenever we connect
anything to the BeagleBone Black we should always disconnect the power.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRMU2rvfoZWEJ3VRnMFYM6KqvcXzewP46F6usd8WSgUhxkRStlOrCVS538ruj5Gy2-KbLG-XLvdcn0uImdGkX57ZUetYg1jLaNEseXCHtaH5PrqitqaQ0dsgRuoxxDSFWYbHjIXnA0enUr/s1600/led_only_bb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="301" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRMU2rvfoZWEJ3VRnMFYM6KqvcXzewP46F6usd8WSgUhxkRStlOrCVS538ruj5Gy2-KbLG-XLvdcn0uImdGkX57ZUetYg1jLaNEseXCHtaH5PrqitqaQ0dsgRuoxxDSFWYbHjIXnA0enUr/s400/led_only_bb.png" width="400" /></a></div>
<o:p></o:p><br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We run a solder-less jumper from pin 1 of the P9 expansion header
to the ground rail marked with the blue line on the breadboard and then take
another solder-less jumper from pin 2 of the P9 expansion header to the power
rail marked with the red line.<span style="mso-spacerun: yes;"> </span>We will
use these rails to provide power and ground for our LED and Button.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;">
<span style="color: #262626; mso-bidi-font-family: Arial;">Now
lets add the LED to our breadboard. Connect the cathode end of the LED
(shorter wire) to the ground rail of our breadboard and then connect the anode
end of the LED (longer wire) to one of the other rows on our breadboard.<o:p></o:p></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<span style="color: #262626; mso-bidi-font-family: Arial;">Now
take a 100 OHM resistor and connect one end to the row on the breadboard that
the LED is connected to and the other end of the resistor to another row on the
breadboard. Finally run a solder-less jumper from pin 12 of the P9
expansion header to the row that the 100 OHM resistor is connected too.<span style="mso-spacerun: yes;"> </span>We are now set to power up the BeagleBone
Black.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
You will want to create a separate directory for each Swift
project so lets begin by creating a directory named <b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">blinkyled</span></b>
and then change to that directory.<span style="mso-spacerun: yes;"> </span>You
will want to copy the <b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">SwiftyGPIO.swift</span></b>
file from the SwiftyGPIO package to this directory.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Copy the following code into a file named <b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">main.swift</span></b> also in the <b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">blinkyled</span></b> directory (the file needs to
be named main.swift).<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">import
Glibc<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">let
gpios = SwiftyGPIO.getGPIOsForBoard(.BeagleBoneBlack)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">var
led = GPIO(name:"GPIO_60", id: 60)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">led.direction
= .OUT<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">while(true){<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";"><span style="mso-tab-count: 1;"> </span>print(“Changing”)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";"><span style="mso-spacerun: yes;"> </span>led.value = (led.value == 0) ? 1 : 0<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";"><span style="mso-spacerun: yes;"> </span>usleep(150000)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">} <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
In this file we start off by importing the GLibc
module.<span style="mso-spacerun: yes;"> </span>In the next line we retrieve the
list of GPIOs available for the BeagleBone Black.<span style="mso-spacerun: yes;"> </span>Next we get a reference to GPIO_60 (pin 12 of
the P9 expansion header).<span style="mso-spacerun: yes;"> </span>You can see
the <a href="http://elinux.org/Beagleboard:Cape_Expansion_Headers">GPIO ports listed here</a>.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The next line configures the port direction for the GPIO
port.<span style="mso-spacerun: yes;"> </span>We can use <i style="mso-bidi-font-style: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">GPIODirection.IN</span></i>
or <i style="mso-bidi-font-style: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">GPIODirection.OUT</span></i> here.<span style="mso-spacerun: yes;"> </span>Now we create a while loop.<span style="mso-spacerun: yes;"> </span>Within the while loop the first line prints a
message to the console letting us know that we are changing the LED.<span style="mso-spacerun: yes;"> </span>The next line checks the value of the LED and
changes it causing the LED to blink.<span style="mso-spacerun: yes;"> </span>A
value of 1 turns the LED on and a value of 0 turns it off.<span style="mso-spacerun: yes;"> </span>We then use the <i style="mso-bidi-font-style: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">usleep</span></i>
function to pause before we loop back.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
To compile this application we use the following command:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-family: "Courier New"; font-size: 9.0pt;">swiftc –o blinkyled SwiftyGPIO.swift main.swift <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This command uses the swift compiler to compile <b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">SwiftyGPIO.swift</span></b> and <b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">main.swift</span></b> and writes the output to the
file named <b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">blinkyled</span></b>.<span style="mso-spacerun: yes;"> </span>We are now able to run our application.<span style="mso-spacerun: yes;"> </span>If you attempt to run this without super user
privileges the LED will not blink.<span style="mso-spacerun: yes;"> </span>To
access the GPIO ports you will need to run the application with sudo like this:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-family: "Courier New"; font-size: 9.0pt;">sudo ./blinkled <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-family: "Courier New"; font-size: 9.0pt;"><br /></span></div>
<div class="MsoNormal">
If everything is connected correctly, the LED should blink
on and off pretty quickly.<span style="mso-spacerun: yes;"> </span>Now lets look
at how we would check the state of a button.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<h2>
Reading the state of a button</h2>
<div class="MsoNormal">
Now that we have the LED working lets look at how we would
read the state of a button.<span style="mso-spacerun: yes;"> </span>To begin
with lets connect a button to our Beaglebone Black as shown in the following
diagram.<span style="mso-spacerun: yes;"> </span>Keep in mind that whenever we
connect anything to the BeagleBone Black we should always disconnect the power.<o:p></o:p></div>
<div class="MsoNormal">
<span style="mso-spacerun: yes;"> </span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqp32yEZ2E_UaYI_Ahm_GnU8K9aCBYpEq2OnWElb1dSMFlyz9B5YTCfsFMdfuBrBQU7wiCFHt9tDdLUiTQo-jhyCDaKV9I0g4olMBgiqSGnJ-3N52nycdfWuCXfxOBjUi8j1fU4FM5NxpL/s1600/button_only_bb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="302" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqp32yEZ2E_UaYI_Ahm_GnU8K9aCBYpEq2OnWElb1dSMFlyz9B5YTCfsFMdfuBrBQU7wiCFHt9tDdLUiTQo-jhyCDaKV9I0g4olMBgiqSGnJ-3N52nycdfWuCXfxOBjUi8j1fU4FM5NxpL/s400/button_only_bb.png" width="400" /></a></div>
<div class="MsoNormal">
<span style="mso-spacerun: yes;"><br /></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #1d1d1d; mso-bidi-font-family: Arial;">In
this diagram we add the push button to the breadboard. You will want the
button to straddle the middle section as show in the previous image.
Using a solder-less jumper, connect the power rail of your breadboard to one
end of the button. Next connect the same end of the button to the ground
rail of your breadboard using the 10K pulldown resistor. Finally connect
the other end of the button to pin 23 of the P9 expansion header. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #1d1d1d; mso-bidi-font-family: Arial;">Now
lets power up the BeagleBone Black and write our code to read the state of the
button.<span style="mso-spacerun: yes;"> </span>Create a directory named </span><b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-bidi-font-family: Arial; mso-themecolor: accent1; mso-themeshade: 191;">button</span></b><span style="color: #1d1d1d; mso-bidi-font-family: Arial;"> and copy the </span><b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-bidi-font-family: Arial; mso-themecolor: accent1; mso-themeshade: 191;">SwiftyGPIO.swift</span></b><span style="color: #1d1d1d; mso-bidi-font-family: Arial;"> file to this directory.<span style="mso-spacerun: yes;"> </span>Next create a file named </span><b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-bidi-font-family: Arial; mso-themecolor: accent1; mso-themeshade: 191;">main.swift</span></b><span style="color: #1d1d1d; mso-bidi-font-family: Arial;"> in the </span><b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-bidi-font-family: Arial; mso-themecolor: accent1; mso-themeshade: 191;">button</span></b><span style="color: #1d1d1d; mso-bidi-font-family: Arial;"> directory and add the
following code to it.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt;">import Glibc<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt;">let gpios =
SwiftyGPIO.getGPIOsForBoard(.BeagleBoneBlack)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt;">var button = GPIO(name:
"GPIO_49",id: 49)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt;">button.direction = .IN<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt;">while(true){<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt;"><span style="mso-tab-count: 1;"> </span>if
button.value == 1 {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt;"><span style="mso-tab-count: 2;"> </span>print("Pressed")<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt;"><span style="mso-tab-count: 1;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt;"><span style="mso-tab-count: 1;"> </span>usleep(10000)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt;">}</span><span style="color: #1d1d1d; font-family: "Courier New"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
In this file we start off by importing the GLibc
module.<span style="mso-spacerun: yes;"> </span>In the next line we retrieve the
list of GPIOs available for the BeagleBone Black.<span style="mso-spacerun: yes;"> </span>We then get a reference to GPIO_49 (pin 23 of
the P9 expansion header).<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The next line configures the port direction for the GPIO
port.<span style="mso-spacerun: yes;"> </span>We can use <i style="mso-bidi-font-style: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">GPIODirection.IN</span></i>
or <i style="mso-bidi-font-style: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">GPIODirection.OUT</span></i> here.<span style="mso-spacerun: yes;"> </span>Notice in the LED example we used <i style="mso-bidi-font-style: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">GPIODirection.OUT</span></i> however in this
example we used<i style="mso-bidi-font-style: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;"> GPIODirection.IN</span></i>.<span style="mso-spacerun: yes;"> </span>Next we create a while loop.<span style="mso-spacerun: yes;"> </span>Within the while loop we check the state of
the port and if it is high (value of 1) we print the message “Pressed” to the
console letting us know the button is pressed.<span style="mso-spacerun: yes;">
</span>We then use the <i style="mso-bidi-font-style: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">usleep</span></i>
function to pause before we loop back.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
To compile this application we use the following command:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-family: "Courier New"; font-size: 9.0pt;">swiftc –o button SwiftyGPIO.swift main.swift <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This command uses the swift compiler to compile <b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">SwiftyGPIO.swift</span></b> and <b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">main.swift</span></b> and writes the output to the
file named <b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-themecolor: accent1; mso-themeshade: 191;">button</span></b>.<span style="mso-spacerun: yes;"> </span>We are now able to run our application.<span style="mso-spacerun: yes;"> </span>The following command will run our
application.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-family: "Courier New"; font-size: 9.0pt;">sudo ./button <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-family: "Courier New"; font-size: 9.0pt;"><br /></span></div>
<div class="MsoNormal">
If everything is connected correctly, when you press the
button you should get a message printed to the console.<span style="mso-spacerun: yes;"> </span>Now lets put our LED and Button examples
together to turn the LED on whenever the button is pressed.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<h2>
Putting it together</h2>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The following diagram shows how we would wire the LED and
Button to our BeagleBone Black (notice no changes from the previous two
diagrams just combined them).<o:p></o:p></div>
<div class="MsoNormal">
<o:p><br /></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2MWbPP8ll3mcRu67RCuZwIAri_eNFpAeZk9aOcjd8VUS4ATgGJ5fMwLzZH7Yx0J-zgfs56l1HnfvAeFZx8VA5ExfGY8zZago2Jr8QnWcyCtsEIIwC4XsHPgHC7ax2n8g9GO2F7WOYc3GU/s1600/led_and_button_bb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="302" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2MWbPP8ll3mcRu67RCuZwIAri_eNFpAeZk9aOcjd8VUS4ATgGJ5fMwLzZH7Yx0J-zgfs56l1HnfvAeFZx8VA5ExfGY8zZago2Jr8QnWcyCtsEIIwC4XsHPgHC7ax2n8g9GO2F7WOYc3GU/s400/led_and_button_bb.png" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #1d1d1d; mso-bidi-font-family: Arial;">The
following code will go in our </span><b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-bidi-font-family: Arial; mso-themecolor: accent1; mso-themeshade: 191;">main.swift</span></b><span style="color: #1d1d1d; mso-bidi-font-family: Arial;"> file:<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">import
Glibc<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">let
gpios = SwiftyGPIO.getGPIOsForBoard(.BeagleBoneBlack)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">var
button = GPIO(name: "GPIO_49",id: 49)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">var
led = GPIO(name:"GPIO_60", id: 60)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">button.direction
= .IN<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">led.direction
= .OUT<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">while(true){<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";"><span style="mso-tab-count: 1;"> </span>if button.value == 1 {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";"><span style="mso-tab-count: 1;"> </span><span style="mso-tab-count: 1;"> </span>print("Pressed")<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";"><span style="mso-tab-count: 2;"> </span>led.value = 1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";"><span style="mso-tab-count: 1;"> </span>} else {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";"><span style="mso-tab-count: 2;"> </span>led.value = 0<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";"><span style="mso-tab-count: 1;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";"><span style="mso-tab-count: 1;"> </span>usleep(10*1000)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 28.0pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 28.0pt 56.0pt 84.0pt 112.0pt 140.0pt 168.0pt 196.0pt 224.0pt 3.5in 280.0pt 308.0pt 336.0pt; text-autospace: none;">
<span style="color: black; font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Menlo Regular";">} <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #1d1d1d; mso-bidi-font-family: Arial;">When
you compile this, don’t forget to include the </span><b style="mso-bidi-font-weight: normal;"><span style="color: #2e74b5; mso-bidi-font-family: Arial; mso-themecolor: accent1; mso-themeshade: 191;">SwiftyGPIO.swift</span></b><span style="color: #1d1d1d; mso-bidi-font-family: Arial;"> file.<span style="mso-spacerun: yes;"> </span>When you run
the application, the LED should turn on when you press the button and turn off
when you release it.<span style="mso-spacerun: yes;"> </span>The following image
shows how my wiring looks in real life<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs9Y7dWu8w4A0XYa-JWzLa1SBVLSCpQP3gvGJRl41fl4qK_o_xop56CQMLcTD_rsmT2fWiMK_RFlI5Dj0lmMlK7U2wBKBsIVDYHrRpjPMok8nQC6npyfpAg8BCdBqlUWciABZpGHm9CwZL/s1600/IMG_1003.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs9Y7dWu8w4A0XYa-JWzLa1SBVLSCpQP3gvGJRl41fl4qK_o_xop56CQMLcTD_rsmT2fWiMK_RFlI5Dj0lmMlK7U2wBKBsIVDYHrRpjPMok8nQC6npyfpAg8BCdBqlUWciABZpGHm9CwZL/s640/IMG_1003.jpg" width="480" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #1d1d1d; mso-bidi-font-family: Arial;">Notice
the sporty new BB8 case I made for my <a href="http://amzn.to/25Fggs2">BeagleBone Black</a></span><span style="color: #1d1d1d; mso-bidi-font-family: Arial;">, pretty cool huh?<span style="mso-spacerun: yes;"> </span>Not to mention that BB8 and BBB kind of go
together.<span style="mso-spacerun: yes;"> </span>Just printed it on my new 3D
printer.<span style="mso-spacerun: yes;"> </span>I will be talking about the
printer in a post very soon and will include links to some of the stuff I have
printed and designed including the BB8 case. <span style="mso-spacerun: yes;"> </span>I am thinking about making a R2D2 case for my
other <a href="http://amzn.to/25Fggs2">BeagleBone Black</a></span>.<span style="color: #1d1d1d; mso-bidi-font-family: Arial;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #1d1d1d; mso-bidi-font-family: Arial;">If
you are new to Swift, I will be discussing some of the basics while I am
showing how to use Swift with the <a href="http://amzn.to/25Fggs2">BeagleBone black</a></span><span style="color: #1d1d1d; mso-bidi-font-family: Arial;"> however my assumption is you
will have at least a basic understanding of Swift.<span style="mso-spacerun: yes;"> </span>I will also be writing more blog posts that
are specific to Swift on Linux on my Swift programming blog however if you are
really interested in the language I would recommend my <a href="http://amzn.to/1N4vVpm">Mastering Swift 2</a></span><span style="color: #1d1d1d; mso-bidi-font-family: Arial;"> and <a href="http://amzn.to/25FsG34">Protocol Oriented Programming with Swift</a></span><span style="color: #1d1d1d; mso-bidi-font-family: Arial;"> books.<span style="mso-spacerun: yes;"> </span>Please keep in mind that those books talk
about using Swift on the Mac however most of the language concepts themselves
are the same whether you are using Swift on a Mac or with Linux.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #1d1d1d; mso-bidi-font-family: Arial;">Now
that my books are done, you should start seeing a lot more posts on both my
robotic and swift blogs.<span style="mso-spacerun: yes;"> </span>I do have a
question for anyone that might be able to answer: Does anyone know when/if we
will see an update for the BeagleBone Black?<span style="mso-spacerun: yes;">
</span>I am not talking about the X15 that looks like it is going to be pretty
expensive.<span style="mso-spacerun: yes;"> </span>I am looking more for an
update to the BeagleBone black that will have roughly the same price point.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves>false</w:TrackMoves>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNormal">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com1tag:blogger.com,1999:blog-1266480015345788892.post-76725691583393078472016-03-20T09:45:00.001-07:002016-03-20T09:45:55.557-07:00Generic Programming and POP with Swift – The Law of Useful Return<div class="MsoNormal">
In my first post on Generic Programming I talked about the
iterative approach to improving algorithms.
In this post I would like to discuss another concept from the <span style="color: #548dd4; mso-themecolor: text2; mso-themetint: 153;"><a href="http://amzn.to/1XD6ReO">From Mathematics to Generic Programming</a> </span>book that I am
currently reading. This concept is called <b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;">The Law of Useful Return</i></b>.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The Law of Useful Return says:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<i style="mso-bidi-font-style: normal;">If
you have already done the work to get some useful result, don’t throw it
away.<span style="mso-spacerun: yes;"> </span>Return it to the caller because
they may be able to use it.<o:p></o:p></i></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
What do we mean by this law.
Well the easy way to explain it is to look at an example. In the <span style="color: #548dd4; mso-themecolor: text2; mso-themetint: 153;"><a href="http://amzn.to/1XD6ReO">From Mathematics to Generic Programming</a> </span>book,
they explain this law based on a mathematical equation however, most developers
that I know do not get that excited about complex mathematical equations
therefore I am going to take a non-mathematical approach to explaining this.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Lets say that we were creating a pump that is connected to
the Internet for real time monitoring (think IoT).<span style="mso-spacerun: yes;"> </span>This pump could be used to pump different
types of liquids and would be able to return the temperature of the liquid as
it is being pumped.<span style="mso-spacerun: yes;"> </span>In our application,
that monitors the pump, we could then retrieve the temperature and send out an
alert if it is outside of the acceptable range for the particular liquid that
is being pumped.<span style="mso-spacerun: yes;"> </span>Our function to monitor
the temperature may look something like this:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">
isTemperatureWithinRange() -> </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #007400; font-family: "Menlo Regular"; font-size: 9.0pt;">//Get liquid temperature<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> temp = getLiquidTemp()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #007400; font-family: "Menlo Regular"; font-size: 9.0pt;">//Check if temp is within acceptable
range<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">if</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> temp < MIN_TEMP || tem >
MAX_TEMP {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This function would work well and if the temperature was outside
the acceptable range it would return false triggering an alert.<span style="mso-spacerun: yes;"> </span>The problem that could arise from this is
eventually we will want to display the actual temperature of the liquid being
pumped, therefore someone may add another function that would simply retrieve
the temperature of the liquid and return it.<span style="mso-spacerun: yes;">
</span>This function may look something like this:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> getTemperature()
-> </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">Double</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #007400; font-family: "Menlo Regular"; font-size: 9.0pt;">//Get liquid temperature<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> getLiquidTemp()<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: #007400; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now in order to retrieve the temperature of the liquid and
to also check if it is within the acceptable range we would need to call the <b style="mso-bidi-font-weight: normal;">getLiquidTemp()</b> function twice.<span style="mso-spacerun: yes;"> </span>Since this function retrieves the temperature
from a remote device, making two separate calls like this is definitely not
optimal.<span style="mso-spacerun: yes;"> </span>What we could have done to
avoid this problem was to return the temperature with the Boolean value that
indicates if the temperature was within the acceptable range.<span style="mso-spacerun: yes;"> </span>It would be very easy to do since we are
already retrieving the temperature as part of the check.<span style="mso-spacerun: yes;"> </span>The function that returns both values could look
something like this:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> getTemperature()
-> (acceptable:</span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">, temperature: </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">Double</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #007400; font-family: "Menlo Regular"; font-size: 9.0pt;">//Get liquid temperature<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> temp = getLiquidTemp()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #007400; font-family: "Menlo Regular"; font-size: 9.0pt;">//Check if temp is within acceptable
range<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">if</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> temp < MIN_TEMP || tem >
MAX_TEMP {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> (acceptable:</span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">, temperature:
temp)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> (acceptable:</span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">, temperature:
temp)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Be careful not to follow this law to closely because we only
want to return data that is useful within our application.<span style="mso-spacerun: yes;"> </span>When we create functions like this we really
need to ask ourselves not only what information do we currently need but also
what information may be useful.<span style="mso-spacerun: yes;"> </span>In our
example above, returning the temperature, since we already retrieved it, could
definitely prove useful even if it is not needed with our current requirements.<span style="mso-spacerun: yes;"> </span>Writing our API correctly (generically) the
first time will save us from having to change the interface for our APIs in the
future.<span style="mso-spacerun: yes;"> </span>This means a lot less
refactoring of our code.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
To me, one of the ideas behind the Law of Useful Return is
to avoid making our APIs so granular that we end up performing the same
functions multiple times.<span style="mso-spacerun: yes;"> </span>To illustrate
this idea another way lets look at a second example.<span style="mso-spacerun: yes;"> </span>Lets say that we have a NSDate object and we
need to retrieve the month from it.<span style="mso-spacerun: yes;"> </span>We
could very easily design our API like this:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> getMonth(date:
</span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">NSDate</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">) -> </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> components = </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">NSCalendar</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">.</span><span style="color: #2e0d6e; font-family: "Menlo Regular"; font-size: 9.0pt;">currentCalendar</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">().</span><span style="color: #2e0d6e; font-family: "Menlo Regular"; font-size: 9.0pt;">components</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">(.Month,
fromDate: date)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> components.</span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">month</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This works great for our present need however what happens if
in the future we also need to retrieve the day of the month.<span style="mso-spacerun: yes;"> </span>We could write a second function to retrieve
the day of the month however we would then need to make two function calls if
we needed both the day of the month and month itself.<span style="mso-spacerun: yes;"> </span>A better way to design our API is to think
ahead and realize that if we are retrieving the month from the NSDate object maybe
the day of the month and year would be useful.<span style="mso-spacerun: yes;">
</span>We would then create a function that returns the month, day and year
like this:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> getDate(date: </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">NSDate</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">) -> (month:
</span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">, day: </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">, year: </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> components = </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">NSCalendar</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">.</span><span style="color: #2e0d6e; font-family: "Menlo Regular"; font-size: 9.0pt;">currentCalendar</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">().</span><span style="color: #2e0d6e; font-family: "Menlo Regular"; font-size: 9.0pt;">components</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">([</span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">NSCalendarUnit</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">.Month, </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">NSCalendarUnit</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">.Day, </span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">NSCalendarUnit</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">.Year],
fromDate: date)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "Menlo Regular"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;"> (month: components.</span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">month</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">, day:
components.</span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">day</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">, year: components.</span><span style="color: #5c2699; font-family: "Menlo Regular"; font-size: 9.0pt;">year</span><span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt;">
<span style="color: black; font-family: "Menlo Regular"; font-size: 9.0pt;">}</span><span style="font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
By designing our API to return the month, day and year
rather than just the month our function becomes much more generic and useful
not just for our present needs but also for our future needs.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
When we create APIs that only meet our present requirements
we end up having to do a lot of extra code refactoring in the future when we
have to change those API to meet our future needs.<span style="mso-spacerun: yes;"> </span>When we are designing our APIs we should always
remember to think beyond our present needs and think about how we can make our
APIs generic enough to also meet our future needs. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
There are going to (hopefully) be
a number of posts in the Generic Programming and POP with Swift series
therefore I made a separate post that contains links to all of the articles in
this series.<span style="mso-spacerun: yes;"> </span>The post is located
here:<span style="mso-spacerun: yes;"> </span><u style="text-underline: #420178;"><span style="color: #420178; mso-bidi-font-family: Times;"><a href="http://masteringswift.blogspot.com/2016/03/generic-programming-and-protocol.html">http://masteringswift.blogspot.com/2016/03/generic-programming-and-protocol.html</a></span></u><o:p></o:p></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNormal">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-22273256627307349672016-03-19T18:55:00.000-07:002016-03-19T18:57:43.607-07:00Generic Programming and POP with Swift – Iterative approach to Algorithms<div class="MsoNormal" style="tab-stops: 242.0pt;">
After I released my <a href="http://amzn.to/1XD6ReO">Protocol OrientedProgramming with Swift book</a>, I had an e-mail
conversation with Dave Abrahams about what exactly is protocol oriented
programming.<span style="mso-spacerun: yes;"> </span>If you are not familiar
with who Dave Abrahams is, take a look at this <a href="https://developer.apple.com/videos/play/wwdc2015/408/">video from the 2015 WWDC</a>. <span style="mso-spacerun: yes;"> </span>When the conversation started I did
not realize the person I was talking to was the person that introduced Protocol
Oriented Programming to the world even though I probably watched the video at
least fifteen times while I was writing my book.<span style="mso-spacerun: yes;"> </span>It is a very good presentation and a must see
for anyone interested in Protocol Oriented Programming.<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
One of the things that Dave
recommended to me was to focus on Generic Programming.<span style="mso-spacerun: yes;"> </span>Well in my mind I knew what generic
programming was.<span style="mso-spacerun: yes;"> </span>It was about using
Generics, right?<span style="mso-spacerun: yes;"> </span>Wrong.<span style="mso-spacerun: yes;"> </span>I could tell that Dave was getting frustrated
with me and he ended up recommending that I check out the <span style="color: #548dd4; mso-themecolor: text2; mso-themetint: 153;"><a href="http://amzn.to/22jXML0">From Mathematicsto Generic Programming</a></span> book.<span style="mso-spacerun: yes;"> </span>I was very interested in what Dave was trying
to explain so I started reading the book.<span style="mso-spacerun: yes;">
</span><o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
I will say that the book is very
interesting and I have enjoyed reading it so far.<span style="mso-spacerun: yes;"> </span>I have not finished it yet but I did want to start
sharing some of my initial thoughts.<span style="mso-spacerun: yes;">
</span>First off, as the title would indicate, the book is not for those
intimidated by mathematics.<span style="mso-spacerun: yes;"> </span>I graduated
from college and have not taken a course on mathematics since before my
favorite young baseball player, <a href="http://www.baseball-reference.com/players/b/bettsmo01.shtml">Mookie Betts</a>, <span style="mso-spacerun: yes;"> </span>was born (I’m showing my age here) so I really
had to shake some of those math cobwebs out of my head but it is worth it. <span style="mso-spacerun: yes;"> </span>If you are intimidated by mathematics, you
can read a more general overview here:<span style="mso-spacerun: yes;"> </span><a href="http://www.generic-programming.org/">generic-programming.org</a>.<span style="mso-spacerun: yes;"> </span>The
author Douglas Gregor has not updated the site since 2013 but it does appear to
have some good information from what I have seen so far.<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
I do not want to spend the time
writing a review of the book, instead, over the next few posts, I want to
discuss some of the ideas behind Generic programming as I understand them.<span style="mso-spacerun: yes;"> </span>I am learning what generic programming is as
I write these posts so please leave comments with suggestions or any
corrections if I get something wrong.<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
This book does start off by
covering a lot of basic concepts that all advanced developers show know but
sometimes we forget or ignore during our day to day work especially with the
deadlines that we are always on.<span style="mso-spacerun: yes;">
</span>Sometimes we need to be reminded of these concepts to make sure we are
creating the best applications that we can.<span style="mso-spacerun: yes;">
</span>This post will cover one of these concepts.<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
The second chapter of this book
looks at the iterative approach to programming where we should be constantly
improving our code.<span style="mso-spacerun: yes;"> </span>At the end of the
chapter the authors says that “<span style="color: #cc0000;">No one writes good code the first time' it takes many
iterations to find the most efficient or general way to do something. No programmer should have a single pass
mindset.</span>”<span style="mso-spacerun: yes;"> </span>While most experience programmers
realize this, a lot of times we are pressured with deadlines to just get the
coding done.<span style="mso-spacerun: yes;"> </span>This creates a lot of
technical debt for our company and we should really take the time to make sure
we find the most efficient way to do something.<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
To illustrate this iterative
approach the authors’ shows how the algorithm for multiplication improved over
time starting with how the ancient Egyptians did multiplication.<span style="mso-spacerun: yes;"> </span>To me, an example that is presented in
chapter 7 also does an excellent job showing this concept.<span style="mso-spacerun: yes;"> </span>This example also demonstrates the concept
that <span style="color: #548dd4; mso-themecolor: text2; mso-themetint: 153;">it is
sometimes better to do more work rather than less</span>.<span style="mso-spacerun: yes;"> </span>The example that I am talking about shows how
we would compute the n<sub>th</sub> Fibonacci number.<span style="mso-spacerun: yes;"> </span>Since this blog is about programming in
Swift, I would like to walk through this iterative process with examples in
Swift.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
The Fibonacci sequence is a series
of numbers:<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
55, 89….<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
Where each number in the sequence
is the sum of the previous two numbers in the sequence.<span style="mso-spacerun: yes;"> </span>For example, 2+3 = 5 therefore 5 is the next
number in the sequence after 3.<span style="mso-spacerun: yes;"> </span>Also 3+5
= 8 therefore 8 is the next number in the sequence after 5.<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
Any entry-level developer could
easily write a function to calculate the n<sub>th</sub> Fibonacci number using
recursion like this:<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "menlo regular"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">
fibonacciRecursive(num: </span><span style="color: #5c2699; font-family: "menlo regular"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">) -> </span><span style="color: #5c2699; font-family: "menlo regular"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 9.0pt;">if</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"> num == </span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 9.0pt;">0</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"> </span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 9.0pt;">0</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 9.0pt;">if</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"> num == </span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 9.0pt;">1</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"> </span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 9.0pt;">1</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "menlo regular"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"> </span><span style="color: #26474b; font-family: "menlo regular"; font-size: 9.0pt;">fibonacciRecursive</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">(num - </span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 9.0pt;">1</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">) + </span><span style="color: #26474b; font-family: "menlo regular"; font-size: 9.0pt;">fibonacciRecursive</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">(num - </span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 9.0pt;">2</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 26.45pt; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">}</span><span style="font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
This seems to work very well and
we could call the function like this:<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: #26474b; font-family: "menlo regular"; font-size: 9.0pt;">fibonacciRecursive</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">(</span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 9.0pt;">5</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
Everything is good, right?<span style="mso-spacerun: yes;"> </span>Wrong.<span style="mso-spacerun: yes;">
</span>Lets try to make this call:<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: #26474b; font-family: "menlo regular"; font-size: 9.0pt;">let start =
NSDate()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: #26474b; font-family: "menlo regular"; font-size: 9.0pt;">fibonacciRecursive</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">(</span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 9.0pt;">20</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">let end =
NSDate()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">let
timeInterval: Double = end.timeIntervalSinceDate(start)<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<span style="color: black; mso-bidi-font-family: "Menlo Regular";">On my MacBook Pro this call takes almost 4
seconds.<span style="mso-spacerun: yes;"> </span>This would indicate that we might
have a problem.<span style="mso-spacerun: yes;"> </span>Let's see what happens with
this call:<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: #26474b; font-family: "menlo regular"; font-size: 9.0pt;">let start =
NSDate()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: #26474b; font-family: "menlo regular"; font-size: 9.0pt;">fibonacciRecursive</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">(</span><span style="color: #1c00cf; font-family: "menlo regular"; font-size: 9.0pt;">30</span><span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">let end =
NSDate()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">let
timeInterval: Double = end.timeIntervalSinceDate(start)<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<span style="color: black; mso-bidi-font-family: "Menlo Regular";">This takes 492 seconds WOW.<span style="mso-spacerun: yes;"> </span>If you try to find the 33<sup>rd</sup> Fibonacci
number you might as well take a quick nap because it took 2295 seconds on my
MacBook Pro.<span style="mso-spacerun: yes;"> </span>Yes I would say that we
have a problem here. To solve this problem we need to figure out why we have
it.<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<span style="color: black; mso-bidi-font-family: "Menlo Regular";">The best way to figure out what is wrong with an
algorithm like this is to manually walk though it.<span style="mso-spacerun: yes;"> </span>Let's go ahead and do this as if we were
figuring out the 5<sup>th</sup> Fibonacci number. The fifth Fibonacci number
would be the sum of the forth and third Fibonacci numbers and we would write
the formula like this:<span style="mso-spacerun: yes;"> </span>F5 = F4+F3.<span style="mso-spacerun: yes;"> </span>With this format we would figure out the
fifth Fibonacci number like this<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<span style="color: black; font-family: Courier New, Courier, monospace; font-size: xx-small; mso-bidi-font-family: "Menlo Regular";"> F5 =
(F4) <span style="mso-spacerun: yes;"> </span>+ (F3)<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<span style="color: black; font-family: Courier New, Courier, monospace; font-size: xx-small; mso-bidi-font-family: "Menlo Regular";"><span style="mso-spacerun: yes;"> </span>= (F3 + F2) <span style="mso-spacerun: yes;"> </span>+ (F2 + F1)<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<span style="color: black; font-family: Courier New, Courier, monospace; font-size: xx-small; mso-bidi-font-family: "Menlo Regular";"><span style="mso-spacerun: yes;"> </span>= ((F2 + F1) + (F1 + F0)) <span style="mso-spacerun: yes;"> </span>+ ((F1 + F0) + F1)<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<span style="color: black; font-size: 10.0pt;"><span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span style="mso-spacerun: yes;"> </span>= (((F1 + F0) + F1) + ( F1 + F0)) + ((F1 +
F0) + F1)</span><span style="font-family: 'courier std'; font-size: x-small;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<span style="color: black; mso-bidi-font-family: "Menlo Regular";">As we can see, just to calculate the fifth
Fibonacci number this code performs seven additions and also calculates F1 + F0
three times.<span style="mso-spacerun: yes;"> </span>So how can we eliminate this
duplicated work?<span style="mso-spacerun: yes;"> </span>One way we could do
this is to do our calculations going up the chain, rather than down and to pass
the Fibonacci pair into the function.<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">func
fibonacciRecursive2(count: Int, fPair: (Int, Int) = (0,1)) -> Int {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let newCount = count - 1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>if newCount == 0 { return fPair.1 }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>let newFPair = (fPair.1, fPair.0 +
fPair.1)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>return fibonacciRecursive2(newCount,
fPair: newFPair)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="color: black; font-family: "menlo regular"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
This new function allows us to
calculate the fifth Fibonacci number with five additions.<span style="mso-spacerun: yes;"> </span>While there may not be that noticeable of a
time distance when we are calculating the lower Fibonacci numbers once we get to
the higher ones (like 30) there are some drastic time differences.<span style="mso-spacerun: yes;"> </span>I am talking about the difference between 492
seconds and 0.0223 seconds.<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
Is this the best algorithm for us
to calculate a Fibonacci number?<span style="mso-spacerun: yes;"> </span>Probably
not.<span style="mso-spacerun: yes;"> </span>It does take a certain amount of
time to call functions therefore using a recursive function does add additional
time.<span style="mso-spacerun: yes;"> </span>Let's see how we would take the recursion
out but still keep the logic.<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="font-family: "menlo regular"; font-size: 9.0pt;">func
fibonacciIterative(num: Int) -> Int {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>if num == 0 { return 0 }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>var values = (0,1)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>for _ in 1..<num {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>values = (values.1, values.0 +
values.1)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="font-family: "menlo regular"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>return values.1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; tab-stops: 242.0pt;">
<span style="font-family: "menlo regular"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
Now I think we have a great
algorithm to compute a Fibonacci number.<span style="mso-spacerun: yes;">
</span>To calculate the 70<sup>th</sup> Fibonacci number with the <b style="mso-bidi-font-weight: normal;">fibonacciRecursive2()</b> function it takes
0.0472 seconds.<span style="mso-spacerun: yes;"> </span>With the <b style="mso-bidi-font-weight: normal;">fibonacciIterative()</b> function it takes
0.0235 seconds.<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
This example showed how we could
improve an algorithm by taking an iterative approach where we improved the
algorithm’s perform each time we rewrote the function.<span style="mso-spacerun: yes;"> </span>On thing to keep in mind is the iterative
approach can be used not only with mathematical algorithms as we just showed but
also in our day-to-day development.<span style="mso-spacerun: yes;"> </span>We
should always be thinking about how we can improve our code to not only make it
faster but also safer and more generic (we will be discussing this a lot more in
future posts).<span style="mso-spacerun: yes;"> </span>This post also showed
that by doing more work in the function itself, rather than using a recursive
function we ended up creating an algorithm that is faster and more efficent.<span style="mso-spacerun: yes;"> </span>Another bonus is it really shows off how
valuable Tuples can be when used correctly.<o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
Over the next few posts I will
write more about what I am reading.<span style="mso-spacerun: yes;"> </span>Some
of the posts will be like this one where we are reminded about some basic
concepts like taking an iterative approach to our code while others will be
about the concepts of Generic Programming.<span style="mso-spacerun: yes;">
</span><o:p></o:p></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
I made a separate post that
contains links to all of the articles in this series.<span style="mso-spacerun: yes;"> </span>The post is located here:<span style="mso-spacerun: yes;"> </span><o:p></o:p><a href="http://masteringswift.blogspot.com/2016/03/generic-programming-and-protocol.html">http://masteringswift.blogspot.com/2016/03/generic-programming-and-protocol.html</a></div>
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNormal" style="tab-stops: 242.0pt;">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-42672134997754484642016-03-19T18:51:00.000-07:002016-04-14T17:34:52.361-07:00Generic Programming and Protocol Oriented Programming with SwiftThere will (hopefully) be a number of posts in the Generic Programming and Protocol Oriented Programming with Swift series. This page will list the post with links to them.<br />
<br />
<span style="font-family: inherit; font-size: medium;">1. <span style="font-size: 12pt;"><a href="http://masteringswift.blogspot.com/2016/03/generic-programming-and-pop-with-swift.html">Iterative approach to Algorithms</a></span></span><br />
<span style="font-family: "times" , "times new roman" , serif;">
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--></span><br />
<div class="MsoNormal">
<span style="font-family: inherit;"><span style="font-size: 11pt;">In this post we will look </span><span style="font-size: 11pt;">at the iterative
approach to programming where we should be constantly looking to improve our
code. Keep in mind that no one writes good code the first time' it takes
many iterations to find the most efficient or general way to do
something. No programmer should have a single pass mindset.</span></span></div>
<div class="MsoNormal">
<span style="font-size: 11pt;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 11pt;"><br /></span></div>
<span style="font-family: inherit; font-size: medium;">2. <a href="http://masteringswift.blogspot.com/2016/03/generic-programming-and-pop-with-swift_20.html">The Law of Useful Return</a></span><br />
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;">
<span style="color: #1a1a1a; font-size: 11.0pt;"><span style="font-family: inherit;">In this post I would like to look at the <b><i>The Law of Useful
Return</i></b>.<span style="mso-spacerun: yes;"> </span>The Law of Useful Return
says:<span style="mso-spacerun: yes;"> </span><i>If you have already done the
work to get some useful result, don’t throw it away. Return it to the
caller because they may be able to use it.</i></span><o:p></o:p></span><br />
<br /></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;">
<span style="color: #1a1a1a; font-size: 11.0pt;"><i><br /></i></span></div>
<div class="MsoNormal" style="mso-layout-grid-align: none; mso-pagination: none; text-autospace: none;">
<span style="color: #1a1a1a; font-size: 11.0pt;"><i><br /></i></span></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment--><!--EndFragment-->Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com1tag:blogger.com,1999:blog-1266480015345788892.post-7592429947878854112016-02-28T08:34:00.001-08:002016-02-28T10:35:26.971-08:00My Protocol Oriented Programming with Swift book has been released<div class="MsoNormal">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijr_q-yww4qY1wEMawZjEN4PhpAngDo1klo2zNNWP-UtcLGj6bW-jY3pwa60dn6Ip8hyphenhyphenCuLTvZRZM64tFwnqVLBmcFjdIGFs8JzQxLzxK3UVOIy7DtqNLw7EXyJtOnuDhyphenhyphenVpWnSo1Fo7FJ/s1600/POPcover.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijr_q-yww4qY1wEMawZjEN4PhpAngDo1klo2zNNWP-UtcLGj6bW-jY3pwa60dn6Ip8hyphenhyphenCuLTvZRZM64tFwnqVLBmcFjdIGFs8JzQxLzxK3UVOIy7DtqNLw7EXyJtOnuDhyphenhyphenVpWnSo1Fo7FJ/s200/POPcover.jpg" width="161" /></a></div>
My forth book titled Protocol Oriented Programming has been
released.<span style="mso-spacerun: yes;"> </span>You can buy a copy of the book
on <a href="http://www.amazon.com/gp/product/1785882945/ref=as_li_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1785882945&linkCode=as2&tag=myadveinrobo-20&linkId=NOKN4LDQNLFDRAT6">Amazon</a> or from <a href="https://www.packtpub.com/application-development/protocol-oriented-programming-swift">Packt’s</a> site.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This book is about protocol-oriented programming. When Apple
announced Swift 2 at the World Wide Developers Conference (WWDC) in 2015, they
also declared that Swift was the world's first protocol-oriented programming
language. By its name, we may assume that protocol-oriented programming is all
about the protocol; however, that would be a wrong assumption. Protocol-oriented
programming is about so much more than just the protocol; it is actually a new
way of not only writing applications, but also thinking about the design of our
application.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
One of the biggest misconceptions about protocol-oriented
programming is that it is just another name for object-oriented programming. <i><span style="color: #b45f06;"><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter
1</span></span>, <span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Object-Oriented
and Protocol-Oriented Programming</span></span> </span></i>of this book immediately takes
on this myth by comparing protocol-oriented programming to object-oriented
programming to see what is similar and what the differences are. We will also
discuss the advantages and disadvantages of both the programming paradigms.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
From <i><span style="color: #b45f06;"><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter 2</span></span>, <span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Our Type Choices</span></span></span></i> to <i><span style="color: #b45f06;"><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter
5</span></span>, <span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Let's Extend
Some Types</span></span></span></i>, we will take an in-depth look at each of the
components that make up the protocol-oriented programming paradigm. These
chapters are designed to give the reader a solid understanding of the different
components of protocol-oriented programming, so users will understand how they
can use tthem in their applications.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The last two chapters are written to help the reader
understand how they can design their application in a protocol-oriented
programming way. <span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;"><i><span style="color: #b45f06;">C</span></i><span style="color: #b45f06;">hapter 6</span></span></span><span style="color: #b45f06;">, <span class="ItalicsPACKT"><span style="font-family: "cambria";">Adopting Design Patterns in Swift</span></span></span>
looks at how we would implement several design patterns in a protocol-oriented
way and <span style="color: #b45f06;"><i><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter 7</span></span>, <span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Case Studies</span></span></i></span> looks at three
real-world case studies to reinforce everything previously discussed in the
book.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<h3>
What this book covers by chapter:</h3>
<o:p></o:p><br />
<div class="MsoNormal">
<i><span style="color: #b45f06;"><o:p> </o:p><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter 1</span></span>,<span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> Object-Oriented and Protocol-Oriented
Programming</span></span></span></i>, will show the differences between object-oriented
programming and protocol-oriented programming, giving the reader a good
understanding of the different paradigms. By the end of the chapter, the reader
should have a basic understanding of protocol-oriented programming and what it
offers.</div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<i><span style="color: #b45f06;"><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter 2</span></span>,<span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> Our Type Choices</span></span></span></i>, will look at
the different types that Swift offers (Structs, Classes, Enums, and Tuples). We
will show several examples on when to use the various types and when not to.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<i><span style="color: #b45f06;"><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter 3</span></span>,<span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> Catching Our Errors</span></span></span></i>, will look
at the various ways we can catch and report errors. This chapter will not only
cover the new Swift 2 do-try-catch blocks, but also the older error handling patterns.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #b45f06;"><i><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter 4</span></span>, <span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">All about the Protocol</span></span></i></span>, will be
all about the protocol. We will show the advantages of using protocols and why,
in our design, we should start with the protocol.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<i><span style="color: #b45f06;"><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter 5</span></span>,<span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;"> Let's Extend Some Types</span></span></span></i>, will
cover extensions in great detail. We will look at how to extend standard Swift
types, such as structures and classes. We will also look at protocol extensions
and discuss why they are so important in protocol-oriented programming.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<i><span style="color: #b45f06;"><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter 6</span></span>, <span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Adopting Design Patterns in Swift</span></span></span></i>,
will be implementing several design patterns using protocol-oriented
programming. For each of the design patterns, we will look at the problem they
are designed to solve and how to implement the pattern.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #b45f06;"><i><span class="ChapterrefPACKT"><span style="font-family: "cambria"; mso-ansi-font-size: 12.0pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-font-size: 12.0pt; mso-bidi-theme-font: minor-bidi; mso-hansi-theme-font: minor-latin;">Chapter 7</span></span>, <span class="ItalicsPACKT"><span style="font-family: "cambria"; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Case Studies</span></span></i></span>, will explore
three case studies. This chapter is designed to pull everything from the first
six chapters together to show the reader how to use protocol-oriented
programming with design patterns in real-world situations.<o:p></o:p><br />
<br />
You can read about <a href="http://masteringswift.blogspot.com/2016/02/pop-and-oop.html">Protocol Oriented Programming in my last blog post</a>.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
If you are interested in using the new protocol oriented
programming paradigm in your next project or if you are curious about what it
is, I hope you will consider picking up my new book. <o:p></o:p>You can pick up your copy from <a href="http://www.amazon.com/gp/product/1785882945/ref=as_li_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1785882945&linkCode=as2&tag=myadveinrobo-20&linkId=NOKN4LDQNLFDRAT6">Amazon</a> or from <a href="https://www.packtpub.com/application-development/protocol-oriented-programming-swift">Packt’s</a> site.<span style="mso-spacerun: yes;"> </span></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="MsoNormal">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com0tag:blogger.com,1999:blog-1266480015345788892.post-27506413738713389432016-02-14T15:20:00.000-08:002016-02-14T15:43:43.459-08:00POP and OOP<div class="NormalPACKT">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf14Eim5ahDa1TvOu0CyJYGu68Uzcit1fkFXSULDLg5sIT_kylcv_WjtRIpVFSWZWNPXIm1Q94OUDgYkxJzWm-dIA0zP6GfPCPoZSiJagqXLZvtmbrQFbiYsIr-q3qd5O7UdGeqFl-95lp/s1600/POPcover.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf14Eim5ahDa1TvOu0CyJYGu68Uzcit1fkFXSULDLg5sIT_kylcv_WjtRIpVFSWZWNPXIm1Q94OUDgYkxJzWm-dIA0zP6GfPCPoZSiJagqXLZvtmbrQFbiYsIr-q3qd5O7UdGeqFl-95lp/s200/POPcover.jpg" width="161" /></a></div>
With my new book titled <a href="http://www.amazon.com/gp/product/1785882945/ref=as_li_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1785882945&linkCode=as2&tag=myadveinrobo-20&linkId=I6YPJWFGPVSJEW2J">Protocol-Oriented programming Programming with Swift</a> being
released in the next few days I thought that I would write a post comparing
protocol-oriented programming to object-oriented programming to highlight the differences.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Numerous tutorials that I have seen take a very Object-Oriented
approach to the protocol-oriented programming (POP) paradigm.<span style="mso-spacerun: yes;"> </span>By this statement I mean that they tell us
that with POP we should begin our design with the protocol rather than with the
superclass as we did with OOP however the protocol design tends to mirror the
superclass design of OOP.<span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>They also tell us that we should use extensions
to add common functionality to types that conform to a protocol as we did with superclasses in OOP.<span style="mso-spacerun: yes;"> </span>While protocols and protocol extensions are
arguably two of the most important concepts of POP these tutorials seem to be
missing some other very important concepts.<span style="mso-spacerun: yes;">
</span>In my new book, <a href="http://www.amazon.com/gp/product/1785882945/ref=as_li_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1785882945&linkCode=as2&tag=myadveinrobo-20&linkId=I6YPJWFGPVSJEW2J">Protocol-Oriented programming with Swift,</a> I cover POP in
depth to show the reader how they can use POP, and it’s related technologies,
to reduce the complexity of their code base and to create applications that are
easy to maintain and update.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
In this post I would like to compare Protocol-Oriented design
to Object-Oriented design to highlight some of the conceptual differences.<span style="mso-spacerun: yes;"> </span>To do this we will look at how we would
define animals types for a video game in both an Object-Oriented approach and also a
Protocol-Oriented approach to see the advantages of both.<span style="mso-spacerun: yes;"> </span>Lets start off by defining the requirements
for our animals.<o:p></o:p></div>
<h1>
<span lang="EN-GB">Requirements<o:p></o:p></span></h1>
<div class="NormalPACKT">
Here are the requirements for our animals:<o:p></o:p></div>
<div class="NormalPACKT">
<span style="mso-bidi-font-weight: bold;">-</span><span style="mso-spacerun: yes;"> </span>We will have three categories of animals:
sea, land and air<o:p></o:p></div>
<div class="NormalPACKT">
-<span style="mso-spacerun: yes;"> </span>Animals may be a
member of multiple categories.<span style="mso-spacerun: yes;"> </span>For
example an alligator can be a member of both the land and sea category.<o:p></o:p></div>
<div class="NormalPACKT">
-<span style="mso-spacerun: yes;"> </span>Animals may be
able to attack and/or move when they are on a tile that matches the categories
they are in.<o:p></o:p></div>
<div class="NormalPACKT">
- Animals will start off with a certain amount of hit
points and if those hit points reach 0 or less then they will die.<o:p></o:p></div>
<div class="NormalPACKT">
- For our example here we will define two animals (Lion
and Alligator) but we know the number of animal types will grow as we develop
the game<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Lets start off by looking at how we would design this with
the Object-Oriented approach.<o:p></o:p></div>
<h1>
<span lang="EN-GB">Object-Oriented Design<o:p></o:p></span></h1>
<div class="NormalPACKT">
Before we start writing code, lets create a class diagram
that shows our design.<span style="mso-spacerun: yes;"> </span>I usually start
off by doing a very basic diagram that simply shows the classes themselves
without much detail.<span style="mso-spacerun: yes;"> </span>This helps me
picture the class hierarchy in my mind.<span style="mso-spacerun: yes;"> </span>The
following diagram shows the class hierarchy for our Object-Oriented design:<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRmOJavl_fg1UUxbjax7IvKULEQZGr7vVe2mNZGKJlLKyCc0RXadVzKpr3XT_ogHCfxUji4hohA7JdmRPoD_ieZ3Yx0cbUuT4zhN39l5YrXAXSLfmHMVP2CKKjizgFhJXekYNQJVXxTIIO/s1600/oopDiagram.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="247" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRmOJavl_fg1UUxbjax7IvKULEQZGr7vVe2mNZGKJlLKyCc0RXadVzKpr3XT_ogHCfxUji4hohA7JdmRPoD_ieZ3Yx0cbUuT4zhN39l5YrXAXSLfmHMVP2CKKjizgFhJXekYNQJVXxTIIO/s400/oopDiagram.png" width="400" /></a></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span style="mso-no-proof: yes;"><v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape alt="Description: Macintosh HD:Users:hoffmanjon:Dropbox:Blog Posts:Swift Blog Posts:ComparePOP2OOP:oopDiagram.png" id="Picture_x0020_1" o:spid="_x0000_i1026" style="height: 157pt; mso-wrap-style: square; visibility: visible; width: 252pt;" type="#_x0000_t75">
<v:imagedata o:title="oopDiagram.png" src="file://localhost/Users/hoffmanjon/Library/Caches/TemporaryItems/msoclip/0clip_image001.png">
</v:imagedata></v:shape></span><o:p></o:p></div>
<div class="NormalPACKT">
This diagram shows that we have one superclass named <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i> and two subclasses named <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Alligator</span></i> and <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Lion</span></i>.<span style="mso-spacerun: yes;"> </span>We may think that, with the three categories,
we would need to create a larger class hierarchy where the middle layer would
contain the classes for the Land, Air and Sea animals however that is not
possible with our requirements.<span style="mso-spacerun: yes;"> </span>The
reason this is not possible is because animal types can be members of multiple
categories and with a class hierarchy each class can have only one super
class.<span style="mso-spacerun: yes;"> </span>This means that our <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i> super class will need to contain
the code required for each of the three categories.<span style="mso-spacerun: yes;"> </span>Lets take a look at the code for the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i> super class.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">class</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> Animal {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #007400; font-family: "courier new"; font-size: 9.0pt;">/* Need to be var so override init() */<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #007400; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>/* in animal class can set them<span style="mso-spacerun: yes;"> </span>*/<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #007400; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>/* Animal types need to be in
the same physical */<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #007400; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>/* file to access private
properties */</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">private</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> landAnimal = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">private</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> landAttack = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">private</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> landMovement = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">private</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> seaAnimal = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">private</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> seaAttack = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">private</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> seaMovement = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">private</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> airAnimal = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">private</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> airAttack = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">private</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> airMovement = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">private</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> hitPoints = </span><span style="color: #1c00cf; font-family: "courier new"; font-size: 9.0pt;">0</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">init</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">() {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landAttack</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landMovement</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">airAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">airAttack</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">airMovement</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">seaAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">seaAttack</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">seaMovement</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">hitPoints</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #1c00cf; font-family: "courier new"; font-size: 9.0pt;">0</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> isLandAnimal() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> canLandAttack() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landAttack</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> canLandMove() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landMovement</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> isSeaAnimal() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">seaAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> canSeaAttack() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">seaAttack</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> canSeaMove() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">seaMovement</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> isAirAnimal() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">airAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> canAirAttack() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">airAttack</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> canAirMove() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">airMovement</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandAttack() {}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandMovement() {}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doSeaAttack() {}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doSeaMovement() {}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doAirAttack() {}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doAirMovement() {}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> takeHit(amount: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) { </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">hitPoints</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> -= amount }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> hitPointsRemaining() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">hitPoints</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> isAlive() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">hitPoints</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> > </span><span style="color: #1c00cf; font-family: "courier new"; font-size: 9.0pt;">0</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> ? </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> : </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><br /></span></div>
<div class="NormalPACKT">
This class starts off with nine Boolean properties that
define the category (land, sea or air) of the animal and if the animal can
attack/move on the land, sea or air.<span style="mso-spacerun: yes;"> </span>We
defined these as private variables because we need to set them in the subclass
however we do not want external entities to change them.<span style="mso-spacerun: yes;"> </span>The preference is for these to be constants
however a subclass can not set/change the value of a constant defined in a
superclass.<span style="mso-spacerun: yes;"> </span>In order for this to work
the subclass needs to be defined in the same physical file as the
superclass.<span style="mso-spacerun: yes;"> </span>You can see <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html">Apple’s page toread about access controls with Swift</a>.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
We define the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">hitPoints</span></i>
property similar to how we defined the other properties so only the subclasses will
have access to them.<span style="mso-spacerun: yes;"> </span>We then define a
default initiator that is used to ensure that all of the properties are set to
their default values.<span style="mso-spacerun: yes;"> </span>Finally we define
eighteen functions that are used to access the properties, move the animal,
attack or other functionality needed for our animals.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
We can now create the Alligator and Lion classes that are
subclasses of the Animal class.<span style="mso-spacerun: yes;"> </span>The code
for these classes is shown next.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">class</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> Lion: </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Animal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">override</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">init</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">() {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">super</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">.</span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">init</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landAttack</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landMovement</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">hitPoints</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #1c00cf; font-family: "courier new"; font-size: 9.0pt;">20</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">override</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandAttack() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Lion Attack"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">override</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandMovement() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Lion Move"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">class</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> Alligator: </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Animal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">override</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">init</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">() {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">super</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">.</span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">init</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landAttack</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">landMovement</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">seaAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">seaAttack</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">seaMovement</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">hitPoints</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> = </span><span style="color: #1c00cf; font-family: "courier new"; font-size: 9.0pt;">35</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">override</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandAttack() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Alligator Land Attack"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">override</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandMovement() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Alligator Land Move"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">override</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doSeaAttack() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Alligator Sea Attack"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">override</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doSeaMovement() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Alligator Sea Move"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="NormalPACKT">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}</span><span style="font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
As we can see in these classes we override the
functionality needed for each animal.<span style="mso-spacerun: yes;">
</span>The <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Lion</span></i> class contains the
functionality for a land animal and the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Alligator</span></i>
class contains the functionality for both a land and sea animal.<span style="mso-spacerun: yes;"> </span>Since both class have the same <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i> superclass we can use
polymorphism to access them through the interface provided by the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i> superclass.<span style="mso-spacerun: yes;"> </span>Lets see how we would do this.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> animals = [</span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Animal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">]()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> an1 = </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Alligator</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> an2 = </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Alligator</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> an3 = </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Lion</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">animals</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">.</span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">append</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">an1</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">animals</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">.</span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">append</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">an2</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">animals</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">.</span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">append</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">an3</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">for</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> (index, animal) </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">in</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">animals</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">.</span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">enumerate</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">() {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">if</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> animal.</span><span style="color: #26474b; font-family: "courier new"; font-size: 9.0pt;">isAirAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">() {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Animal
at </span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">\</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">index</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">) is Air"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">if</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> animal.</span><span style="color: #26474b; font-family: "courier new"; font-size: 9.0pt;">isLandAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">() {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Animal
at </span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">\</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">index</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">) is Land"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">if</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> animal.</span><span style="color: #26474b; font-family: "courier new"; font-size: 9.0pt;">isSeaAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">() {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Animal
at </span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">\</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">index</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">) is Sea"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
How we designed the animal types here would definitely
work but there are several drawbacks to this design.<span style="mso-spacerun: yes;"> </span>The first drawback is the large monolithic <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i> superclass.<span style="mso-spacerun: yes;"> </span>For those that are familiar with designed
characters for video games you probably realize how much functionality is actually
missing form the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i> superclass and
it’s subclasses.<span style="mso-spacerun: yes;"> </span>This is on purpose so
we can focus on the design and not all of the functionality.<span style="mso-spacerun: yes;"> </span>For those who are not familiar with designed
characters for video games, trust me when I say that this class will get much bigger when we add all of the functionality needed.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Another drawback is not being able to define constants in
the superclass that the subclasses can set.<span style="mso-spacerun: yes;">
</span>We could define an initiator in the superclass that would set all of the
constants however the initiator would become pretty complex and that is
something we would like to avoid.<span style="mso-spacerun: yes;"> </span>The
builder pattern could help us with the initiation but as we are about to see, a
protocol-oriented design would be even better. <o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
One final drawback that I am going to point out is the use
of flags (<i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">landAnimal</span></i>, <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">seaAnimal</span></i> and <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">airAnimal</span></i>
properties) to define the type of animal.<span style="mso-spacerun: yes;">
</span>If we accidently set these flags wrong then the animal will not behave
correctly.<span style="mso-spacerun: yes;"> </span>As an example, if we set the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">seaAnimal</span></i> flag rather than the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">landAnimal</span></i> flag in the Lion class then
the lion would not be able to move or attack on land.<span style="mso-spacerun: yes;"> </span>Trust me it is very easy even for the most
experience developer to set flags like these wrong.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Now lets look at how we would define this same
functionality in a Protocol-Oriented way.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<h1>
<span lang="EN-GB">Protocol-Oriented Design</span> </h1>
<div class="NormalPACKT">
Just like with the Object-Oriented design, we will want to
start off with a type diagram that shows the types needed to create and the
relationships between them.<span style="mso-spacerun: yes;"> </span>The
following diagram shows our Protocol-Oriented design.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWV6izf4CFOx2zGYFpXO18G75iswQr0T1D2vLBTJbsHk62X4IFq4qkvonunME32b4eX-HT8Nc7fdqB3GmD0Z303oGHn3keSdL8T3XqL3gPyW2Hfi3aWtIsyV1u6wR3tqjb5LkblKDmRrE1/s1600/popDiagram.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="416" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWV6izf4CFOx2zGYFpXO18G75iswQr0T1D2vLBTJbsHk62X4IFq4qkvonunME32b4eX-HT8Nc7fdqB3GmD0Z303oGHn3keSdL8T3XqL3gPyW2Hfi3aWtIsyV1u6wR3tqjb5LkblKDmRrE1/s640/popDiagram.png" width="640" /></a></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span style="mso-no-proof: yes;"><v:shape alt="Description: Macintosh HD:Users:hoffmanjon:Dropbox:Blog Posts:Swift Blog Posts:ComparePOP2OOP:popDiagram.png" id="Picture_x0020_4" o:spid="_x0000_i1025" style="height: 259pt; mso-wrap-style: square; visibility: visible; width: 396pt;" type="#_x0000_t75">
<v:imagedata o:title="popDiagram.png" src="file://localhost/Users/hoffmanjon/Library/Caches/TemporaryItems/msoclip/0clip_image002.png">
</v:imagedata></v:shape></span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
As we can see our POP design is different
from our OOP design.<span style="mso-spacerun: yes;"> </span>In this design we
use three techniques that make POP significantly different from OOP.<span style="mso-spacerun: yes;"> </span>These techniques are protocol inheritance, protocol
composition and protocol extensions.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Protocol inheritance is where one protocol can inherit the
requirements from one or more other protocols.<span style="mso-spacerun: yes;">
</span>In our example the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">LandAnimal</span></i>,
<i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">SeaAnimal</span></i> and <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">AirAnimal</span></i> protocols will inherit the requirements of the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i>
protocol.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Protocol composition allows types to conform to more than
one protocol.<span style="mso-spacerun: yes;"> </span>This is one of the many advantages
that POP has of OOP.<span style="mso-spacerun: yes;"> </span>With OOP a class
can have only one superclass which can lead to very monolithic superclasses as
we just saw.<span style="mso-spacerun: yes;"> </span>With POP we are encouraged
to create multiple smaller protocols with very specific requirements.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Protocol extensions are arguably one of the most important
parts of the protocol-oriented programming paradigm.<span style="mso-spacerun: yes;"> </span>They allow us to add functionality to all
types that conform to a given protocol.<span style="mso-spacerun: yes;">
</span>Without protocol extensions if we had common functionality that was
needed for all types, that conformed to a particular protocol, then we would of
had to add that functionality to each type.<span style="mso-spacerun: yes;">
</span>This would lead to large amounts of duplicate code and that would not be
ideal to say the least. <o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Lets look at how this design works.<span style="mso-spacerun: yes;"> </span>We will start off by defining our <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i> protocol.<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">protocol</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> Animal {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> hitPoints: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {</span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">get</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">set</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="NormalPACKT">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
In the Animal protocol, the only item that we are defining
is the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">hitPoints</span></i> property.<span style="mso-spacerun: yes;"> </span>This protocol would also contain any additional
items that are common to all animals. To be consistent with our OOP design, we only need to add the <i><span style="color: #365f91;">hitPoints</span></i> property to this protocol. </div>
<div class="NormalPACKT">
<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Next we need to add a protocol extension so we can add the
functionality that will be common for all types that conform to the
protocol.<span style="mso-spacerun: yes;"> </span>Our <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i>
protocol extension would contain the following code:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">extension</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Animal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">mutating</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> takeHit(amount: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) { </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">hitPoints</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> -= amount }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> hitPointsRemaining() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Int</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">hitPoints</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> isAlive() -> </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> { </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">return</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">hitPoints</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> > </span><span style="color: #1c00cf; font-family: "courier new"; font-size: 9.0pt;">0</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> ? </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> : </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">false</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> }<o:p></o:p></span></div>
<div class="NormalPACKT">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}</span><span style="font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i>
protocol extension contains the same <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">takeHit()</span></i>,
<i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">hitPointsRemaining()</span></i> and <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">isAlive()</span></i> functions that we saw in
the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animals</span></i> superclass from
the OOP example.<span style="mso-spacerun: yes;"> </span>Any type that conforms
to the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i> protocol will
automatically receive these three functions. <o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Now lets define our <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">LandAnimal</span></i>,
<i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">SeaAnimal</span></i> and <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">AirAnimal</span></i>
protocols.<span style="mso-spacerun: yes;"> </span>These protocols will define
the requirements for the land, sea and air animals respectively.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">protocol</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> LandAnimal: </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Animal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> landAttack: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {</span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">get</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> landMovement: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {</span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">get</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandAttack()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandMovement()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">protocol</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> SeaAnimal: </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Animal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> seaAttack: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {</span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">get</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> seaMovement: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {</span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">get</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doSeaAttack()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doSeaMovement()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">protocol</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> AirAnimal: </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Animal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> airAttack: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {</span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">get</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> airMovement: </span><span style="color: #5c2699; font-family: "courier new"; font-size: 9.0pt;">Bool</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {</span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">get</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doAirAttack()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doAirMovement()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Unlike the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i>
superclass in the OOP example, these three protocols only contain the
functionality needed for their particular type of animal.<span style="mso-spacerun: yes;"> </span>Each of these protocols only contains four
lines of code while the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i>
superclass, as we saw, contains significantly more.<span style="mso-spacerun: yes;">
</span>This makes our protocol design much easier to read and manage.<span style="mso-spacerun: yes;"> </span>The protocol design is also much safer
because the functionality for the various animal types is isolated in their own
protocol rather than being embedded in a giant superclass.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Now lets look at how we would create our Lion and
Alligator types using the protocol-oriented design.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">struct</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> Lion: </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">LandAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> hitPoints = </span><span style="color: #1c00cf; font-family: "courier new"; font-size: 9.0pt;">20</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> landAttack = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> landMovement = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandAttack() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Lion
Attack"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandMovement() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Lion
Move"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">struct</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> Alligator: </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">LandAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">, </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">SeaAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> hitPoints = </span><span style="color: #1c00cf; font-family: "courier new"; font-size: 9.0pt;">35</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> landAttack = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> landMovement = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> seaAttack = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> seaMovement = </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">true</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandAttack() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Alligator
Land Attack"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doLandMovement() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Alligator
Land Move"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doSeaAttack() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Alligator
Sea Attack"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">func</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> doSeaMovement() { </span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Alligator
Sea Move"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">) }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Notice that we specify that the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Lion</span></i>
type conforms to the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">LandAnimal</span></i>
protocol while the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Alligator</span></i>
type conforms to both the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">LandAnimal</span></i>
and <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">SeaAnimal</span></i> protocols.<span style="mso-spacerun: yes;"> </span>Having a single type that conforms to
multiple protocols is called protocol composition and is what allows us to use smaller protocols rather than one giant monolithic superclass as in
the OOP example.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Both the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Lion</span></i>
and <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Alligator</span></i> types originate
from the Animal protocol thereforel we can still use polymorphism as we did in
the OOP example where we use the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i>
type to store instances of the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Lion</span></i>
and <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Alligator</span></i> types.<span style="mso-spacerun: yes;"> </span>Lets see how this works:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> animals = [</span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Animal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">]()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> an1 = </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Alligator</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> an2 = </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Alligator</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">var</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> an3 = </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">Lion</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">animals</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">.</span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">append</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">an1</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">animals</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">.</span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">append</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">an2</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">animals</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">.</span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">append</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">an3</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">for</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> (index, animal) </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">in</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">animals</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">.</span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">enumerate</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">() {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">if</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> animal = animal </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">as</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">? </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">AirAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Animal
at </span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">\</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">index</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">) is Air"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">if</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> animal = animal </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">as</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">? </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">LandAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Animal
at </span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">\</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">index</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">) is Land"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">if</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">let</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> animal = animal </span><span style="color: #aa0d91; font-family: "courier new"; font-size: 9.0pt;">as</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">? </span><span style="color: #3f6e74; font-family: "courier new"; font-size: 9.0pt;">SeaAnimal</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #2e0d6e; font-family: "courier new"; font-size: 9.0pt;">print</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">"Animal
at </span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">\</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">(</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">index</span><span style="color: #c41a16; font-family: "courier new"; font-size: 9.0pt;">) is Sea"</span><span style="color: black; font-family: "courier new"; font-size: 9.0pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin: 0in; mso-layout-grid-align: none; mso-pagination: none; tab-stops: 26.45pt; text-autospace: none;">
<span style="color: black; font-family: "courier new"; font-size: 9.0pt;">}<o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
In this example we create an array that will contain <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Animal</span></i> types names <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">animals</span></i>.<span style="mso-spacerun: yes;"> </span>We then create two instances of the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Alligator</span></i> type and one instance of the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Lion</span></i> type and add all three instances to
the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">animals</span></i> array. Finally we
use a for-in loop to loop through the array and print out the animal type based
on the protocol that the instance conform too.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<h1>
<span lang="EN-GB">Conclusion</span> </h1>
<div class="NormalPACKT">
As we were reading through this post and seeing some of
the advantages that protocol-oriented programming has over object-oriented
programming, we may think that protocol-oriented programming is clearly
superior to object-oriented programming. However, this assumption may not be
totally correct.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Object-oriented programming has been around since the
1970s and is a tried and true programming paradigm. Protocol-oriented
programming is the new kid on the block and was designed to correct some of the
issues with object-oriented programming. I have personally used the
protocol-oriented programming paradigm in a couple of projects and I am very
excited about its possibilities.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Object-oriented programming and protocol-oriented
programming have similar philosophies like creating custom types that model
real-world objects and polymorphism to use a single interface to interact with
multiple types. The difference is how these philosophies are implemented.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
To me, the code base in a project that uses
protocol-oriented programming is much safer and easier to read and maintain as
compared to a project that uses object-oriented programming. This does not mean
that I am going to stop using object-oriented programming all together. I can
still see plenty of need for class hierarchy and inheritance.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Remember, when we are designing our application, we should
always use the right tool for the right job. We would not want to use a chain
saw to cut a piece of 2 x 4 lumber, but we also would not want to use a skilsaw
to cut down a tree. Therefore, the winner is the programmer where we have the
choice of using different programming paradigms rather than being limited to
only one.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<h1>
<span lang="EN-GB">Protocol-Oriented Programming with Swift<o:p></o:p></span></h1>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
I only scratched the surface of protocol-oriented
programming in this post.<span style="mso-spacerun: yes;"> </span>There is a lot
more that is covered in my new book titled <a href="http://www.amazon.com/gp/product/1785882945/ref=as_li_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1785882945&linkCode=as2&tag=myadveinrobo-20&linkId=I6YPJWFGPVSJEW2J">Protocol-Oriented Programming withSwift</a>.<span style="mso-spacerun: yes;"> </span>If you would like to learn more
about protocol-oriented programming you can order my book from <a href="http://www.amazon.com/gp/product/1785882945/ref=as_li_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1785882945&linkCode=as2&tag=myadveinrobo-20&linkId=I6YPJWFGPVSJEW2J">Amazon</a> and
<a href="https://www.packtpub.com/web-development/protocol-oriented-programming-swift">Packt’s</a> website.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<br /></div>
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:RelyOnVML/>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves>false</w:TrackMoves>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="0" Name="footer"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="NormalPACKT">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com5tag:blogger.com,1999:blog-1266480015345788892.post-16649306642847956992016-02-02T13:41:00.003-08:002016-02-02T13:41:51.810-08:00Swift for Linux part 2 – Using C libraries with Swift<div class="NormalPACKT">
Swift developers coming from Apple’s iOS and OS X
environments are use to using the Cocoa and Cocoa Touch frameworks however
these frameworks are not available in the Linux environment.<span style="mso-spacerun: yes;"> </span>When we develop Linux applications and
utilities with Swift we need to use the system libraries provided by the Linux
environment.<span style="mso-spacerun: yes;"> </span>In this post will look at
how we can use these system libraries with our Swift code to build useful
applications and utilities.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<span style="mso-spacerun: yes;"><br /></span></div>
<div class="NormalPACKT">
In this post we will look at the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i>
module that Apple provides for us which includes the majority of the Linux
Standard Library.<span style="mso-spacerun: yes;"> </span>We will also look at
how we could create our own modules to add additional system libraries not
included in the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i> module.<span style="mso-spacerun: yes;"> </span>To demonstrate the concepts discussed we will
conclude this post by building a simple command line utility that will list the
IP addresses of the device that it is run on.<o:p></o:p></div>
<h1>
<span lang="EN-GB">Modules<o:p></o:p></span></h1>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
A module in Swift is code that is distributed as a single
unit that can then be imported into other modules using Swift’s <b style="mso-bidi-font-weight: normal;">import</b> keyword.<span style="mso-spacerun: yes;"> </span>Frameworks and applications are examples of
modules in Swift. In this post we are going to be looking at a special kind of
module that can be used to map system libraries so we can import and use them into
our Swift code.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The Linux port of Swift comes with a predefined module
named <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i> that contains most
of the Linux standard library however there are numerous headers that have not
been imported in it.<span style="mso-spacerun: yes;"> </span>This module is
similar to the Darwin module on Apple platforms.<span style="mso-spacerun: yes;"> </span>Lets start off by looking at tthe <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i> module and then we will look at
defining our own modules to map other system libraries that we may need.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
To see what headers are defined in the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i> module view the <b style="mso-bidi-font-weight: normal;">module.map</b> file located in the <b style="mso-bidi-font-weight: normal;">usr/lib/swift/glibc</b> directory of your
Swift installation.<span style="mso-spacerun: yes;"> </span>Don’t worry if you
do not fully understand the format of this file at this time, we will be
looking at how to create <b style="mso-bidi-font-weight: normal;">module.map</b>
files later on in this post.<span style="mso-spacerun: yes;"> </span>For right
now, knowing that any header that is defined in this file will be included
simply by importing the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i>
module is enough.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
In my previous post, <a href="http://masteringswift.blogspot.com/2016/01/swift-for-linux-part-1-building.html">Swift for Linux part 1</a>,
we saw an example of how to use the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i>
module.<span style="mso-spacerun: yes;"> </span>In that example we created an
extension to the Array type that would randomly select an element from the
array.<span style="mso-spacerun: yes;"> </span>We used the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">random()</span></i>
function provided by the system to generate the random number in the extension.<span style="mso-spacerun: yes;"> </span>Lets take a look at the code for this example
again so we can see how it worked.<span style="mso-spacerun: yes;"> </span>The
following code shows the Array extension:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">import</span> Foundation<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">import</span> Glibc<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">extension</span> <span style="color: #5c2699;">Array</span> {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span><span style="color: #aa0d91;">func</span> getRandomElement() -> <span style="color: #5c2699;">Element</span> {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 2;"> </span><span style="color: #aa0d91;">let</span> index = Int(random() % <span style="color: #aa0d91;">self</span>.count)<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 2;"> </span><span style="color: #aa0d91;">return</span> <span style="color: #aa0d91;">self</span>[index]<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span>}<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace;"><span style="font-size: x-small;">}</span><span style="mso-spacerun: yes;"> </span></span><o:p></o:p></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace;"><span style="mso-spacerun: yes;"><br /></span></span></div>
<div class="NormalPACKT">
In this example the code starts off with two <b style="mso-bidi-font-weight: normal;">import</b> statements.<span style="mso-spacerun: yes;"> </span>The first <b style="mso-bidi-font-weight: normal;">import</b> statement imports the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Foundation</span></i>
framework.<span style="mso-spacerun: yes;"> </span>The <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Foundation</span></i>
framework defines the basic functionality that is needed for most
applications.<span style="mso-spacerun: yes;"> </span>Most if not all of your Swift
source files will need to import the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Foundation</span></i>
framework. <o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The second <b style="mso-bidi-font-weight: normal;">import</b>
statement imports the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i>
framework.<span style="mso-spacerun: yes;"> </span>This import statement allows
us to use the system libraries that are defined in the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i>
framework.<span style="mso-spacerun: yes;"> </span>If we tried to build the code
without importing the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i>
framework we would receive the following error. <o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
<span style="font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Courier New";">/xxx/xxx/xxx/xxx/MakeFtpFile/Sources/ArrayExtension.swift:6:19:
error: use of unresolved identifier 'random'<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="NormalPACKT">
<span style="font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Courier New";">let index = Int(random() % self.count)<o:p></o:p></span></div>
<div class="NormalPACKT">
<span style="font-family: "Courier New"; font-size: 9.0pt; mso-bidi-font-family: "Courier New";"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>^~~~~~ <o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
What this error tells us is the compiler does not know
anything about the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">random()</span></i>
function.<span style="mso-spacerun: yes;"> </span>If we look at the man page for
the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">random()</span></i> function
(command: <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">man random</span></i>) we see that
we need to import the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">stdlib.h</span></i>
header if we want to use this function.<span style="mso-spacerun: yes;">
</span>If we look at the headers that are imported in the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i>
framework we will see that the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i>
framework does include the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">stdlib.h</span></i>
header.<span style="mso-spacerun: yes;"> </span>By importing the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i> Framework we are essentially
importing all of the header files defined within it therefore we are importing
the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">stdlib.h</span></i> header which
defines the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">random()</span></i> function.<span style="mso-spacerun: yes;"> </span>This will allows us to use the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">random()</span></i> function within our code.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
If you are new to developing applications and utilities in
the Linux environment you will want to get use to using the Linux man pages to
retrieve information about the system libraries and the functionality they
provide.<span style="mso-spacerun: yes;"> </span>These man pages will give you a
wealth of knowledge about the functions that you are using.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Earlier we mentioned that the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i>
framework contains most of the Linux standard library so what do we do if we
want include libraries that are not in the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i>
framework?<span style="mso-spacerun: yes;"> </span>These libraries could be part
of the Linux standard library that are not currently defined in the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Glibc</span></i> framework or libraries that are
not part of the Linux standard library itself.<span style="mso-spacerun: yes;">
</span>Lets look at how to include these libraries and also how to use the
functionality they provide in our code by creating a custom module.<o:p></o:p></div>
<h1>
<span lang="EN-GB">Creating a custom module<o:p></o:p></span></h1>
<div class="NormalPACKT">
To create a custom module we will begin by creating a directory
to put the files for the module in.<span style="mso-spacerun: yes;"> </span>This
will be the module’s main directory.<span style="mso-spacerun: yes;">
</span>Within this directory we will need two files.<span style="mso-spacerun: yes;"> </span>The first is an empty file named <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Package.swift</span></i> and the second is named <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">module.modulemap</span></i>.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Within the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">module.modulemap</span></i>
file we will define the headers we want to import and the libraries that
contain the functionality defined in the headers.<span style="mso-spacerun: yes;"> </span>The example below shows the format of the
module.modulemap file <o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">module CMyModule [system] {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>header
"/usr/include/mylibheader.h"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>link
"mylib"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>export *<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The first line defines the name for our module.<span style="mso-spacerun: yes;"> </span>This name is what we will import in our Swift
files.<span style="mso-spacerun: yes;"> </span>In this sample the module’s name
is <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">CMyModule</span></i>.<span style="mso-spacerun: yes;"> </span>The next line defines the full path to the
header file that we want to import.<span style="mso-spacerun: yes;"> </span>The
third line tells the compiler that the functionality defined in the header can
be found in the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">mylib</span></i> library so we will
need to link it.<span style="mso-spacerun: yes;"> </span>The last line says to
export all of the functionality. <o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The Swift package manager uses git and git tags to manage
packages and modules therefore once we create both files we will want to create
a git repository for our module.<span style="mso-spacerun: yes;"> </span>To do
this we run the following commands in the main directory for the module.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span class="KeyWordPACKT"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git init<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span class="KeyWordPACKT"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git add .<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span class="KeyWordPACKT"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git commit -m "Initial Import"<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span class="KeyWordPACKT"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git tag 0.1.0</span><o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Before we show how to use a module, lets go ahead and
create the module needed for our example.<o:p></o:p></div>
<h1>
<span lang="EN-GB">Creating the Cifaddrs module<o:p></o:p></span></h1>
<div class="NormalPACKT">
In this post we will be creating a utility that will list
the network addresses of the device it is running on.<span style="mso-spacerun: yes;"> </span>For this utility we will use the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">getifaddrs()</span></i> function.<span style="mso-spacerun: yes;"> </span>The man page for the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">getiffaddrs()</span></i>
function shows that we will need to import <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">sys/types.h</span></i>
and <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">ifaddrs.h</span></i> header
files.<span style="mso-spacerun: yes;"> </span>In addition to these two headers
we will also need to import the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">netdb.h</span></i>,
<i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">sys/socket.h</span></i> and <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">arpa/inet.h</span></i>
headers for other functions that we will be using in our code. <span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Since some of the headers that we need for our project are
not defined in the Glibc framework we will create our own module so we can
import them.<span style="mso-spacerun: yes;"> </span>Lets begin by creating a
directory name <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Cifaddrs</span></i> and the two
files that we need:<o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">mkdir<span style="mso-spacerun: yes;"> </span>Cifaddrs<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">cd Cifaddrs<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">touch Package.swift<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">touch module.modulemap</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Now we will need to define the five headers in the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">module.modulemap</span></i> file.<span style="mso-spacerun: yes;"> </span>To do this we would put the following code
into <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">module.modulemap</span></i> file.<o:p></o:p></div>
<div class="CodePACKT">
<span style="color: #aa0d91;"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">module</span> Cifaddrs [system]
{<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">module</span> types {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">header</span> <span style="color: #c41a16;">"/usr/include/x86_64-linux-gnu/sys/types.h"</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">export</span> *<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>} <o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">module</span> ifaddrs {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">header</span> <span style="color: #c41a16;">"/usr/include/ifaddrs.h"</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">export</span> *<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>} <o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">module</span> Socket {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">header</span> <span style="color: #c41a16;">"/usr/include/x86_64-linux-gnu/sys/socket.h"</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">export</span> *<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">module</span> inet {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">header</span> <span style="color: #c41a16;">"/usr/include/arpa/inet.h"</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">export</span> *<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">module</span> netdb {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">header</span> <span style="color: #c41a16;">"/usr/include/netdb.h"</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">export</span> *<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Now we need to create our git repository by running the
following commands in the module’s main directory.<o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span class="KeyWordPACKT"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git init<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span class="KeyWordPACKT"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git add .<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span class="KeyWordPACKT"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git commit -m "Initial
Import"<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span class="KeyWordPACKT"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git tag 0.1.0</span><o:p></o:p></span></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Since the swift package manager uses the tag for
versioning, you will want to update the tag whenever you update code.<span style="mso-spacerun: yes;"> </span>To make it easier to create the initial
structure for the module, I created a shell scripted named <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">createmodule.sh</span></i>.<span style="mso-spacerun: yes;"> </span>This script is very similar to the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">createproject.sh</span></i> that I created in my
last post to create the structure for a project.<span style="mso-spacerun: yes;"> </span>The following is the code for the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">createmodule.sh</span></i> script.<o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#!/bin/bash<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#title:<span style="mso-spacerun: yes;">
</span>createmodule.sh<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#author:<span style="mso-spacerun: yes;"> </span>Jon
Hoffman<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#description:<span style="mso-spacerun: yes;"> </span>Creates
the directories and files need for a Swift module<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#date:<span style="mso-spacerun: yes;"> </span>012816<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#version:<span style="mso-spacerun: yes;"> </span>1.0<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#usage:<span style="mso-spacerun: yes;">
</span>createmodule.sh {module name} {optional: dir name}<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">MODULENAME=""<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">DIRNAME=""<span style="mso-tab-count: 1;"> </span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">PACKAGEFILENAME="Package.swift"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">MODULEFILENAME="module.modulemap"<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Check to make sure at least one command<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#line arg is present otherwise exit script<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if [ $# -le 0 ]; then<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>echo "Usage:
creatproject {Name for Module} {Optional directory name}"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>exit 1<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">fi<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Assign the value of the first command line arg to the
module name<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#if a second command line arg is present assign that value
to the<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#the directory name otheerwise use the module name<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">MODULENAME=$1<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if [ "$1" != "" ]; then<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>DIRNAME=$1<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">else<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;">
</span>DIRNAME=$MODULENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">fi<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Check to see if the directory exists and if so display an
error<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#and exit<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if [ -d "$DIRNAME" ]; then<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>echo
"Directory already exists, please choose another name"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>exit 1<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">fi<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Make the directory structue and create the neccessary files<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">mkdir -p $DIRNAME<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">cd $DIRNAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">touch $PACKAGEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">touch $MODULEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo "module $MODULENAME [system] {" >>
$MODULEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo "" >> $MODULEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo "}" >> $MODULEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git init<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git add .<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git commit -m "Initial Import"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">git tag 0.0.1</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The <b style="mso-bidi-font-weight: normal;">createmodule.sh</b>
script takes one required and one optional command line argument.<span style="mso-spacerun: yes;"> </span>The first (required) command line argument is
the name of the module and is used to create the <b style="mso-bidi-font-weight: normal;">module.modulemap</b> file.<span style="mso-spacerun: yes;"> </span>The
second (optional) command line argument is the name for the module
directory.<span style="mso-spacerun: yes;"> </span>If the second command line
argument is not present then we use the name of the module (first command line
argument) for the directory name.<span style="mso-spacerun: yes;"> </span>The
following examples show how we would use the <b style="mso-bidi-font-weight: normal;">createmodule.sh</b> script to create a module named <b style="mso-bidi-font-weight: normal;">Clib</b> in a directory named <b style="mso-bidi-font-weight: normal;">Clib</b>.<o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">./createmodule.sh Clib </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The previous command would create a directory named <span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">Clib</span></span>.<span style="mso-spacerun: yes;"> </span>It would also create the <b style="mso-bidi-font-weight: normal;">Package.swift</b> and <b style="mso-bidi-font-weight: normal;">module.modulemap</b>
files.<span style="mso-spacerun: yes;"> </span>The following code shows what the
newly created <b style="mso-bidi-font-weight: normal;">module.modulemap</b> file
would look like. <o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import PackageDescription<span style="mso-spacerun: yes;">
</span><o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">module</span> Clib [system] {<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
We used the module name (first command line argument) to
define the module name in this <b style="mso-bidi-font-weight: normal;">module.modulemap</b>
file.<span style="mso-spacerun: yes;"> </span>You can find the code for the
<i>createmodule.sh</i> file on my <a href="https://github.com/hoffmanjon/Linux-Swift-Scripts">Scripts for Swift Linux development github<span class="URLPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;"> </span></span>page</a>.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Now that we have created our module, lets see how to use
it in a project.<o:p></o:p></div>
<h1>
<span lang="EN-GB">Using the Cifaddrs module<o:p></o:p></span></h1>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Now that we have our module created, lets look at how we
would use it in a project.<span style="mso-spacerun: yes;"> </span>The first
thing we will want to do is to create the project.<span style="mso-spacerun: yes;"> </span>For this I will use my <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">createproject.sh</span></i>
script like this:<o:p></o:p></div>
<div class="CodePACKT">
./createproject.sh getifaddrs<o:p></o:p></div>
<div class="NormalPACKT">
This will create the directory structure and files needed
to start the project with. <span style="mso-spacerun: yes;"> </span>To tell the
compiler to use our newly created module we will need to add a dependency to
the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">Package.swift</span></i> file.<span style="mso-spacerun: yes;"> </span>We would add this dependency as shown with
the following code:<o:p></o:p></div>
<div class="CodePACKT">
<span style="color: #aa0d91;">import</span> PackageDescription<o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">let</span> package = Package(<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>name:<span style="mso-spacerun: yes;"> </span><span style="color: #c41a16;">"getifaddrs"</span>,<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>dependencies:
[.Package(url: <span style="color: #c41a16;">"../Cifaddrs"</span>,
majorVersion: <span style="color: #1c00cf;">0</span>, minor: <span style="color: #1c00cf;">1</span>)]<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">)</span><o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
The <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">url</span></i>
defines the path to the module.<span style="mso-spacerun: yes;"> </span>This can
be the full file system path as shown in our example or an Internet path to a
github repository.<span style="mso-spacerun: yes;"> </span>We can also define
multiple dependencies by separating the packages by a comma as shown here:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">l</span><span style="color: #aa0d91;">et</span> package = Package(</span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>name:<span style="mso-spacerun: yes;"> </span><span style="color: #c41a16;">"getifaddrs"</span>,<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>dependencies:
[.Package(url: <span style="color: #c41a16;">"../modOne"</span>,
majorVersion: <span style="color: #1c00cf;">0</span>, minor: <span style="color: #1c00cf;">1</span>),<o:p></o:p></span></div>
<div class="CodePACKT" style="text-indent: .25in;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>dependencies: [.Package(url: <span style="color: #c41a16;">"../modTwo"</span>, majorVersion: <span style="color: #1c00cf;">0</span>, minor: <span style="color: #1c00cf;">1</span>)]<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">)</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
We are now ready to use the libraries defined in the
module within our application.<span style="mso-spacerun: yes;"> </span>The
following code shows the main.swift file that will retrieve the list of IP
addresses and print them out.<o:p></o:p></div>
<div class="CodePACKT">
<span style="color: #aa0d91;"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">import</span> Foundation<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">import</span> Cifaddrs<o:p></o:p></span></div>
<div class="CodePACKT" style="margin-left: 0in;">
<br /></div>
<div class="CodePACKT">
<span style="color: #007400;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">// Get list of all interfaces <o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">var</span> ifaddr : <span style="color: #5c2699;">UnsafeMutablePointer</span><<span style="color: #5c2699;">ifaddrs</span>>
= <span style="color: #aa0d91;">nil</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">if</span>
getifaddrs(&ifaddr) == <span style="color: #1c00cf;">0</span> {<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #007400;">// Loop through all interfaces<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">var</span> ptr = ifaddr<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">while</span> (ptr != <span style="color: #aa0d91;">nil</span>)
{<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #007400;">// Get address and interface name<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">var</span> addr = ptr.memory.ifa_addr.memory<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">var</span>
ifname = String.fromCString(ptr.memory.ifa_name)<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #007400;">// If addr is IPv4 or IPv6<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">if</span> addr.sa_family == UInt16(AF_INET) <o:p></o:p></span></div>
<div class="CodePACKT" style="margin-left: .75in; text-indent: .25in;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">||
addr.sa_family == UInt16(AF_INET6) {<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #007400;">// Convert interface address to a string and print it<o:p></o:p></span></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">var</span> ad = [CChar](count: Int(NI_MAXHOST), <o:p></o:p></span></div>
<div class="CodePACKT" style="margin-left: 1.75in; text-indent: .25in;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">repeatedValue: <span style="color: #1c00cf;">0</span>)<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">if</span> (getnameinfo(&addr, socklen_t(<span style="color: #1c00cf;">32</span>), &ad, <o:p></o:p></span></div>
<div class="CodePACKT" style="margin-left: 2.0in;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">socklen_t(ad.count), <span style="color: #aa0d91;">nil</span>, socklen_t(<span style="color: #1c00cf;">0</span>),
NI_NUMERICHOST) == <span style="color: #1c00cf;">0</span>) {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="color: #aa0d91;">if</span> <span style="color: #aa0d91;">let</span> address
= String.fromCString(ad) {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 2;"> </span><span style="mso-spacerun: yes;"> </span>print(<span style="color: #c41a16;">"</span>\<span style="color: #c41a16;">(</span>ifname<span style="color: #c41a16;">):<span style="mso-spacerun: yes;"> </span></span>\<span style="color: #c41a16;">(</span>address<span style="color: #c41a16;">)"</span>)<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>ptr =
ptr.memory.ifa_next<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;">
</span>freeifaddrs(ifaddr)<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Notice that in the second line we import the <b style="mso-bidi-font-weight: normal;">Cifaddrs</b> module using the <b style="mso-bidi-font-weight: normal;">import</b> keyword.<span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>This
essentially imports all of the headers that are defined in the <b style="mso-bidi-font-weight: normal;">Cifaddrs</b> <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">modeul.modulemap</span></i>
file.<o:p></o:p></div>
<div class="NormalPACKT">
The code is commented so you can see what is going on but
I do want to point out a couple of items that will help you when it comes to
use Linux system libraries with swift.<span style="mso-spacerun: yes;">
</span>The first item is how to use C pointers.<span style="mso-spacerun: yes;">
</span>The following code show how we would use the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">getifaddrs()</span></i>
function in normal C code:<o:p></o:p></div>
<div class="CodePACKT">
<span style="color: #000078;"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #000078;">struct</span> ifaddrs *ifap;<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">getifaddrs (&ifap);</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
In this code we create a pointer to an <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">ifaddrs</span></i> structure.<span style="mso-spacerun: yes;"> </span>In Swift we would write this same code like
this:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">var</span> ifap :
UnsafeMutablePointer<ifaddrs> = <span style="color: #aa0d91;">nil</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">if</span> getifaddrs(&ifap)</span><o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
Notice in Swift we use the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">UnsafeMutablePointer</span></i>
structure to declare a pointer to an object type in memory.<span style="mso-spacerun: yes;"> </span>In this case the object type is the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">ifaddrs</span></i> structure.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<span style="mso-spacerun: yes;"><br /></span></div>
<div class="NormalPACKT">
The other item that I want to point is how we are
accessing the information within the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">ifaddrs</span></i>
structure using pointers.<span style="mso-spacerun: yes;"> </span>In C we would
access the information like this:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">ifa->ifa_addr</span><o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
In Swift we access the information like this:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="color: #aa0d91;">var</span> addr = ifa.memory.ifa_addr.memory</span><o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
It took me a little bit of time to wrap my brain around
this.<span style="mso-spacerun: yes;"> </span>Having a pretty good C background
this line of code seemed just wrong to me but once I really wrapped my brain around
the basic concepts here it really made since.<span style="mso-spacerun: yes;">
</span>Basically in Swift we want to avoid using pointers if we can so there
isn’t a simple interface to use them.<span style="mso-spacerun: yes;">
</span>Notice in our Swift line of code we have <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">ifa.memory.ifa_addr.memory</span></i>.<span style="mso-spacerun: yes;"> </span>The <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">ifa.memory</span></i>
part of this line gets the value in memory that the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">ifa</span></i>
pointer is pointing too.<span style="mso-spacerun: yes;"> </span>Then the second
part of this line <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">ifa_addr.memory</span></i>
gets the value in memory that the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">ifa_addr</span></i>
pointer is pointing too.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
If we wanted to get the pointer rather than the actual
value, we would use this line instead:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">var addr = ifa.memory.ifa_addr</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
In this line the <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">addr</span></i>
variable would contain an <i style="mso-bidi-font-style: normal;"><span style="color: #365f91; mso-themecolor: accent1; mso-themeshade: 191;">UnsafeMutablePointer</span></i>.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
It does take a little bit of work to include the Linux
system libraries in our Swift code but overall I think Apple did a great job
making it as easy as possible while avoid a lot of the complexity of C.<span style="mso-spacerun: yes;"> </span>I will hopefully writing more posts on how to
use the Swift port for Linux.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:RelyOnVML/>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="0" Name="footer"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="NormalPACKT">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com2tag:blogger.com,1999:blog-1266480015345788892.post-87630619287308064872016-01-30T12:45:00.001-08:002016-01-30T12:45:13.827-08:00Swift for Linux part 1 – Building Applications<div class="NormalPACKT">
At the end of last year Apple open sourced Swift and
released a port for the Linux operating system.<span style="mso-spacerun: yes;">
</span>At the time of the release I really wanted to try the Linux port of
Swift however I was right in the middle of writing my new book on Protocol-Oriented
programming so I was unable to really spend any time with it.<span style="mso-spacerun: yes;"> </span>Now that I am finishing up the new book, I am
able to spend some quality time with the Swift Linux port.<span style="mso-spacerun: yes;"> </span>These next few posts will show what I have discovered.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
In this first post we will look at several examples that
will demonstrate how to write and build applications with the Swift port for
Linux.<span style="mso-spacerun: yes;"> </span>We will also create a shell
scripts that we can use to create the directory structure and minimum files
needed to use Swift’s package manager to build our applications.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
We will not go over installing Swift on Linux because
Apple has very good documentation on how to do this.<span style="mso-spacerun: yes;"> </span>You can find the documentation on the
<a href="https://swift.org/download/#linux">Swift.org</a><span style="mso-spacerun: yes;"> </span></div>
<h1>
<span lang="EN-GB">Using Swiftc<o:p></o:p></span></h1>
<div class="NormalPACKT">
Once we install Swift on our system and set up the path we
should be able to run the Swift compile.<span style="mso-spacerun: yes;">
</span>To run the compiler we would use the <span style="font-family: Times, 'Times New Roman', serif;"><span style="color: #0b5394;"><i>swiftc</i></span></span> command.<span style="mso-spacerun: yes;"> </span>To see how we could use <span class="CodeInTextPACKT"><span style="color: #0b5394; font-family: Times, Times New Roman, serif;"><b>swiftc</b></span></span>
lets create a file named <b style="mso-bidi-font-weight: normal;">helloWorld.swift</b>
and put the following code in it.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import Foundation<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">print(“Hello World”)</span><o:p></o:p></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="NormalPACKT">
Now run the command <span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">swiftc helloWorld.swift</span></span>.<span style="mso-spacerun: yes;"> </span>If all went well, we would have an
application named <b style="mso-bidi-font-weight: normal;">helloWorld</b> that we
can run like this:<span style="mso-spacerun: yes;"> </span><span class="CodeInTextPACKT"><span style="color: #0b5394; font-family: Times, Times New Roman, serif;"><i>./helloWorld</i></span></span>.<span style="mso-spacerun: yes;"> </span>This application will (obviously) print <span class="MsoIntenseEmphasis">Hello World</span> to the console.<span style="mso-spacerun: yes;"> </span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;"><o:p></o:p></span></span></div>
<div class="NormalPACKT">
<span style="mso-spacerun: yes;"><br /></span></div>
<div class="NormalPACKT">
There are numerous options with the swiftc command and we
can see them by using the <span class="CodeInTextPACKT"><span style="color: #0b5394; font-family: Times, Times New Roman, serif;"><i>–help</i></span></span> option like this:<span style="mso-spacerun: yes;"> </span><span class="CodeInTextPACKT"><span style="color: #0b5394;"><i>swiftc –help</i></span></span>.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<h1>
<span lang="EN-GB">Setting up the directory structure for an application<o:p></o:p></span></h1>
<div class="NormalPACKT">
We could use the Swift command line compiler to compile
our applications but if we had multiple files and/or dependencies, our compile
command could get very complicated and hard to maintain.<span style="mso-spacerun: yes;"> </span>Anyone that has used Make files or other
similar utilities to build C projects can verify that building applications in
this manner can get pretty complicated.</div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Apple has given us a much better approach for developing
applications and modules.<span style="mso-spacerun: yes;"> </span>This approach
does require us to set up a specific directory structure and also a manifest
file named <b style="mso-bidi-font-weight: normal;">Package.swift</b>.<o:p></o:p></div>
<div class="NormalPACKT">
The following diagram shows how we would set up the
directory structure and also the required files:<o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace;">{project dir} <o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace;"><span style="mso-spacerun: yes;"> </span>|<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace;"><span style="mso-spacerun: yes;"> </span>|----
Package.swift <span style="color: #548dd4; mso-themecolor: text2; mso-themetint: 153;">{file}</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace;"><span style="mso-spacerun: yes;"> </span>|<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace;"><span style="mso-spacerun: yes;"> </span>|------ Sources <span style="color: #548dd4; mso-themecolor: text2; mso-themetint: 153;">{directory}</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace;"><span style="mso-spacerun: yes;"> </span>|<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace;"><span style="mso-spacerun: yes;">
</span>|----main.swift <span style="color: #548dd4; mso-themecolor: text2; mso-themetint: 153;">{file}</span></span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
This diagram shows that we have one subdirectory below our
main project directory named <b style="mso-bidi-font-weight: normal;">Sources</b>.<span style="mso-spacerun: yes;"> </span>It also shows that we need two files.<span style="mso-spacerun: yes;"> </span>The first file is the <b style="mso-bidi-font-weight: normal;">Package.swift</b> file which is located in the main project directory
and the <b style="mso-bidi-font-weight: normal;">main.swift</b> file which is
located in the <b style="mso-bidi-font-weight: normal;">Sources</b> directory.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The <b style="mso-bidi-font-weight: normal;">Package.swift</b>
file is a manifest file that tells the compiler about our project and any
dependencies that it may have.<span style="mso-spacerun: yes;"> </span>At
minimum we need to define a name for our project.<span style="mso-spacerun: yes;"> </span>The following example shows the minimum
manifest file that simply defines the name of the project which is <span class="MsoIntenseEmphasis">HelloWorld</span>.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import PackageDescription<span style="mso-spacerun: yes;">
</span><o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">let package = Package(<span style="mso-spacerun: yes;">
</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>name:<span style="mso-spacerun: yes;">
</span>"HelloWorld" <o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">)</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The <b style="mso-bidi-font-weight: normal;">main.swift</b> file
is a special file that is the entry point for our application.<span style="mso-spacerun: yes;"> </span>It is also the only file that is allowed to
have top-level code in it.<span style="mso-spacerun: yes;"> </span>Top-level
code is code that is not encapsulated in a function or type.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
To simplify the process of starting a project I created a
shell script named <span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">createPoject.sh</span></span> that will create the
directory structure, manifest file and main swift file for a project.<span style="mso-spacerun: yes;"> </span>The <b style="mso-bidi-font-weight: normal;">Package.swift</b>
and <b style="mso-bidi-font-weight: normal;">main.swift</b> files are created
with the minimum code needed for our project.<span style="mso-spacerun: yes;">
</span>You can find this and other scripts that I use with my Swift Linux development
on my <span class="URLPACKT"><a href="https://github.com/hoffmanjon/Linux-Swift-Scripts">Scripts for Linux development github page</a></span>. The following
shows the code for the <b style="mso-bidi-font-weight: normal;">createproject.sh</b>
script.<o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#!/bin/bash<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">PROJECTNAME=""<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">DIRNAME=""<span style="mso-tab-count: 1;"> </span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">PACKAGEFILENAME="Package.swift"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">MAINFILENAME="main.swift"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">SOURCESDIRNAME="Sources"<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Check to make sure at least one command<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#line arg is present otherwise exit script<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if [ $# -le 0 ]; then<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>echo "Usage:
creatproject {Name for project} {Optional directory name}"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>exit 1<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">fi<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Assign the value of the first command line arg to the
project name<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#if a second command line arg is present assign that value
to the<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#the directory name otheerwise use the project name<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">PROJECTNAME=$1<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if [ "$1" != "" ]; then<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>DIRNAME=$1<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">else<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;">
</span>DIRNAME=$PROJECTNAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">fi<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Check to see if the directory exists and if so display an error<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#and exit<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if [ -d "$DIRNAME" ]; then<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>echo
"Directory already exists, please choose another name"<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>exit 1<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">fi<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Make the directory structure<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">mkdir -p $DIRNAME/$SOURCESDIRNAME<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Change to the project's directory and create the
Package.swift file<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">cd $DIRNAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">touch $PACKAGEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo "import PackageDescription" >>
$PACKAGEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo "" >> $PACKAGEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo "let package = Package(" >>
$PACKAGEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo "<span style="mso-spacerun: yes;">
</span>name:<span style="mso-spacerun: yes;">
</span>\"$PROJECTNAME\"" >> $PACKAGEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo ")" >> $PACKAGEFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Change to the Sources directory and create the main.swift
file<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">cd $SOURCESDIRNAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">touch $MAINFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo "import Foundation" >> $MAINFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo ""<span style="mso-spacerun: yes;">
</span>>> $MAINFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">echo "print(\"Hello from Swift\")"
>> $MAINFILENAME<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#Done</span><o:p></o:p></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="NormalPACKT">
The <b style="mso-bidi-font-weight: normal;">createPoject.sh</b>
script takes one required and one optional command line argument.<span style="mso-spacerun: yes;"> </span>The first (required) command line argument is
the name of the project and is used to create the <b style="mso-bidi-font-weight: normal;">Package.swift</b> file.<span style="mso-spacerun: yes;"> </span>The
second (optional) command line argument is the name for the project directory.<span style="mso-spacerun: yes;"> </span>If the second command line argument is not
present then we use the name of the project (first command line argument) for
the directory name.<span style="mso-spacerun: yes;"> </span>The following
examples show how we would use the <b style="mso-bidi-font-weight: normal;">createPoject.sh</b>
script to create a project named <b style="mso-bidi-font-weight: normal;">Hello</b>
in a directory named <b style="mso-bidi-font-weight: normal;">Hello</b>.<o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">./createproject Hello </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The previous command would create a directory named <span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">Hello</span></span>
and also the <span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">Sources</span></span> subdirectory.<span style="mso-spacerun: yes;"> </span>It would also create the <b style="mso-bidi-font-weight: normal;">Package.swift</b> and <b style="mso-bidi-font-weight: normal;">main.swift</b>
files.<span style="mso-spacerun: yes;"> </span>The following code shows what the
newly created <b style="mso-bidi-font-weight: normal;">Package.swift</b> file
would look like. <o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import PackageDescription<span style="mso-spacerun: yes;">
</span><o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">let package = Package(<span style="mso-spacerun: yes;">
</span><o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-spacerun: yes;"> </span>name:<span style="mso-spacerun: yes;"> </span>"Hello" <o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">)</span><o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
We used the project name (first command line argument) to
define the package name in this </div>
<div class="NormalPACKT">
<b style="mso-bidi-font-weight: normal;">Package.swift</b>
file.<span style="mso-spacerun: yes;"> </span>The newly created <b style="mso-bidi-font-weight: normal;">main.swift</b> file would look like this.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import Foundation<span style="mso-spacerun: yes;"> </span></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">print("Hello from Swift") </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
As we mentioned earlier, the <b style="mso-bidi-font-weight: normal;">main.swift</b> file is the entry point for our application therefore
the code that is in this file is run when our application starts. <o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
If we wanted the main project directory to have a
different name from our project name then we would use the second command line
argument. This next example shows how we would create a project named <b style="mso-bidi-font-weight: normal;">Hello</b> in a directory named <b style="mso-bidi-font-weight: normal;">HelloDirectory</b>.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">./createproject Hello HelloDirectory</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
The <span class="CodeInTextPACKT"><b>createPoject.sh</b></span> script actually creates
a full project that can be built as is.<span style="mso-spacerun: yes;">
</span>Lets see how we would build this new project.<o:p></o:p></div>
<h1>
<span lang="EN-GB">Building a project<o:p></o:p></span></h1>
<div class="NormalPACKT">
To build our project we would use the following command; <span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">swift
build</span></span>.<span style="mso-spacerun: yes;"> </span>To see the options
with this command we would use the --help option like this:<span style="mso-spacerun: yes;"> </span><span class="CodeInTextPACKT"><i><span style="color: #0b5394;">s</span><span style="color: #0b5394;">wift build --help</span></i></span>.<span style="mso-spacerun: yes;"> </span>Notice the two dashes, all of the other help
options for the other swift commands (IE:<span style="mso-spacerun: yes;">
</span><span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">swiftc</span></span> and <span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">swift</span></span> commands)
use the single dash.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Let build our project that we created in the last
section.<span style="mso-spacerun: yes;"> </span>Change to the project directory
that was created by the <b style="mso-bidi-font-weight: normal;">createPoject.sh</b>
script and then run <span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">swift build</span></span>.<span style="mso-spacerun: yes;"> </span>If all went well you should see output
similar to this:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Compiling Swift Module 'hello' (1 sources) <o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Linking Executable:
.build/debug/hello </span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
If we see this output, we will have an executable named <span class="CodeInTextPACKT"><span style="color: #0b5394;"><i>hello</i></span></span>
in the <b style="mso-bidi-font-weight: normal;">.build/debug</b> directory.<span style="mso-spacerun: yes;"> </span>You can execute it like this:<span style="mso-spacerun: yes;"> </span><span class="CodeInTextPACKT"><span style="color: #0b5394;"><i>.build/debug/hello</i></span></span><o:p></o:p></div>
<h1>
<span lang="EN-GB">Creating a project with multiple files<o:p></o:p></span></h1>
<div class="NormalPACKT">
Recently I had the need to create a number of files that
were of a specific size (I was testing sftp transfer speeds over different
connection types).<span style="mso-spacerun: yes;"> </span>I decided that this
would be a good project to do in Swift.<span style="mso-spacerun: yes;">
</span>The requirements that I had for this project was to create a number of
files that contained random characters and were of specific sizes.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
What I decided to do was to create an array that contained
each character of the alphabet and then randomly select a character from the
array until the file was the size I needed.<span style="mso-spacerun: yes;">
</span>I also decided that I would create an extension to the array type which
would randomly select an element from the array.<span style="mso-spacerun: yes;"> </span>I created a file name <b style="mso-bidi-font-weight: normal;">ArrayExtension.swift</b> in the <b style="mso-bidi-font-weight: normal;">Sources</b>
directory that contained the following code:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import Foundation<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import Glibc<br />
<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">extension Array {<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 1;"> </span>func
getRandomElement() -> Element {<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="mso-tab-count: 2;"> </span>let index =
Int(random() % self.count)<br />
<span style="mso-tab-count: 2;"> </span><o:p></o:p></span></div>
<div class="CodePACKT" style="margin-left: .75in; text-indent: .25in;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">return
self[index]<br />
<span style="mso-tab-count: 1;"> </span><o:p></o:p></span></div>
<div class="CodePACKT" style="text-indent: .25in;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<o:p></o:p></div>
<div class="CodePACKT">
<br /></div>
<div class="NormalPACKT">
Don’t worry too much about how this code works at this
time.<span style="mso-spacerun: yes;"> </span>My next post will be about using C
libraries with Swift and will explain more about modules and using C functions.<span style="mso-spacerun: yes;"> </span>You can however see that generating a random
number with the Swift port for Linux is a little different than with Swift for
OS X or iOS.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Now in our <b style="mso-bidi-font-weight: normal;">main.swift</b>
file we can put the following code:<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import Foundation<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">import Glibc</span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">let num = 1024<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">var str = ""</span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">let alpha =
["a","b","c","d","e","f","g","h","i","j","k",<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">"l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">srandom(UInt32(NSDate().timeIntervalSince1970))<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">for i in 0..<num {<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="CodePACKT" style="text-indent: .25in;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">str +=
alpha.getRandomElement()<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">print(str)<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">var filename = "test\(num)file.txt"<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<br /></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">do {<br />
<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="CodePACKT" style="margin-left: .5in;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">try str.writeToFile(filename,
atomically: true,encoding: <o:p></o:p></span></div>
<div class="CodePACKT" style="margin-left: .5in; text-indent: .5in;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">NSUTF8StringEncoding)<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">} catch let e {<br />
<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="CodePACKT" style="text-indent: .25in;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">print("Error:
\(e)")<br />
<o:p></o:p></span></div>
<div class="CodePACKT">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Once again, we are not worried about how this code
works.<span style="mso-spacerun: yes;"> </span>We are mainly focused on creating
and building a project with multiple files.<span style="mso-spacerun: yes;">
</span>Now we should have two files in our <b style="mso-bidi-font-weight: normal;">Sources</b>
directory named <b style="mso-bidi-font-weight: normal;">main.swift</b> and <b style="mso-bidi-font-weight: normal;">ArrayExtension.swift</b>.<span style="mso-spacerun: yes;"> </span>Now if we go back to the main project
directory (the one with the <b style="mso-bidi-font-weight: normal;">Package.swift</b>
file) we can run the <span class="CodeInTextPACKT"><span style="color: #0b5394;"><i>swift build</i></span></span> command and our project
should compile to an executable.<span style="mso-spacerun: yes;"> </span><o:p></o:p></div>
<div class="NormalPACKT">
<span style="mso-spacerun: yes;"><br /></span></div>
<div class="NormalPACKT">
What we just saw is the <span class="CodeInTextPACKT"><i><span style="color: #0b5394;">swift build</span></i></span> command
will compile all of the files in the Sources directory and include them in our
project.<span style="mso-spacerun: yes;"> </span>This is a lot easier than
creating complex Make files with C.<span style="mso-spacerun: yes;"> </span>I
would recommend that unless there is a specific requirement to use the <span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">swiftc</span></span>
command that you use the <span class="CodeInTextPACKT"><span style="font-size: 9.5pt; mso-bidi-font-size: 9.0pt;">swift build</span></span> command as we saw in
this post.<o:p></o:p></div>
<div class="NormalPACKT">
<br /></div>
<div class="NormalPACKT">
Developers that are use to using Swift to build iOS and/or
OS X applications are also use to using the Cocoa and Cocoa Touch frameworks
however these frameworks are not present in the Linux environment.<span style="mso-spacerun: yes;"> </span>Instead we need to use the C libraries that
are provided with Linux.<span style="mso-spacerun: yes;"> </span>In my next post
I will show how to create modules that will expose those libraries so we can
use them with our Swift applications.<o:p></o:p></div>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:RelyOnVML/>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="0" Name="footer"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";}
</style>
<![endif]-->
<!--StartFragment-->
<!--EndFragment--><br />
<div class="NormalPACKT">
<br /></div>
Jonhttp://www.blogger.com/profile/15130741093149033106noreply@blogger.com9