为了推广Swift编程,苹果在iPad和macOS上发布了Swift Playgrounds 应用程序。今天我来体验一下,写个简单的demo
在开发过程中,可以配合使用Playground,尤其是开发函数时,Playground能更直观的看到函数的值,加快我们开发的速度。
在Xcode中可以直接创建Playground

import UIKit
import SwiftUI
var greeting = "Hello, playground"
import PlaygroundSupport
func test() -> Int{
let a = 1
let b = 3
return a + b
}
test()
struct ContentView: View {
@State var msg: Int = 0
var body: some View {
Text("helloWorld").foregroundColor(.blue)
}
}
PlaygroundPage.current.setLiveView(ContentView())
点击运行,在右侧可以直观的看到变量的值,和View的预览。
