Stefan Kaczmarek, Brad Lees and Gary Bennett
Swift 5 for Absolute BeginnersLearn to Develop Apps for iOS5th ed.
Stefan Kaczmarek
Phoenix, AZ, USA
Brad Lees
Phoenix, AZ, USA
Gary Bennett
Scottsdale, AZ, USA
ISBN 978-1-4842-4867-6e-ISBN 978-1-4842-4868-3
© Stefan Kaczmarek, Brad Lees, Gary Bennett 2019
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
Introduction
Over the last ten years, we’ve heard the following countless times:
  • “I’ve never programmed before, but I have a great idea for an iPhone or iPad app.”

  • “Can I really learn to program the iPhone or iPad?”

To the latter we answer, “Yes, but you have to believe you can.” Only you are going to tell yourself you can’t do it.

For the Newbie

This book assumes you may have never programmed before. The book is also written for someone who may have never programmed before using object-oriented programming (OOP) languages. There are many Swift books out there, but all of these books assume you have programmed before and know OOP and computer logic. We wanted to write a book that takes readers from knowing little or nothing about computer programming and logic to being able to program in Swift. After all, Swift is a native programming language for the iPhone, iPad, and Mac.

Over the last ten years, we have taught thousands of students to be iOS (iPhone/iPad) developers. Many of our students have developed some of the most successful iOS apps in their category in the App Store. We have incorporated what we have learned in our first two courses, Introduction to Object-Oriented Programming and Logic and Swift for iPhone/iPad Developers, into this book.

For the More Experienced

Many developers who programmed years ago or programmed in a non-OOP language need a background in OOP and Logic before they dive into Swift. This book is for you. We gently walk you through OOP and how it is used in iOS development to help make you a successful iOS developer.

How This Book Is Organized

You’ll notice that we are all about successes in this book. We introduce the OOP and Logic concepts in Swift Playgrounds and then move those concepts to Xcode. Many students are visual or learn by doing. We use both techniques. We’ll walk you through topics and concepts with visual examples and then take you through step-by-step examples reinforcing the concepts.

We often repeat topics in different chapters to reinforce what you have learned and apply these skills in new ways. This enables new programmers to reapply development skills and feel a sense of accomplishment as they progress. Don’t worry if you feel you haven’t mastered a topic. Keep moving forward!

The Formula for Success

Learning to program is an interactive process between your program and you. Just like learning to play an instrument, you have to practice. You must work through the examples and exercises in this book. Understanding a concept doesn’t mean you know how to apply it and use it.

You will learn a lot from this book. You will learn a lot from working through the exercises in this book. However, you will really learn when you debug your programs. Spending time walking through your code and trying to find out why it is not working the way you want is an unparalleled learning process. The downside of debugging is a new developer can find it especially frustrating. If you have never wanted to throw your computer out the window, you will. You will question why you are doing this, and whether you are smart enough to solve the problem. Programming is very humbling, even for the most experienced developer.

Like a musician, the more you practice the better you get. By practicing, we mean programming! You can do some amazing things as a programmer. The world is your oyster. Seeing your app in the App Store is one of the most satisfying accomplishments. However, there is a price, and that price is time spent coding and learning.

Having taught many students to become iOS developers, we have put together a formula for what makes students successful. Here is our formula for success:
  • Believe you can do it. You’ll be the only one who says you can’t do this. So don’t tell yourself that.

  • Work through all the examples and exercises in this book.

  • Code, code, and keeping coding. The more you code, the better you’ll get.

  • Be patient with yourself. If you were fortunate enough to have been a 4.0 student who can memorize material just by reading it, this will not happen with Swift coding. You are going to have to spend time coding.

  • You learn by reading this book. You really learn by debugging your code.

  • Don’t give up!

The Development Technology Stack

We will walk you through the process of understanding the development process for your iOS apps and what technology you need. However, briefly looking at all the technology pieces together is helpful. These are the key iOS development technologies you will need to know in order to build a successful app and get it on the App Store:
  • Apple Developer web site

  • App Analytics

  • iOS SDK

  • Swift

  • Object-Oriented Programming and Logic

  • Xcode Integrated Development Environment (IDE)

  • Debugging

  • Performance Tuning

We know this is a lot of technology. Don’t worry, we will go through it and will be comfortable using it.

