SwiftUI implementation

Hello,

Does anybody know how SwiftUI is implemented: which language it's written it, are there any plans to make it opensource, etc?

My guess is it's more or less a wrapper for UIKit, with the classes presumably written in swift and calling UIKit methods. But I couldn't find any info about it. Could someone point me in the right direction?

Many thanks
Marcel Ganczak

1 Like

Apple have been marketing it as a "Swift-native" framework, so it would be reasonable to assume it's written in Swift. It also depends how deep you want to go; unless they reimplemented the entire graphics stack, it would also be reasonable to assume it hits C/Obj-C eventually (e.g. CoreAnimation). I wouldn't expect an official answer though, or open-sourcing (although there have been 3rd-party implementations of UIKit, such as Microsoft's WinObjC bridge)

I've heard that SwiftUI components get hosted in a UIKit view, so to me that would indicate that it isn't a wrapper (OpenGL/Metal/SceneKit etc can also be hosted by special UIKit adapters). Again, I don't expect an official answer to that. It's an implementation detail.

Thanks for your response Karl. I didn't know about the WinObjC implementation, thanks for pointing it out!

It would be great if the swift team could make it open source, it would really help the project I'm working on (swift-to-typescript transpiler) -- would essentially mean we don't have to reimplement the SwiftUI on our side. I wonder what's holding apple back on going open source; since it's (presumably) entirely dependent on UIKit & Swift, they're not really exposing any intellectual property that other companies could take advantage of. Unless it could be possibly used as a wrapper for other UI technologies? I would die to know what's their thinking here :smiley:

Anyone, thanks for the info and well informed guesses Karl :slight_smile:

IP isn't the only variable in a decision whether to make something open source. It's seemingly a fundamental building black of Apple's plans for their platforms going forward so I can understand them wanting to keep control of it as long as possible. It's also likely far from "finished", so even if they are planning on releasing it eventually, it probably wouldn't be for another year or two.

I hope it will be open at some point, but it wouldn't surprise me if it never is. At least not in it's current form. However most/all the features of Swift it's using should available soon, so there's nothing to say someone could make a source-compatable version for linux/windows/web at some point.

Also, hopeful there will soon be DSLs for other languages like TypeScript. Might make your job alot easier :slight_smile:

1 Like

Thanks a lot for your response. Unfortunately it does indeed seem unlikely that Apple make it open source in the near future. As long as they're not sure it benefits them, they'll probably err on the side of caution and keep the full control.

Sorry, could you elaborate on it a little bit? You mean Domain-specific languages that will try to mimic SwiftUI for other languages like TS?:thinking:

It depends on at which level you're doing a cross-piler, but if you're doing it at the source code level (and not using a templating library like Mustache), you could parse a Swift file into Types and have a DSL to transform them into TypeScript source code. Basically giving a programmable interface rather than dealing directly with Strings.

e.g.

constructor {
    parameter(named: "foo", type: .number)

    set("this.foo") {
        equal("foo")
    }
}

Could be converted to

constructor(foo: number) {
    this. foo = foo;
}

I had similar questions after first WWDC videos: "Is it has dependencies more than hosting NSView/UIView. When it will be open-sourced, so that we can write platform specific renderers/hosting views".

If you are curious as to how it's implemented / relation to platform frameworks I would recommend:

  • Take a view snapshot of a relevant SwiftUI view hierarchy, you will get the actual UIViews / NSViews that implement it as well as the SwiftUI Views
  • Look through the memory debugger at the object graphs involved
Terms of Service

Privacy Policy

Cookie Policy