Book Image

Swift iOS Programming for Kids

By : Steffen D. Sommer, Jim Campagno
Book Image

Swift iOS Programming for Kids

By: Steffen D. Sommer, Jim Campagno

Overview of this book

This book starts at the beginning by introducing programming through easy to use examples with the Swift Playgrounds app. Kids are regularly encouraged to explore and play with new concepts to support knowledge acquisition and retention – these newly learned skills can then be used to express their own unique ideas. Children will be shown how to create their first iOS application and build their very own movie night application.
Table of Contents (21 chapters)
Swift iOS Programming for Kids
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
2
Getting Set Up

Making our own function


Earlier in the chapter, we looked at how one could write code that simulates the making of a pizza. The code looked like this:

print("Flattening the dough to form a round pizza ")
print("Adding some tomato sauce ")
print("Adding some mozzarella cheese ")
print("Adding some spicy pepperoni ")
print("Preparing the pizza in the oven ")
print("Done! Delicious pizza ready to be eaten ")

We discussed how this will scale if one would like to make many pizzas and the issues associated with that. Let's now look at how we can solve this by abstracting the preceding code using a function.

Go ahead and create a new Xcode playground and type in the preceding code:

The first thing we can do is to move our lines of code into a function body. Let's name our function makePizza for now. The function shouldn't take in any parameters and it will not return anything:

func makePizza() {
    print("Flattening the dough to form a round pizza ")
    print("Adding some tomato sauce ")
    print...