Required Software, Materials, and Equipment

One of the great things about developing iOS apps is just about everything is free to develop your app.
  • Xcode

  • Swift

  • macOS 10.14 or higher

  • iOS SDK

  • iOS Simulator

All you need to get started is a Mac and knowledge of where to download everything. We will cover this.

Operating System and IDE

For developing iOS apps, you have to use Xcode on a Mac. You can download Xcode for free from the Mac App Store (see Figure 1 ).
../images/341013_5_En_BookFrontmatter_Fig1_HTML.jpg
Figure 1

Downloading Xcode from the Mac App Store

Software Development Kits

You will need to register as a developer. You can do this for free at https://developer.apple.com/ios (see Figure 2 ).
../images/341013_5_En_BookFrontmatter_Fig2_HTML.jpg
Figure 2

Apple Developer web site

When you are ready to upload your app to the App Store, you will need to pay $99/year in order to publish it.

Dual Monitors

We recommend developers have a second monitor connected to their computer. It is great to step through your code and watch your output window and iOS simulator at the same time on dual independent monitors.

Apple hardware makes this easy. Just plug your second monitor into the port of any Mac, with the correct adapter of course, and you have two monitors working independently of one another. See Figure 3 . Note that dual monitors are not required. You will just have to organize your open windows to fit on your screen if you don’t.
../images/341013_5_En_BookFrontmatter_Fig3_HTML.jpg
Figure 3

Arranging dual monitors on a Mac

Table of Contents

Index 353

About the Authors and About the Technical Reviewer

About the Authors

Stefan Kaczmarek
../images/341013_5_En_BookFrontmatter_Figb_HTML.png

has more than 20 years of software development experience specializing in mobile applications, large-scale software systems, project management, network protocols, encryption algorithms, and audio/video codecs. As chief software architect and cofounder of SKJM, LLC, Stefan developed a number of successful mobile applications including iCam (which has been featured on CNN , Good Morning America , and The Today Show , and which was chosen by Apple to be featured in the “Dog Lover” iPhone 3GS television commercial) and iSpy Cameras (which held the #1 Paid iPhone App ranking in a number of countries around the world including the United Kingdom, Ireland, Italy, Sweden, and South Korea). Stefan resides in Phoenix, Arizona, with his wife, Veronica, and their two children.

 
Brad Lees
../images/341013_5_En_BookFrontmatter_Figc_HTML.png

has more than a decade of experience in application development and server management. He has specialized in creating and initiating software programs in real-estate development systems and financial institutions.

His career has been highlighted by his positions as information systems manager at The Lyle Anderson Company; product development manager for Smarsh; vice president of application development for iNation; and IT manager at The Orcutt/Winslow Partnership, the largest architectural firm in Arizona.

A graduate of Arizona State University, Brad resides in Phoenix with his wife Natalie and their five children.

 
Gary Bennett
../images/341013_5_En_BookFrontmatter_Figd_HTML.png

teaches iPhone/iPad programming courses online. He has taught hundreds of students how to develop iPhone/iPad apps and has several very popular apps on the iTunes App Store. Gary’s students have some of the best-selling apps on the iTunes App Store. Gary also worked for 25 years in the technology and defense industries. He served 10 years in the US Navy as a nuclear engineer aboard two nuclear submarines. After leaving the Navy, Gary worked for several companies as a software developer, chief information officer, and resident. As CIO, he helped take VistaCare public in 2002. He also coauthored iPhone Cool Projects (Apress, 2009). Gary lives in Scottsdale, Arizona, with his wife, Stefanie, and their four children.

 

About the Technical Reviewer

Bruce Wade

is a software engineer from British Columbia, Canada. He started software development when he was 16 years old by coding his first web site. He went on to study Computer Information Systems at DeVry Institute of Technology in Calgary, then to further enhance his skills he studied Visual & Game Programming at The Art Institute of Vancouver. Over the years he has worked for large corporations as well as several start-ups. His software experience has led him to utilize many different technologies including C/C++, Python, Objective-C, Swift, Postgres, and JavaScript. In 2012, he started the company Warply Designed to focus on mobile 2D/3D and OS X development. Aside from hashing out new ideas, he enjoys spending time hiking with his Boxer Rasco, working out, and exploring new adventures.