Skip to content

Instantly share code, notes, and snippets.

import Combine
final class RepoViewModel: ObservableObject {
@Published var isLoading = true
@Published var repos = [Repo]() {
didSet {
didChange.send(self)
}
}
private let didChange = PassthroughSubject<RepoViewModel, Never>()
var body: some View {
NavigationView{
List(reposArray, id: \.name){ model in
RepoCell(repoModel: model)
.shadow(color: .gray, radius: 4, x: 4, y: 4)
.padding(8.0)
}
.navigationBarTitle(Text("🔥HOT REPOS🔥 "))
.onAppear(perform: loadData)
/// removing separators from the list
var body: some View {
// We set all elements in a Vertical Stack
VStack(alignment: .center, spacing: 0.0){
Text(repoModel.name)
.font(.headline)
.foregroundColor(Color.gitHubText) // Custom color
.padding()
Text(repoModel.description)
.font(.subheadline)
.fontWeight(.medium)
import SwiftUI
struct RepoCell: View {
@State var repoModel: Repo
static var imagePlaceHolder = UIImage(named: "image_placeholder")
var body: some View {
Text("New Cell")
}
}
import SwiftUI
struct ContentView: View {
@ObservedObject var repoViewModel = RepoViewModel()
var body: some View {
NavigationView{
if repoViewModel.isLoading {
Loader()