diff --git a/MobileFort/MobileFort/Common.swift b/MobileFort/MobileFort/Common.swift index 678ae59..f6d6086 100644 --- a/MobileFort/MobileFort/Common.swift +++ b/MobileFort/MobileFort/Common.swift @@ -1,5 +1,14 @@ import Foundation +enum PostType: String, Decodable { + case picture +} + struct Post: Decodable, Identifiable { let id: Int + + let title: String? + let content: String + + let postType: PostType } diff --git a/MobileFort/MobileFort/ContentView.swift b/MobileFort/MobileFort/ContentView.swift index cfd742c..3f5b29a 100644 --- a/MobileFort/MobileFort/ContentView.swift +++ b/MobileFort/MobileFort/ContentView.swift @@ -8,7 +8,13 @@ struct ProfileView: View { var body: some View { VStack { List(posts) { post in - Text(String(post.id)) + VStack { + Text(String(post.id)) + + if post.title != nil { + Text(post.title!) + } + } } }.navigationBarTitle(username + "'s Feed").onAppear { let url = URL(string: "https://www.pillowfort.social/" + self.username + "/json")! @@ -20,7 +26,10 @@ struct ProfileView: View { let posts: [Post] } - let decodedPosts = try JSONDecoder().decode(Posts.self, from: jsonData) + let decoder = JSONDecoder() + decoder.keyDecodingStrategy = .convertFromSnakeCase + + let decodedPosts = try decoder.decode(Posts.self, from: jsonData) DispatchQueue.main.sync { self.posts = decodedPosts.posts