import SwiftUI import KordophoneKit struct MessageView : View { var message: Message var attachmentData: Data? var body: some View { HStack { VStack { attachmentData.map { Image(data: $0) } Text(message.text) } .multilineTextAlignment(.leading) } .padding() .background(Color.blue) .padding() } } struct MessageViewWrapper : View { var message: Message @State private var attachmentData: Data? @EnvironmentObject private var connection: Connection var body: some View { MessageView(message: message, attachmentData: attachmentData) .onChange(of: message) { _ in print(message) if let attachment = message.attachments.first { print(attachment) Task { let data = await connection.data(for: attachment) DispatchQueue.main.async { print(data) self.attachmentData = data } } } } } }