//
// ContentView.swift
// ClosureExample
//
// Created by Jeff Jeong on 2022/07/09.
//
import SwiftUI
struct CardView<Content: View>: View {
// 👇🏻 We can't add @ViewBuilder in stored properties before Swift 5.4
let content: Content
init(@ViewBuilder content: () -> Content) {
self.content = content()
}
var body: some View {
VStack{
Text("하하하 컨테이너임")
content
}
}
}
// Use
struct ContentView: View {
var body: some View {
CardView(content: {
Text("gkgkgkgk")
})
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Created
July 9, 2022 12:20
-
-
Save TuenTuenna/8c15c02777c98fe0934747e601bead87 to your computer and use it in GitHub Desktop.
SwiftUi Generic 뷰 만들기
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment