Why there will never be SwiftUI for non-Apple devices

SwiftUI relies on Apple's own frameworks that are missing from other platforms.

Why there will never be SwiftUI for non-Apple devices

I know that SwiftUi is the future, but we are not there yet.
The fact that remarkable John Harper is working on SwiftUI gives me enormous confidence that it will be able to unite UIKit and AppKit. There is so much more work to be done in that area. John Harper is, among other things, the creator of Core Animation framework. Core Animation drives every UIView, and from not so long ago, every NSView as well. So, it is crucial to SwiftUI as well.

If you want to learn more about SwiftUI animations, there is a great resource from SwiftUILab. And his series of articles like Advanced SwiftUI Animations


As you can see in the image, Shape resolves to CAShapeLayer, for both macOS and iOS.

If we take a look at SwiftUI reflection dump, we can see Core Animation CALayers.

Furthermore, It is evident that all drawing is done with Core Graphics, for all platforms.

Core Graphics and Core Animation are platform-independent for all Apple devices, and all Apple UI frameworks use them as building blocks: AppKit, UIKit and SwiftUI respectively.

For example, you can write platform-independent code using only Core Graphics like this grid drawing code: Draw grid

import Foundation
import CoreGraphics

public struct DrawGrid {
  public func draw(_ context: CGContext, rectToFill: CGRect, options : GridProperties.Options, lineSize: GridProperties.LineSize) {
    
    let squareSide = lineSize.sideWidth
    let lineWidth = lineSize.lineWidth
    let bounds = rectToFill
    
    let colorSpace = CGColorSpaceCreateDeviceRGB()
    
    let whiteColor = CGColor(colorSpace: colorSpace, components: [1, 1, 1, 1])!
    context.setFillColor(whiteColor)
    context.fill(bounds)
    
    let color = CGColor(colorSpace: colorSpace, components: [0, 0, 0, 0.2])!
    context.setStrokeColor(color)
    context.setLineWidth(lineWidth)
    
    // Stroke the border
    context.stroke(bounds)

    for x in 1..<Int(bounds.height / squareSide) {
      // Vertical line
      context.move(to: CGPoint(x: CGFloat(x) * squareSide, y: 0))
      context.addLine(to: CGPoint(x: CGFloat(x) * squareSide, y: bounds.height))

      for y in 1..<Int(bounds.width / squareSide) {
        // Horizontal line
        context.move(to: CGPoint(x: 0, y: CGFloat(y) * squareSide))
        context.addLine(to: CGPoint(x: bounds.width, y: CGFloat(y) * squareSide))
      }
    }
...

The same is true for Core Animation where CALayer is not typecast to UILayer or NSLayer, but remains a CALayer

Some other frameworks used for Apple UI implementation are: Core Text for all text renderings, Core Image for image filters, Core Foundation .

With SwiftUI Apple is reshuffling its building blocks to make developing for Apple devices easier and less error-prone. But without those frameworks, SwiftUI DSL is useless.
So, any attempt to “port SwiftUI” to other platforms is impossible.

One would have to first make a PDF 2D graphics framework like Core Graphics, which is a huge endeavor by itself.

Then, one would have to make Core Animation, a compositing and animation framework. As its author, John Harper said in a 2009 WWDC session, it has been modelled after Photoshop, After Effects, and Motion.

As if that is not enough, one would also have to make all the other frameworks as well.
Neither Windows, nor Linux have a resolution-independent 2D PDF engine for 2D graphics. They also have nothing even resembling Core Animation to offload the UI drawing to the GPU, and to animate it.
Without those building blocks SwiftUI DSL is useless on those platforms.

Android I need not comment, since it doesn’t even have rotation of the views (activities) implemented, or GPU acceleration for the UI.