let username: String let handle: String let time: Date let content: String let avatar: String let retweets: Int let likes: Int let comments: Int let views: Int let image: String? } struct SNSView: View { let posts = [ Post( username: "John Doe", handle: "@johndoe", time: Date(), content: "μϯλϯͷ৽͍͠ΧϑΣͰ࠷ߴͷίʔώʔΛҿΈ·ͨ͠ʂ", avatar: "person.circle", retweets: 12, likes: 34, comments: 5, views: 120, image: nil ), Post( username: "Jane Smith", handle: "@janesmith", time: Date().addingTimeInterval(-3600), content: "࠷৽ͷιϑτΣΞΞοϓσʔτͷ৽ػೳ͕େ͖Ͱ͢ʂ", avatar: "person.circle.fill", retweets: 20, likes: 55, comments: 8, views: 200, image: nil ), Post( username: "Alice Johnson", handle: "@alicej", time: Date().addingTimeInterval(-7200), content: "ࠓͷϏʔνͰͷඒ͍͠༦ɻ", avatar: "person", retweets: 18, likes: 45, comments: 3, views: 180, image: "sun.max" ), Post( username: "Bob Brown", handle: "@bobb", time: Date().addingTimeInterval(-86400), content: "ࠓேͷૉΒ͍͠ϫʔΫΞτηογϣϯɻ", avatar: "person.crop.circle", retweets: 10, likes: 30, comments: 2, views: 150, image: "figure.walk" ), Post( username: "Charlie Davis", handle: "@charlied", time: Date().addingTimeInterval(-172800), content: "ྺ࢙ʹؔ͢Δڵຯਂ͍ຊΛಡΜͰ͍·͢ɻ", avatar: "person.crop.circle.fill", retweets: 25, likes: 60, comments: 10, views: 220, image: nil ), Post( username: "Dana Lee", handle: "@danalee", time: Date().addingTimeInterval(-259200), content: "ࠓ͓͍͍͠ΫοΩʔΛম͖·ͨ͠ɻ", avatar: "person.circle", retweets: 15, likes: 50, comments: 6, views: 170, image: nil ), Post( username: "Evan Green", handle: "@evangreen", time: Date().addingTimeInterval(-345600), content: "ࢁͰϋΠΩϯάʹߦ͖·ͨ͠ɻͱͯϦϑϨογϡ͠·ͨ͠ʂ", avatar: "person.circle.fill", retweets: 22, likes: 58, comments: 9, views: 210, image: nil ), Post( username: "Fiona White", handle: "@fionawhite", time: Date().addingTimeInterval(-432000), content: "৽͍͠ςϨϏγϦʔζΛݟ͍ͯ·͢ɻຊʹ໘ന͍Ͱ͢ʂ", avatar: "person", retweets: 30, likes: 75, comments: 12, views: 240, image: nil ), Post( username: "George King", handle: "@georgek", time: Date().addingTimeInterval(-518400), content: "ࠓͷσΟφʔͷͨΊʹ৽͍͠ϨγϐΛࢼ͍ͯ͠·͢ɻ", avatar: "person.crop.circle", retweets: 14, likes: 40, comments: 4, views: 160, image: nil ), Post( username: "Hannah Scott", handle: "@hannahs", time: Date().addingTimeInterval(-604800), content: "ࠓതؗΛ๚Ε·ͨ͠ɻͨ͘͞Μͷັྗతͳల͕ࣔ͋Γ·ͨ͠ɻ", avatar: "person.crop.circle.fill", retweets: 28, likes: 70, comments: 11, views: 230, image: "building.columns" ) ] var body: some View { NavigationView { ScrollView { VStack(spacing: 0) { ForEach(posts) { post in HStack(alignment: .top) { Image(systemName: post.avatar) .resizable() .frame(width: 50, height: 50) .clipShape(Circle()) VStack(alignment: .leading) { HStack { Text(post.username) .font(.headline) Text(post.handle) .font(.subheadline) .foregroundColor(.gray) Spacer() Text(formatDate(post.time)) .font(.subheadline) .foregroundColor(.gray) } Text(post.content) .font(.body) if let imageName = post.image { Image(systemName: imageName) .resizable() .aspectRatio(contentMode: .fit) .frame(maxWidth: .infinity) .padding(.horizontal) } HStack { Button { } label: { HStack { Image(systemName: "message") Text("\(post.comments)") } } Spacer() Button { } label: { HStack { Image(systemName: "arrow.2.squarepath") Text("\(post.retweets)") } } Spacer() Button { } label: { HStack { Image(systemName: "heart") Text("\(post.likes)") } } Spacer() HStack { Image(systemName: "eye") Text("\(post.views)") } } .foregroundColor(.gray) .padding([.horizontal, .bottom], 10) } } .padding([.horizontal, .top], 10) Divider() } } } .navigationBarTitle("ϗʔϜ", displayMode: .inline) .overlay { HStack { Spacer() VStack { Spacer() Button { } label: { Image(systemName: "plus") .resizable() .frame(width: 24, height: 24) .padding() .background(Color.blue) .foregroundColor(.white) .clipShape(Circle()) .shadow(radius: 10) } .padding() } } } } } func formatDate(_ date: Date) -> String { let formatter = RelativeDateTimeFormatter() formatter.unitsStyle = .short return formatter.localizedString(for: date, relativeTo: Date()) } } #Preview { SNSView() } શ෦ग़͢ͱ͜Μͳײ͡ ͜ΕΛෳͷ7JFXϑΝΠϧʹׂͯ͠Β͏