Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learning Swift
  • Table Of Contents Toc
  • Feedback & Rating feedback
Learning Swift

Learning Swift

By : Andrew J Wagner
4.8 (5)
close
close
Learning Swift

Learning Swift

4.8 (5)
By: Andrew J Wagner

Overview of this book

If you are looking to build iOS or OS X apps using the most modern technology, this book is ideal for you. You will find this book especially useful if you are new to programming or if you have yet to develop for iOS or OS X.
Table of Contents (13 chapters)
close
close
12
Index

Functional programming philosophy


Before we jump in to writing code, let's discuss the ideas and motivations behind functional programming.

State and side effects

Programming is significantly easier when we can think of each code component in isolation. This includes types, functions, and methods. If we wrap our mind around every input to these code components and everything that should be output, we can analyze the code easily to ensure that there are no bugs and that it performs well. Every type is created with a certain number of parameters and each method and function in a program has a certain amount of parameters and return values. Normally, we think about these as only input and output, but the reality is that often, there are more parameters. We refer to these extra input and output as a state.

In a more general sense, state is any stored information, however temporary, that can be changed. Let's consider a simple double function:

func double(input: Int) -> Int {
    return input...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY