Skip to content

A Playground for running SwiftUI tutorial code on macOS Mojave

Notifications You must be signed in to change notification settings

carabina/SwiftUI-Tutorial-Playground

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

SwiftUI Playground for macOS Mojave

Apple announced their new SwiftUI Framework at WWDC 2019.

While it requires macOS Catalina beta to be run natively, it can already be used in Swift Playgrounds on the current stable version, macOS Mojave.

This project provides a Playground version of Apple’s Building Lists and Navigation tutorial. Xcode 11 beta is required.

Implementation

A UIHostingController can be used in a Playground Live View like this:

PlaygroundPage.current.liveView = UIHostingController(rootView: PlaygroundRootView())

The given root view must be public, along with its init() and body:

public struct PlaygroundRootView: View {
    public init() {}
    
    public var body: some View {
        LandmarkList()
    }
}

From here on, standard SwiftUI Views can be used to build the interface.

Execution

Press the blue Play button next to the PlaygroundPage.current.liveView line or type ⇧⌘↵ to run the Playground. If, after the initial build, the preview is not responsive, just press the Play button again.

Navigation

Use View > Navigator > Show Project Navigator or ⌘1 to show the Playground’s source files and recources.

About

A Playground for running SwiftUI tutorial code on macOS Mojave

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%