Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift iOS Programming for Kids

You're reading from   Swift iOS Programming for Kids Help your kids build simple and engaging applications with Swift 3.0

Arrow left icon
Product type Paperback
Published in Mar 2017
Publisher Packt
ISBN-13 9781787120747
Length 260 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Steffen D. Sommer Steffen D. Sommer
Author Profile Icon Steffen D. Sommer
Steffen D. Sommer
Jim Campagno Jim Campagno
Author Profile Icon Jim Campagno
Jim Campagno
Arrow right icon
View More author details
Toc

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...
lock icon The rest of the chapter is locked
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 $19.99/month. Cancel anytime
Banner background image