Skip to content

Instantly share code, notes, and snippets.

@karigrooms
Created February 23, 2021 19:21
Show Gist options
  • Save karigrooms/a73a7b7a834c0e12b8c02657b1388ff8 to your computer and use it in GitHub Desktop.
Save karigrooms/a73a7b7a834c0e12b8c02657b1388ff8 to your computer and use it in GitHub Desktop.
Blog post: SwiftUI with UICollectionView - 6. Update card to accept data
import SwiftUI
protocol CardContent {
var imageName: String { get }
var title: String { get }
var description: String { get }
}
struct Card: View {
typealias Content = CardContent
let content: Content
var body: some View {
VStack(alignment: .leading, spacing: 8) {
Image(content.imageName)
.resizable()
.clipShape(RoundedRectangle(cornerRadius: 4))
Text(content.title)
.font(.headline)
Text(content.description)
.font(.body)
.lineLimit(1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment