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
[ | |
{ | |
"id":0, | |
"name":"Swifty Swift", | |
"lastMessage":"Hey hows it going", | |
"imageName":"dog", | |
"lastMessagedDate":"Today" | |
}, | |
{ | |
"id":1, |
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
import Foundation | |
struct Message: Codable, Hashable, Identifiable { | |
var id: Int | |
var name: String | |
var lastMessage: String | |
var imageName: String | |
var lastMessagedDate: String | |
} |
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
import Foundation | |
class MessagesObject: ObservableObject { | |
@Published var messages: [Message] = [] | |
init() { | |
self.messages = loadJson("MessagesJson.json")! | |
} | |
func loadJson(_ filename: String) -> [Message]? { |
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
import SwiftUI | |
struct ContentView: View { | |
@ObservedObject var messagesObject = MessagesObject() | |
var body: some View { | |
NavigationView { | |
List(messagesObject.messages, id: \.id) { | |
message in | |
Text("\(message.lastMessage)") | |
} |