NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

< Back to Hacking with Swift+

Why opaque return types are so important

In the full episode…

  • Protocols aren’t enough
  • Why not just use a concrete type?
  • How this applies to SwiftUI
  • Why does this matter?
  • Challenges
Get the full 12:19 video by subscribing

Why subscribe?


Hacking with Swift+ delivers high-quality tutorials for subscribers, with each tutorial coming as a 4K Ultra HD video and in text form so you can read or watch – whatever works best for you.

So, you can get this full video and article as well as all other subscriber-only tutorials and all future tutorials – all by subscribing to Hacking with Swift+ today.

Subscribe to Hacking with Swift+

More from Hacking with 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.

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.

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.

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.

Queues and deques

28:18

DATA STRUCTURES

Queues and deques

Now that we’ve covered stacks and linked lists, queues and deques ought to be easier. In this article we’ll build both data structures in just a few lines of Swift, then explore interesting additions such as contains().

Making the most of optionals

23:07

ADVANCED SWIFT

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.

Remaking the Tips app

27:45

REMAKING APPS

Remaking the Tips app

In this article we’re going to look at how to rebuild the Tips app using SwiftUI, including how to make scrolling tabs of content, how to get a parallax scrolling effect, and more.

User-friendly network access

14:26

NETWORKING

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.

Parsing difficult JSON

26:05

WORKING WITH DATA

Parsing difficult JSON

If you have nice, clean JSON then using Swift and Codable is like a dream come true. But what if you have messy JSON, or JSON where you really don’t know what you’ll receive ahead of time? In this article I’ll show you how to handle any kind of JSON in an elegant way, without relying on third-party libraries.

Understanding generics – part 1

20:01

INTERMEDIATE SWIFT

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.

Advanced string interpolation, part two

19:32

ADVANCED SWIFT

Advanced string interpolation, part two

In part one of this tutorial we looked at how to customize string interpolations on a type-by-type basis, giving you more control over how your code works. In this second part we’ll look at a second powerful use for interpolation: building whole types from scratch.

Controlling views using the accelerometer

39:03

SWIFTUI SPECIAL EFFECTS

Controlling views using the accelerometer

Reading device motion and orientation is a fast and slightly magical way to incorporate the real world into your apps, and can do a huge amount to add a little spark of delight to your UI. In this article I’m going to show you how easy it is to control SwiftUI layouts using the accelerometer, and give you a few ideas for special effects.

Creating completely custom buttons using PrimitiveButtonStyle

19:21

INTERMEDIATE SWIFTUI

Creating completely custom buttons using PrimitiveButtonStyle

SwiftUI’s ButtonStyle lets us focus on how our buttons look, but not how they work, which in many situations is valuable. In this article we’ll look at a more advanced protocol, PrimitiveButtonStyle, and see how that gives us complete control over button functionality.

Creating chained network requests with Combine

18:36

NETWORKING

Creating chained network requests with Combine

We already looked at how to fetch decodable data using Combine, and also how to fetch and merge multiple sources of data. In this article we’ll tackle something even more complex: creating chained network requests, where the information retrieved from one request must be used to create multiple other requests.

Linked lists

29:22

DATA STRUCTURES

Linked lists

If there’s one data structure they just love teaching you at school, it’s linked lists. In this article we’re going to look at why linked lists are so appealing, walk through how to build a linked list with Swift, and look at an alternative approach using enums.

Using dates safely and effectively

18:36

MAKING THE MOST OF FOUNDATION

Using dates safely and effectively

Working with dates in software is hard, and if you don’t understand why then think about time zones, think about leap years, or think about how it’s the year 2563 in the Thai calendar. Apple gives us many tools for making them easier but they can be hard to discover, so in this article I’m going to try to provide some clear guidance for what to use and when.

Finding and fixing slow rendering

25:12

HIGH-PERFORMANCE APPS

Finding and fixing slow rendering

Instruments is a powerful tool for identifying performance problems, but in this article I’ll show you how to find code that slows down rendering in your app, causing slow scrolling, wasted CPU time, and more – all through the simulator.

High-speed computation using Accelerate

36:34

HIGH-PERFORMANCE APPS

High-speed computation using Accelerate

Many coding problems are designed to perform the same operation on lots of data, and in fact they are so common Apple has a whole framework to make it better: Accelerate. In this video I’ll give you an introduction to Accelerate using practical examples so you can see just how easy it is.

Creating a spaceship operator

8:47

INTERMEDIATE SWIFT

Creating a spaceship operator

When it comes to learning operator overloading, there is one operator that Swift lacks, that many other languages have, and is genuinely useful. In this article I’ll show you how to build the spaceship operator in Swift – it’s surprisingly easy, and useful too.

The pros and cons of operator overloading

23:37

ADVANCED SWIFT

The pros and cons of operator overloading

I’ve written about operator overloading previously, not least in my book Pro Swift, but in the article I want to go into more depth on the places where it’s really useful – and the places where it’s not such a good idea.

Link copied to your pasteboard.