FREE TRIAL: Accelerate your app development career with Hacking with Swift+! >>

< Back to Latest Articles

Functional programming in Swift: Introduction

Before you dive in to the first article in this course, I want to give you a brief overview of our goals, how the content is structured, as well as a rough idea of what you can expect to find.

Watch the video here, or read the article below

Quick links

Why functional?

There are lots of ways of thinking about programming, and you’ll often hear folks use terms such as imperative programming or declarative programming. Functional programming is one such approach, but it doesn’t really have a clear-cut definition – it’s a little bit fuzzy, so that the exact definition one person gives is unlikely to match the definition from someone else.

But that’s okay; definitions don’t really help much anyway, not unless you’re planning to sit an exam. Instead, I’m always much more interested in help you understand things in practice: I want you to see real functional Swift in action so the benefits are obvious to you, I want to give you hands-on examples even for the most advanced topics so you can get them into your own projects straightaway, and although I want to show you lots of “how” I also I want to give you as much why as I can – I want you to understand the underlying principles that are at play, so you feel confident in discussing and using functional programming at every level.

Lightweight encounters

I taught some functional programming in my book Pro Swift, and we’re going to use a similar approach here – at least to start with. That approach is based on something I was introduced to by Andy Matuschak, who used to work on the UIKit team at Apple.

The approach we’ll be starting with is called “lightweight encounters”, and it means we start by looking at functional programming purely in terms of practical benefits – we’ll pick off one small task, look at how we can solve it without functional programming, then upgrade our code to have a more functional approach. This “before and after” should mean you can see the benefits of functional programming for yourself, and also give you lots of places where you can get quick wins in your own code.

So, that’s a very similar approach to Pro Swift. However, here that’s just our starting point – as this course progresses we’re going to push further and further past lightweight encounters so you understand all the theory as well as the practice.

Now, that doesn’t mean we’re going to drift off into academia: everything we do will have a firm basis in Swift code you can try for yourself, and in fact I really do encourage you to try the code yourself so you can toy around with it and get a stronger grasp.

Stop when you’re ready

This course is structured so that it more or less gets steadily more complex as we progress. This means the whole first chunk of videos should be really useful to everyone, so you can just dive in and explore. As we progress you’ll feel the difficulty ramp up little by little and there might come a point where you think you’ve had enough – that you’ve already got enough benefit from the course, and are happy to move on to something else.

What I want to say is this: it’s okay to stop when you’re ready. Whenever that point is – whenever you think you’ve gained enough from this course to make a significant difference to your code – it’s okay to move on to something else. Obviously I hope you’ll continue get to the end and find value all the way, but if you’re sitting there thinking “this is hard” or – worse – “will I ever use this?” then chances are you’re not learning too much.

Don’t beat yourself up. Take a break, apply what you’ve learned, and reap the benefits of that – once you’re a bit further along you might find you can come back with fresh eyes and get a whole new round of benefits.

Releasing installments

This course is being published in installments, and although the exact release schedule will fluctuate a little depending on topic difficulty, you should be able to come and get new videos regularly.

However, if you are following along as videos are being published, this is a great chance for you to write in to ask for something specific. I’m happy to hear suggestions, as long as they align my goal of teaching theory and practice hand in hand.

Take your time

And finally, I want to remind you again that the most important thing you can do in this course is apply what you learn.

We all rely on muscle memory to make our jobs faster and easier, which means when it comes to solving a problem we naturally rely on approaches that worked previously. In this course we’ll be covering a huge range of techniques, and if you just fly through the material as fast as you can chances are you won’t retain much – it might be fun to learn, but it won’t really stick.

Instead, your goal should be to try to build new muscle memory: to slowly retrain your brain that there are newer, better ways of solving problems, so that over time you reach for functional programming techniques first and instinctively. The only way to do this is to apply, apply, and apply some more – as soon as you finish one part of this course, have a think about where you can try it out in your own projects, so that not only can you refer back to these articles in the future but you can also look at your own code.

Anyway, I hope you enjoy the course, and more importantly that you find lots of real-world success with functional programming!

If you liked this, you'd love Hacking with Swift+…

Here's just a sample of the other tutorials, with each one coming as an article to read and as a 4K Ultra HD video.

Find out more and subscribe here


Ultimate Portfolio App: Introduction

14:17

ULTIMATE PORTFOLIO APP

FREE: Ultimate Portfolio App: Introduction

While I’m sure you’re keen to get started programming immediately, please give me a few minutes to outline the goals of this course and explain why it’s different from other courses I’ve written.

Shadows and glows

19:50

SWIFTUI SPECIAL EFFECTS

FREE: Shadows and glows

SwiftUI gives us a modifier to make simple shadows, but if you want something more advanced such as inner shadows or glows, you need to do extra work. In this article I’ll show you how to get both those effects and more in a customizable, flexible way.

Making the most of optionals

23:07

ADVANCED SWIFT

FREE: Making the most of optionals

