35
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SwiftUIをMojaveのPlaygroundで実行する

Last updated at Posted at 2019-06-06

概要

WWDC2019で発表されたSiwftUIをmacOS MojaveのPlaygroundで実行する方法の簡単なTipsです。

Xcode 11 Betaは以下URLからインストールしてください。
https://developer.apple.com/download/

コード例

以下のように、SwiftUIとPlaygroundSupportをimportし、PlaygroundPage.current.liveViewにUIHostingControllerをセットしてあげることでプレビューが可能となります。

import SwiftUI
import PlaygroundSupport

struct ContentView: View {
    var body: some View {
        VStack {
            Text("SwiftUI")
                .font(.title)
            Text("in Swift Playground")
                .font(.caption)
        }
    }
}

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

Tipsは以上です。以下のURLにSwigyUIの公式チュートリアルがあるので色々試してみると面白いかと思います。

Tutorials: https://developer.apple.com/tutorials/swiftui/

Documentation: https://developer.apple.com/documentation/swiftui/

35
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?