Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A demo implementation of SwiftUI for the Web

License

NotificationsYou must be signed in to change notification settings

SwiftWebUI/SwiftWebUI

Repository files navigation

Swift5.1macOStuxOSTravis

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.

SwiftWebUI

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.

Requirements

On a Mac macOS 10.15 or later is required.

tuxOS

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.

SwiftWebUI Hello World

To setup a SwiftWebUI project,create a "macOS tool project" in Xcode 11,then use the new SwiftPM integration and addhttps://github.com/SwiftWebUI/SwiftWebUIas 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/:

🥑🍞 AvocadoToast

A small SwiftWebUI sample based on theSwiftUI Essentials"Avocado Toast App".Find it over here:AvocadoToast.

Who

Brought to you byHelge Heß /ZeeZide.We like feedback, GitHub stars, cool contract work,presumably any form of praise you can think of.


[8]ページ先頭

©2009-2025 Movatter.jp