Swift’s optionals are implemented as simple enums, with just a little compiler magic sprinkled around as syntactic sugar. However, they do much more than people realize, and in this article I’m going to demonstrate some of their power features that can really help you write better code – and blow your mind along the way.

How to use phantom types in Swift

24:11

ADVANCED SWIFT

FREE: How to use phantom types in Swift

Phantom types are a powerful way to give the Swift compiler extra information about our code so that it can stop us from making mistakes. In this article I’m going to explain how they work and why you’d want them, as well as providing lots of hands-on examples you can try.

Understanding generics – part 1

20:01

INTERMEDIATE SWIFT

FREE: Understanding generics – part 1

Generics are one of the most powerful features of Swift, allowing us to write code once and reuse it in many ways. In this article we’ll explore how they work, why adding constraints actually helps us write more code, and how generics help solve one of the biggest problems in Swift.

Using memoization to speed up slow functions

36:18

HIGH-PERFORMANCE APPS

FREE: Using memoization to speed up slow functions

In this article you’ll learn how memoization can dramatically boost the performance of slow functions, and how easy Swift makes it thanks to its generics and closures.

Making your app accessible

33:12

ULTIMATE PORTFOLIO APP

FREE: Making your app accessible

It is my firm belief that every iOS app should be usable to everyone, and putting in the work to make your app function well no matter who is using it says a lot about the kind of developer you are.

Creating a custom property wrapper using DynamicProperty

14:20

INTERMEDIATE SWIFTUI

FREE: Creating a custom property wrapper using DynamicProperty

It’s not hard to make a basic property wrapper, but if you want one that automatically updates the body property like @State you need to do some extra work. In this article I’ll show you exactly how it’s done, as we build a property wrapper capable of reading and writing documents from our app’s container.

Creating a WaveView to draw smooth waveforms

32:08

CUSTOM SWIFTUI COMPONENTS

FREE: Creating a WaveView to draw smooth waveforms

In this article I’m going to walk you through building a WaveView with SwiftUI, allowing us to create beautiful waveform-like effects to bring your user interface to life.

Trees

31:55

DATA STRUCTURES

FREE: Trees

Trees are an extraordinarily simple, extraordinarily useful data type, and in this article we’ll make a complete tree data type using Swift in just a few minutes. But rather than just stop there, we’re going to do something quite beautiful that I hope will blow your mind while teaching you something useful.

User-friendly network access

14:26

NETWORKING

FREE: User-friendly network access

Anyone can write Swift code to fetch network data, but much harder is knowing how to write code to do it respectfully. In this article we’ll look at building a considerate network stack, taking into account the user’s connection, preferences, and more.

Introduction to App Clips

1:20:32

HACKING WITH SWIFT LIVE 2020

Introduction to App Clips

App Clips let us ship tiny slices of our app to do exactly one thing, and in this part we’ll explore how to build them in a test environment.

Customizing Toggle using ToggleStyle

9:28

INTERMEDIATE SWIFTUI

Customizing Toggle using ToggleStyle

Most of the time the built-in iOS controls are great, but sometimes you want something just a little different. In this article I’m going to walk you through how you can take complete control over the way toggle switches work in SwiftUI, providing custom rendering and interactions.

Checkpoint 3

6:46

SOLUTIONS

Checkpoint 3

Checkpoint 3 of Swift for Complete Beginners asks you to tackle the classic FizzBuzz problem, printing Fizz, Buzz, FizzBuzz, or a number depending on the input. Let’s solve that now…

Remaking the welcome screen

22:31

REMAKING APPS

Remaking the welcome screen

Few things in SwiftUI are quite so easy and yet quite so rewarding as rebuilding Apple’s welcome screens. In this article we’ll do just that, making it flexible enough to adapt easily for your own apps.

Cleaning up view code

37:26

ULTIMATE PORTFOLIO APP

Cleaning up view code

Although our SwiftUI layouts conform to the View protocol, if you were to try to think about them in MVC terms I’d say they were more like controllers. And like controllers from UIKit, we need to put in some work to keep SwiftUI views lean – let’s look at this now…

Creating the Home view

35:49

ULTIMATE PORTFOLIO APP

Creating the Home view

So far our home view has simply been a host for adding test data, but that changes now: we’re going to make the home view a summary of all their project progress, plus the most important items coming up next.

Disclosure indicators, paging TabView, and grids

1:29:28

HACKING WITH SWIFT LIVE 2020

Disclosure indicators, paging TabView, and grids

In this part we’ll be exploring three important additions to SwiftUI from WWDC20, then starting to integrate them into our app.

Questions and answers, part 2

46:09

ULTIMATE PORTFOLIO APP

Questions and answers, part 2

I’ve had a whole bunch more questions sent in from readers, covering Core Data, property wrappers, localization, and more, so let’s dive into them with some code examples.

Counting Core Data results

20:34

ULTIMATE PORTFOLIO APP

Counting Core Data results

Now that we’ve designed a basic awards UI, we can bring it to life with some Core Data queries to determine which awards have actually been earned.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.