OpenSwiftUI is an OpenSource implementation of Apple's SwiftUI DSL (Domain-specific language.
The project's goal is to stay close to the original API as possible.
The actual rendering of UI elements can then be implemented by other projects for different platforms like Linux, Windows, Embedded, etc.
SwiftUI was introduced by Apple at WWDC 19. Since then, developing applications with graphical user interfaces became easier to read, write and maintain. Unfortunately, the principle "Learn once, apply anywhere" works on Apple platforms, only.
Swift runs on Apple platforms, the web, Linux, Windows and even on embedded devices.
Wouldn't it be great if you could write GUI based applications with SwiftUI on platforms that run Swift?
Xcode 11.2 or higher is required.
It might not be the easiest thing to figure out how SwiftUI works internally but over time and collective guesswork, it can be done.
A good start is to get familar with the SwiftUI interface (see below). This will give you an idea of everything that is available to the user.
Another way is to use reflection (
Mirror(reflecting: …)) to peek into SwiftUI types and instances.
Good to know
Methods and properties of SwiftUI that are marked as private, should be prefixed by an
_ (underscore) and marked as public in OpenSwiftUI.
This is neccessary because another project of a GUI implementation might need access.
Compared to what you can see in Xcode, the file below shows you more than just the public interfaces.
Private properties and even the body of properties, functions and initializers that are marked as
@inlinable is visible in plain text.
SwiftWebUI is an implementation of SwiftUI for the web by Helge Heß.
This project's goal is focused exclusivly on the web.
It deviates a little bit from SwiftUI by taking some shortcuts here and there -- but looks quite complete in functionality and is great for inspiration.
This command prints the symbol table of SwiftUI via the
nm -gUj /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftUI.framework/SwiftUI | swift-demangle | sed 's/SwiftUI.//g' | sed 's/Swift.//g'
You can also have a look at this gist instead.
Subscribe to iOS Example
Get the latest posts delivered right to your inbox