Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Swift iOS Programming for Kids
Swift iOS Programming for Kids
Swift iOS Programming for Kids
Ebook436 pages4 hours

Swift iOS Programming for Kids

Rating: 0 out of 5 stars

()

Read preview

About this ebook

About This Book
  • Children can express their creativity while learning through interactive Swift Playgrounds
  • Empower children to think critically about problems
  • Learning programming basics can help children gain confidence in problem solving
  • Help children put their imagination into action building their first iOS app
Who This Book Is For

Children who are curious about the technology we use in our daily lives and want to know how it works can use this book to learn about programming and building their first iOS app. No prior programming experience is necessary.

LanguageEnglish
Release dateMar 22, 2017
ISBN9781787125650
Swift iOS Programming for Kids

Related to Swift iOS Programming for Kids

Related ebooks

Programming For You

View More

Related articles

Reviews for Swift iOS Programming for Kids

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Swift iOS Programming for Kids - Steffen D. Sommer

    Table of Contents

    Swift iOS Programming for Kids

    Credits

    About the Authors

    About the Reviewer

    www.PacktPub.com

    Why subscribe?

    Customer Feedback

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Downloading the color images of this book

    Errata

    Piracy

    Questions

    1. What is Programming?

    The Swift programming language

    Why is programming important?

    What you will learn from this book

    Summary

    2. Getting Set Up

    Xcode

    Downloading Xcode

    Playground

    Summary

    3. Say Hello

    What is a console application?

    Setting up our first Xcode playground

    Creating the playground

    Saving our playground

    Removing what is unnecessary

    A quick look at the Xcode interface

    Creating our program

    A quick look at Xcode errors

    Xcode and autocompletion

    Summary

    4. Favorite Things

    Variables and constants

    Variables

    Constants

    Summary

    5. Factories

    String and Int

    Double

    Summary

    6. Making Pizza

    How the iPhone runs our program

    A simple program without functions

    What is a function?

    A function can receive some input

    A function can be pure

    A function can return something

    A look at functions in Swift

    Making our own function

    Summary

    7. Toy Bin

    Collection types

    Array

    Dictionary

    Optionals

    Summary

    8. Smarter Toy Bin

    Buttercup

     Learning the for-in loop

    Conditionals

    Learning for-loops and if-statements

    Append method

    Find the buttercup

    Summary

    9. Making Some Friends

    OOP

    Modeling real-world objects

    Modeling a mug

    Modeling a person

    Our first class

    Instance properties

    Instance methods

    Making objects interact with each other

    Adding more classes to the mix

    Summary

    10. Pokémon Battle

    Pokémon type

    Initializer syntax

    Functions and types

    Charizard versus pikachu

    Hug function

    Summary

    11. Simon Says

    GUI

    Laying out a view

    Setting up a new iOS project

    Xcode's Interface Builder and storyboards

    Simon says

    Designing the interface

    Summary

    12. Starry Night

    A deep dive into UI in iOS

    The view hierarchy

    Frames and bounds

    Auto Layout

    The UIViewController life cycle

    Starry Night

    Designing the UI

    Adding functionality to our interface

    Summary

    13. Space Pizza Delivery

    Space Pizza

    Xcode

    Enumerations

    Switch statement

    Planet

    Type property

    Space junk

    Pizza service

    Property observers

    Storyboard and view controller

    Hooking everything up

    Space junk buttons

    Updating the cost

    Summary

    14. Movie Night - iOS App

    How to create a list

    The data source

    The delegate

    UITableViewController

    Our final application: Movie Night

    The interface

    Displaying items in our list

    Dynamically adding items to our list

    Deleting items from our list

    Persisting our movies

    Deploying our application to our iPhone

    Summary

    Swift iOS Programming for Kids


    Swift iOS Programming for Kids

    Copyright © 2017 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: March 2017

    Production reference: 1170317

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham 

    B32PB, UK.

    ISBN 978-1-78712-074-7

    www.packtpub.com

    Credits

    About the Authors

    Since Swift was announced at WWDC, Steffen D. Sommer has had a passionate interest in the programming language. He's currently working as a lead Vapor developer at a company called Nodes in Copenhagen, where he focuses on developing backend systems using Swift.

    In his spare time, he helps organize the local iOS meet up, visits iOS conferences around the world, and explores the different aspects of and use cases for Swift, such as putting Swift on the server and doing functional programming in Swift. You can also find him contributing to open source projects on GitHub or blogging on his personal website.

    First, I would like to thank my girlfriend, Mia, for her never-ending feedback and support while I wrote this book. I would also like to thank my friends at IAIF for their input and support throughout the process.

    Jim Campagno is an iOS developer and teacher living in New York City. He's currently working as an iOS instructor at the Flatiron School, helping beginners of Swift and iOS become iOS developers.

    Jim has a deep desire and high level of creativity that he brings to teaching. He created the Swift online course offered at Flatiron School, which includes in-depth readings along with test-driven labs, challenging the student to write code in Swift. Jim also runs an active YouTube channel, putting out in-depth content and helping students understand everything in iOS and Swift—from the basics to complex topics.

    Most importantly, Jim ensures that the content he creates is accessible, fun, and interactive. He enjoys putting together a story behind every topic to make it more enjoyable for the reader.

    I would like to thank my roommates (Tom and Matt) for putting up with me while I wrote this book. I would also like to thank Tim Clem, who has inspired me to keep learning. Lastly, I would like to thank Joe Burgess for teaching me how to code.

    About the Reviewer

    Doug Sparling works as a technical architect and software developer for Andrews McMeel Universal, a publishing and syndication company in Kansas City, MO. At AMU, he uses Go for web services, Python for backend services, Ruby on Rails and WordPress for website development, and Objective-C, Swift, and Java for native iOS and Android development. AMU's sites include www.gocomics.com, www.uexpress.com, www.puzzlesociety.com, and dilbert.com.

    He also was the co-author of a Perl book, Instant Perl Modules for McGraw-Hill, and a reviewer for other Packt Publishing books, including jQuery 2.0 Animation Techniques: Beginner's Guide and WordPress Web Application Development. Doug has also played various roles for Manning Publications as reviewer, technical development editor, and proofer, working on books such as Go in Action, The Well-Grounded Rubyist 2nd Edition, iOS Development with Swift, and Programming for Musicians and Digital Artists.

    www.PacktPub.com

    For support files and downloads related to your book, please visit www.PacktPub.com.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    https://www.packtpub.com/mapt

    Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Customer Feedback

    Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/Swift-Programming-Kids-Steffen-Sommer/dp/1787120740/.

    If you'd like to join our team of regular reviewers, you can e-mail us at customerreviews@packtpub.com. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!

    Preface

    Swift has risen quickly to be one of the preferred languages among developers and will have a long and fruitful future under the guidance of Apple. Since making the language open source over a year ago, it's become clear that Swift will be a versatile cross-platform language with a wealth of opportunities beyond Apple's ecosystem.

    This book will introduce you to programming in a fun and approachable way. We will be building and interacting with fun examples to help you grasp multiple concepts. We will also be building fun iOS applications to help solidify your knowledge of Swift.

    What this book covers

    Chapter 1, What is Programming?, introduces the Swift programming language.

    Chapter 2, Getting Set up, shows you how to install Xcode and introduces you to writing code in a Playground file.

    Chapter 3, Say Hello, helps you create your own Playground file and write your first line of code.

    Chapter 4, Favorite Things, discusses how to store values in variables and constants.

    Chapter 5, Factories, explains types and introduces the String and int types.

    Chapter 6, Making Pizza, outlines the problem that functions solve along with creating your own functions.

    Chapter 7, Toy Bin, covers the array and dictionary types.

    Chapter 8, Smarter Toy Bin, focuses on the use of loops and if-else statements.

    Chapter 9, Make Some Friends, takes you through object-oriented programming and classes. You will create your first instance of a class.

    Chapter 10, Pokémon Battle, helps you create your own Pokémon class along with having instances of this class interact with each other.

    Chapter 11, Simon Says, introduces Interface Builder and Storyboards, and also helps you create your first application with a user interface.

    Chapter 12, Starry Night, showcases the view hierarchy and auto layout. You will be creating an application that has a user interface that scales across multiple screen sizes and that will be able to change its background color at the press of a button.

    Chapter 13, Space Pizza Delivery, shows you how to create an iOS application that incorporates everything we’ve learned so far. It also introduces enums, private variables, protocols, delegates, and property observers.

    Chapter 14, Movie Night - iOS App, takes you through creating an iOS application that introduces UITableViews and persisting data between the launches of the application.

    What you need for this book

    You will need the following things for the book:

    A Mac computer running OS X 10.11.5 or later.

    The Xcode application, which is available in the Mac App Store for free.

    An iPhone running iOS 8 or newer if you want to test your application on a device. This is optional.

    Who this book is for

    Children who are curious about the technology we use in our daily lives and who want to know how it works can use this book to learn about programming and build their first iOS app. No prior programming experience is necessary.

    Conventions

    In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

    Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: The compiler will expect your variables to be of a certain type (int, string, and so on) and will throw a compile-time error if you try to assign a value of a different type.

    A block of code is set as follows:

    class Pokemon {

        let name: String

        init(name: String) {

            self.name = name

        }

    }

    New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: Launch Xcode and navigate to File | New | Project.

    Note

    Warnings or important notes appear in a box like this.

    Tip

    Tips and tricks appear like this.

    Reader feedback

    Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail feedback@packtpub.com, and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

    Customer support

    Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

    Downloading the example code

    You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

    You can download the code files by following these steps:

    Log in or register to our website using your e-mail address and password.

    Hover the mouse pointer on the SUPPORT tab at the top.

    Click on Code Downloads & Errata.

    Enter the name of the book in the Search box.

    Select the book for which you're looking to download the code files.

    Choose from the drop-down menu where you purchased this book from.

    Click on Code Download.

    Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

    WinRAR / 7-Zip for Windows

    Zipeg / iZip / UnRarX for Mac

    7-Zip / PeaZip for Linux

    The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Swift-iOS-Programming-for-Kids. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

    Downloading the color images of this book

    We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/SwiftiOSProgrammingforKids_ColorImages.pdf.

    Errata

    Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

    To view the previously submitted errata, go to https://www.packtpub.com/books/content/supportand enter the name of the book in the search field. The required information will appear under the Errata section.

    Piracy

    Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

    Please contact us at copyright@packtpub.com with a link to the suspected pirated material.

    We appreciate your help in protecting our authors and our ability to bring you valuable content.

    Questions

    If you have a problem with any aspect of this book,

    Enjoying the preview?
    Page 1 of 1