Created
October 10, 2019 14:58
-
-
Save azamsharp/7434f6e6db2ae8eeffdcae990a551e4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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