Skip to content

Instantly share code, notes, and snippets.

@TuenTuenna
Created July 9, 2022 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TuenTuenna/8c15c02777c98fe0934747e601bead87 to your computer and use it in GitHub Desktop.
Save TuenTuenna/8c15c02777c98fe0934747e601bead87 to your computer and use it in GitHub Desktop.
SwiftUi Generic 뷰 만들기
//
//  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()
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment