My SwiftUI wishlist for WWDC 2020

Let me start by saying that SwiftUI is simply amazing.

I’ve been working on an open-source framework called SwiftUIX for about a year now, with the ambitious goal of filling up certain gaps while we wait for Apple’s annual release cycle. Here are a few of the things I’d like to see in SwiftUI 2.0:

1. Presentation #

While SwiftUI offers some pretty powerful primitives to cover the most commonly used presentation styles such as sheets, action sheets, alerts & popovers - it leaves much to be desired in terms of customizability.

Here are things I’d like to see:

2. Container View Interactors #

You may have come across PresentationMode while working with SwiftUI.

public struct PresentationMode {

    /// Indicates whether a view is currently presented.
    public var isPresented: Bool { get }

    /// Dismisses the view if it is currently presented.
    /// If `isPresented` is false, `dismiss()` is a no-op.
    public mutating func dismiss()

It is exposed via EnvironmentValues as a Binding to a PresentationMode instance. Any sheet presented by SwiftUI can be dismissed by referencing this environment value within the presented view, and invoking dismiss() upon it.

I think this is a fantastic solution to the problem of not being able to reference views/view controllers directly, but still being able to provide a meaningful way of interacting with them.

Consider PaginationView, essentially my take on a port of UIPageViewController. I asked myself, what would an API for programmatic pagination look like?

Drawing inspiration from PresentationMode - I came up with the concept of a “progression controller”. Essentially an opaque interface that exposes two key functions:

protocol ProgressionController {
    func moveToNext()
    func moveToPrevious()

This could be exposed via an environment value (in my case @Environment(\.progressionController)) that could essentially let any child views of the pagination view programmatically navigate back/forth. This ProgressionController could be expanded to fit in more concepts - such as page indices etc.

The beauty of PresentationMode lies in the fact that it decouples the presenter into a concept of a presenter. It lets the presented view have access to one, and only one piece of functionality - presentation. I’d love to see more “interactors” like these. scrollToBottom and scrollToTop for ScrollView, perhaps, by way of a Scroller struct. The possibilities are quite exciting.

3. More Dynamic Properties #

@Environment, @EnvironmentObject, @ObservedObject, @Published & @State are amazing primitives. I feel like this concept can be built upon and fledged out a lot further. Consider @TimerState - a simple wrapper over @State that provides a declarative and easy-to-use API for timers in Swift views.

The following view will refresh every 1 second. @TimerState provides an auto-incrementing Int to reference the current “tick” of a Timer.

struct ContentView: View {
    @TimerState(interval: 1) var tick: Int

    var body: some View {
        Text("\(tick) second(s) have elapsed")

There are obviously many more things I’d like to see in SwiftUI 2.0, such as missing container views (collection views, pagination views etc.) and missing controls (activity indicators, refresh controls, checkboxes) - but these are some areas/concepts that seemed extremely exciting to me, and I’d love to see them developed further.


Now read this

Reimplementing SwiftUI’s deprecated relative view sizing functions.

With Xcode 11 beta 4, Apple deprecated SwiftUI’s View.relativeSize function (as well as View.relativeWidth and View.relativeHeight). The relativeWidth(_:), relativeHeight(_:), and relativeSize(width:height:) modifiers are deprecated. Use... Continue →