Skip to content

Instantly share code, notes, and snippets.

@DDavis1025
Created March 26, 2020 17:53
Show Gist options
  • Save DDavis1025/a78a71e856ce0f50307b0d19dc34505b to your computer and use it in GitHub Desktop.
Save DDavis1025/a78a71e856ce0f50307b0d19dc34505b to your computer and use it in GitHub Desktop.
import SwiftUI
struct Album: View {
var post:Post
var post2:[PostById]
var body: some View {
VStack {
Text("Title: ").bold()
+ Text("\(post.title)")
ImageView(withURL: "http://localhost:8000/\(post.path.replacingOccurrences(of: " ", with: "%20"))")
Text("Description: ").bold()
+ Text("\(post.description)")
List{
ForEach(self.post2.filter { i in i.album_id == post.id }){ post in
Text("\(post.name ?? "title")")
}
}
}
}
}
import SwiftUI
import ASCollectionView
struct ContentView: View {
@ObservedObject var model = PostListViewModel()
@ObservedObject var model2 = PostListViewByIdModel()
var body: some View {
NavigationView {
List(model.posts) { post in
VStack{
Text("Title: ").bold()
+ Text("\(post.title)")
NavigationLink(destination: Album(post: post, post2: self.model2.postsById)) {
ImageView(withURL: "http://localhost:8000/\(post.path.replacingOccurrences(of: " ", with: "%20"))")
}
Text("Description: ").bold()
+ Text("\(post.description)")
}
}
}
.onReceive(model.$posts) { posts in // << first got finished
self.model2.fetchPostsById(for: posts)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment