How to make sure data in variable is loaded before using it

前端 未结 2 1093
一个人的身影
一个人的身影 2021-01-28 15:57

So I have an .onRecieve method

.onReceive(model2.$postsById) { postById in
       print(\"MODEL2 \\(self.model2.postsById)\")
    }
2条回答
  •  一个人的身影
    2021-01-28 16:35

    try this:

    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)")
    
    if post2.count > 0 {
                List(self.post2.filter { i in i.album_id == post.id }) { post       in
                    Text("\(post.name ?? "title")")
                    print(post2)
                 }
    }
    

提交回复
热议问题