Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Object???Oriented Programming with Swift 2

You're reading from  Object???Oriented Programming with Swift 2

Product type Book
Published in Jan 2016
Publisher
ISBN-13 9781785885693
Pages 332 pages
Edition 1st Edition
Languages
Author (1):
Gaston C. Hillar Gaston C. Hillar
Profile icon Gaston C. Hillar

Table of Contents (16) Chapters

Object–Oriented Programming with Swift 2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Objects from the Real World to Playground 2. Structures, Classes, and Instances 3. Encapsulation of Data with Properties 4. Inheritance, Abstraction, and Specialization 5. Contract Programming with Protocols 6. Maximization of Code Reuse with Generic Code 7. Object-Oriented Programming and Functional Programming 8. Extending and Building Object-Oriented Code Exercise Answers Index

Installing the required software


In this book, you will learn to take advantage of all the object-oriented features included in the Swift programming language version 2.2. Most of the examples are compatible with previous Swift versions, such as 1.0, 1.1, 1.2, 2.0, and 2.1, but it is convenient to use Swift 2.0 or later because it has added error-handling features and many performance and stability improvements as compared to its predecessors.

We will use Xcode as our IDE (Integrated Development Environment). All the examples work with Xcode version 7 or higher. The latest versions of the IDE include Swift 2.2 as one of the supported programming languages to build iOS apps, watchOS apps, and Mac OS X applications. It is important to note that Xcode only runs on Mac OS X, and all the instructions provided in this chapter consider that we are running this operating system on a Mac computer. However, after Apple launched Swift 2.2, it made the language open source and added a port to Linux. Thus, we can apply everything we learn about object-oriented programming with Swift when targeting other platforms to which the language is ported.

Tip

In case you want to work with the Swift open source release, you can download the latest development snapshot in the Downloads section at http://swift.org. You can run all the code examples included in the book in the Swift Read Evaluate Print Loop command-line environment instead of working with Xcode Playground. The Swift Read Evaluate Print Loop command-line environment is also known as Swift REPL.

In order to install Xcode, you just need to launch Mac App Store, enter Xcode in the search box, click on the Xcode application icon shown in the results, and make sure that it is the application developed by Apple and not an Xcode helper application. The following screenshot shows the details of the Xcode application in Mac App Store:

Then, click on GET and wait until Mac App Store downloads Xcode. Note that it is necessary to download a few GBs, and therefore, it may take some time to finish the download process. Once the download is finished, click on INSTALL APP and follow the necessary steps to complete the application's installation process. Finally, you will be able to launch the Xcode application as you would execute any other application in your Mac OS X operating system.

Apple usually launches Xcode beta versions before releasing the final stable versions. It is highly recommended to avoid working with beta versions to test the examples included in the book because beta versions are unstable, and some examples might crash or generate unexpected outputs. Mac App Store only offers the latest stable version of Xcode, and therefore, there is no risk of installing a beta version by mistake when following the previously explained steps.

In case we have any Xcode beta version installed on the same computer in which we will run the book samples, we have to make sure that the configuration for the stable Xcode version uses the appropriate command-line tools. We won't work with the command-line tools, but we will take advantage of Playground, and this feature uses the command-line tools under the hood.

Launch Xcode and navigate to Xcode | Preferences… and click on Locations. Make sure that the Command Line Tools drop-down menu displays the stable Xcode version that you installed as the selected option. The following screenshot shows Xcode 7.2 (7C68) as the selected version for Command Line Tools:

Tip

We don't need an iOS Developer Program membership to run the examples included in this book. However, in case we want to distribute the apps or applications coded in Swift to any App Store or activate certain capabilities in Xcode, we will require an active membership.

We don't need any previous experience with the Swift programming language to work with the examples in the book and learn how to model and create object-oriented code with Swift. If we have some experience with Objective-C, Java, C#, Python, Ruby, or JavaScript, we will be able to easily learn Swift's syntax and understand the examples. Swift borrows many features from these and other modern programming languages, and therefore, any knowledge of these languages will be extremely useful.

You have been reading a chapter from
Object???Oriented Programming with Swift 2
Published in: Jan 2016 Publisher: ISBN-13: 9781785885693
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}