WWDC 2022

What are primary associated types in Swift 5.7?

Published on: June 8, 2022

Protocols and associated types have always been somewhat of an interesting beast. They were hard to use sometimes, and before Swift 5.1 we would always have to resort to generics. Consider the following example: class MusicPlayer { func play(_ playlist: Collection) { /* ... */ } } This example wouldn’t compile, and it still wouldn’t today. The reason is that Collection has various associated types that must be clear if we want to use Collection. A common workaround is to use a generic: class MusicPlayer<Playlist: Collection> { func play(_ playlist: Playlist) { /* ... */ } } Instead of using...

Read more...

What’s the difference between any and some in Swift 5.7?

Published on: June 8, 2022

In Swift 5.1 Apple introduced the some keyword. This keyword was key in making SwiftUI work because the View protocol defines a Self requirement: protocol View { associatedtype Body: View @ViewBuilder @MainActor var body: Self.Body { get } } If you’d write var body: View instead of var body: some View you’d see the following compiler error in Swift 5.7: Use of protocol 'View' as a type must be written 'any View’ Or in older versions of Swift you’d see the following: protocol can only be used as a generic constraint because it has Self or associated type requirements The...

Read more...

Presenting a partially visible bottom sheet in SwiftUI on iOS 16

Published on: June 6, 2022

This post is up to date for Xcode 14.0 Beta 1 and iOS 16 Beta 1. It supersedes a version of this post that you can find here On iOS 15, Apple granted developers the ability to present partially visible bottom sheets using a component called UISheetPresentationController. Originally, we had to resort to using a UIHostingController to bring this component to SwiftUI. With iOS 16, we don't have to do this anymore. You can make use of the presentationDetents view modifier to configure your sheets to be fully visible, approximately half visible, or some custom fraction of the screen's height....

Read more...

The iOS Developer’s guide to WWDC 2022

Published on: May 31, 2021

This post was originally published in 2021 and has been touched up for 2022 WWDC is always an exciting time for iOS engineers. It's the one week a year where we're all newcomers to a whole range of features and APIs that Apple has just unleashed upon the world through their latest Xcode, macOS, iOS, tvOS, iPadOS, and watchOS betas. The entire iOS community comes out of hiding and we all come together to share thoughts, experiences, opinions, and findings. For a whole week, Apple releases dozens of sessions on different topics, and we all scramble to watch them as...

Read more...