Add list for post id's in profile view
This commit is contained in:
parent
ebe9fe45ac
commit
1492df1545
3 changed files with 41 additions and 2 deletions
|
@ -12,6 +12,7 @@
|
||||||
03427F5D2488856C00A0073D /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03427F5C2488856C00A0073D /* ContentView.swift */; };
|
03427F5D2488856C00A0073D /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03427F5C2488856C00A0073D /* ContentView.swift */; };
|
||||||
03427F5F2488856D00A0073D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 03427F5E2488856D00A0073D /* Assets.xcassets */; };
|
03427F5F2488856D00A0073D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 03427F5E2488856D00A0073D /* Assets.xcassets */; };
|
||||||
03427F652488856D00A0073D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 03427F632488856D00A0073D /* LaunchScreen.storyboard */; };
|
03427F652488856D00A0073D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 03427F632488856D00A0073D /* LaunchScreen.storyboard */; };
|
||||||
|
03427F6D248887D200A0073D /* Common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03427F6C248887D200A0073D /* Common.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
@ -22,6 +23,7 @@
|
||||||
03427F5E2488856D00A0073D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
03427F5E2488856D00A0073D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||||
03427F642488856D00A0073D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
03427F642488856D00A0073D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||||
03427F662488856D00A0073D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
03427F662488856D00A0073D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
|
03427F6C248887D200A0073D /* Common.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Common.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
@ -60,6 +62,7 @@
|
||||||
03427F5E2488856D00A0073D /* Assets.xcassets */,
|
03427F5E2488856D00A0073D /* Assets.xcassets */,
|
||||||
03427F632488856D00A0073D /* LaunchScreen.storyboard */,
|
03427F632488856D00A0073D /* LaunchScreen.storyboard */,
|
||||||
03427F662488856D00A0073D /* Info.plist */,
|
03427F662488856D00A0073D /* Info.plist */,
|
||||||
|
03427F6C248887D200A0073D /* Common.swift */,
|
||||||
);
|
);
|
||||||
path = MobileFort;
|
path = MobileFort;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -133,6 +136,7 @@
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
03427F6D248887D200A0073D /* Common.swift in Sources */,
|
||||||
03427F592488856C00A0073D /* AppDelegate.swift in Sources */,
|
03427F592488856C00A0073D /* AppDelegate.swift in Sources */,
|
||||||
03427F5B2488856C00A0073D /* SceneDelegate.swift in Sources */,
|
03427F5B2488856C00A0073D /* SceneDelegate.swift in Sources */,
|
||||||
03427F5D2488856C00A0073D /* ContentView.swift in Sources */,
|
03427F5D2488856C00A0073D /* ContentView.swift in Sources */,
|
||||||
|
|
5
MobileFort/MobileFort/Common.swift
Normal file
5
MobileFort/MobileFort/Common.swift
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct Post: Decodable, Identifiable {
|
||||||
|
let id: Int
|
||||||
|
}
|
|
@ -3,10 +3,34 @@ import SwiftUI
|
||||||
struct ProfileView: View {
|
struct ProfileView: View {
|
||||||
let username: String
|
let username: String
|
||||||
|
|
||||||
|
@State var posts: [Post] = []
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
Text("Hello, world!")
|
List(posts) { post in
|
||||||
}.navigationBarTitle(username + "'s Feed")
|
Text(String(post.id))
|
||||||
|
}
|
||||||
|
}.navigationBarTitle(username + "'s Feed").onAppear {
|
||||||
|
let url = URL(string: "https://www.pillowfort.social/" + self.username + "/json")!
|
||||||
|
|
||||||
|
URLSession.shared.dataTask(with: url) { (data, response, error) in
|
||||||
|
do {
|
||||||
|
if let jsonData = data {
|
||||||
|
struct Posts : Decodable {
|
||||||
|
let posts: [Post]
|
||||||
|
}
|
||||||
|
|
||||||
|
let decodedPosts = try JSONDecoder().decode(Posts.self, from: jsonData)
|
||||||
|
|
||||||
|
DispatchQueue.main.sync {
|
||||||
|
self.posts = decodedPosts.posts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
print("\(error)")
|
||||||
|
}
|
||||||
|
}.resume()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,3 +48,9 @@ struct MainView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct MainView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
MainView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in a new issue