Post

Replies

Boosts

Views

Activity

Reply to ForEach won't show text
I apologize I am new at this. The getNFLTeams func is in my ContentModel. In the print console I get the results from the struct NFL and TeamResultNFL but I am not able to show the results in the view it just shows an empty list. class ContentModel: ObservableObject {     @Published var nfl = [NFL]()     @Published var nflResult = [TeamResultNFL]()     init() {          getNFLTeams()     }         func getNFLTeams() {             let headers = ["x-rapidapi-host": "sportspage-feeds.p.rapidapi.com", "x-rapidapi-key": " ]             let urlString = "https://sportspage-feeds.p.rapidapi.com/teams?league=NFL"             let url = URL(string: urlString)             if url != nil {                 var request = URLRequest(url: url!, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 10.0)                 request.httpMethod = "GET"                 request.allHTTPHeaderFields = headers                 let session = URLSession.shared                 let dataTask = session.dataTask(with: request) { data, response, error in                     if error == nil {                         do {                             let decoder = JSONDecoder()                             let result = try decoder.decode(NFL.self, from: data!)                             print(result)                         }                         catch {                             print(error)                         }                     }                 }                 dataTask.resume()             }         } struct NFL: Decodable, Identifiable {     var id: String?     var status: Int?     var time: String?     var teams: Int?     var results: [TeamResultNFL]? } struct TeamResultNFL: Decodable, Identifiable, Hashable {     var id: String?     var team: String?     var mascot: String?     var location: String?     var conference: String?     var division: String?     var league: String?     var abbreviation: String? } struct LaunchView: View {     var result: [TeamResultNFL]     @EnvironmentObject var model: ContentModel     var body: some View { List {             ScrollView {                     ForEach(result) { game in                         Text(game.team ?? "")                 }              }         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         LaunchView(result: [TeamResultNFL(id: "", team: "", mascot: "", location: "", conference: "", division: "", league: "", abbreviation: "")])             .environmentObject(ContentModel())     } } import SwiftUI @main struct SportsBetsApp: App {     var body: some Scene {         WindowGroup {             LaunchView(result: [TeamResultNFL]())                 .environmentObject(ContentModel())             }         }     } Here is all the code again I apologize and thank you for any input @Claude31
Feb ’22