Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created October 10, 2019 14:58
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 azamsharp/7434f6e6db2ae8eeffdcae990a551e4a to your computer and use it in GitHub Desktop.
Save azamsharp/7434f6e6db2ae8eeffdcae990a551e4a to your computer and use it in GitHub Desktop.
class PostListViewModel: ObservableObject {
let webservice = Webservice()
@Published var posts = [PostViewModel]()
init() {
self.webservice.fetchPosts { posts in
self.posts = posts.map(PostViewModel.init)
}
}
}
struct PostViewModel {
let id = UUID().uuidString
let post: Post
var title: String {
return self.post.title
}
var body: String {
return self.post.body
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment