- Notifications
You must be signed in to change notification settings - Fork162
A demo implementation of SwiftUI for the Web
License
SwiftWebUI/SwiftWebUI
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
More details can be found on the related blog post at theAlways Right Institute.
AtWWDC 2019Apple announcedSwiftUI.A single "cross platform", "declarative" framework used to buildtvOS, macOS, watchOS and iOSUIs.SwiftWebUIis bringing that to the Web ✔️
Disclaimer: This is a toy project!Do not use for production.Use it to learn more about SwiftUI and its inner workings.
So what exactly isSwiftWebUI?It allows you to write SwiftUIViewswhich display in a web browser:
import SwiftWebUIstructMainPage:View{@Statevarcounter=0func countUp(){ counter+=1}varbody:someView{VStack{Text("🥑🍞 #\(counter)").padding(.all).background(.green, cornerRadius:12).foregroundColor(.white).onTapGesture(self.countUp)}}}
Results in:
Unlike some other efforts this doesn't just render SwiftUI Viewsas HTML.It also sets up a connection between the browser and the code hostedin the Swift server, allowing for interaction -buttons, pickers, steppers, lists, navigation, you get it all!
In other words:SwiftWebUIis an implementation of (many but not all parts of) the SwiftUI API for the browser.
To repeat theDisclaimer: This is a toy project!Do not use for production.Use it to learn more about SwiftUI and its inner workings.
On a Mac macOS 10.15 or later is required.
SwiftWebUI now runs on Linux usingOpenCombine (also works withoutthat, but then some things don't work, e.g.NavigationView
).
Swift 5.2 or later is required.We also provide a Docker image containing a 5.1 snapshot over here:helje5/swift.
To setup a SwiftWebUI project,create a "macOS tool project" in Xcode 11,then use the new SwiftPM integration and addhttps://github.com/SwiftWebUI/SwiftWebUI
as a dependency.
Open themain.swift
file and replace it's contentwith:
import SwiftWebUISwiftWebUI.serve(Text("Holy Cow!"))
Compile and run the app in Xcode, open Safari and hithttp://localhost:1337/
:
A small SwiftWebUI sample based on theSwiftUI Essentials"Avocado Toast App".Find it over here:AvocadoToast.
Brought to you byHelge Heß /ZeeZide.We like feedback, GitHub stars, cool contract work,presumably any form of praise you can think of.
About
A demo implementation of SwiftUI for the Web
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.