Skip to content

Instantly share code, notes, and snippets.

View alfredoxyanez's full-sized avatar

Alfredo Yanez alfredoxyanez

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