Post

Replies

Boosts

Views

Activity

ForEach won't show text
I am trying to show a list of teams in a list with a ForEach loop but the text does not appear. Here is my code: 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]     var body: some View {         List {             ScrollView {                 ForEach(result, id: \.self) { game in                     Text(game.team ?? "HELLO")                 }             }         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         LaunchView(result: [TeamResultNFL]())     } }
4
0
633
Feb ’22
Decoding JSON
Hello I have been trying to decode a JSON file into my swift project but I am receiving this error. Any help would be much appreciated. dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "results", intValue: nil), _JSONKey(stringValue: "Index 2", intValue: 2), CodingKeys(stringValue: "odds", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "total", intValue: nil), CodingKeys(stringValue: "current", intValue: nil), CodingKeys(stringValue: "total", intValue: nil)], debugDescription: "Parsed JSON number <212.5> does not fit in Int.", underlyingError: nil)) Here is my code and the JSON: Help.json struct Games: Decodable {     var status: Int?     var time: String?     var games: Int?     var skip: Int?     var results: [GameResult]? } struct GameResult: Decodable {    var schedule: GameSchedule?     var summary: String?     var deatails: GameDetails?     var status: String?     var teams: TeamInfo?     var lastUpdated: String?     var gameId: Int?     var venue: GameVenue?     var odds: [GameOdds]? } struct GameSchedule: Decodable {          var date: String?     var tbaTime: Bool? } struct GameDetails: Decodable {     var league: String?     var seasonType: String?     var season: Int?     var conferenceGame: Bool?     var divisionGame: Bool? } struct GameVenue: Decodable {     var name: String?     var city: String?     var state: String?     var neutralSite: Bool? } struct GameOdds: Decodable {     var spread: GameSpread?     var moneyLine: GameMoneyLine?     var total: GameTotal?     var openDate: String?     var lastUpdated: String? } struct GameSpread: Decodable {        var open: OpenSpread?     var current: CurrentSpread? } struct OpenSpread: Decodable {     var away: Double?     var home: Double?     var awayOdds: Int?     var homeOdds: Int? } struct CurrentSpread: Decodable {     var away: Double?     var home: Double?     var awayOdds: Int?     var homeOdds: Int? } struct GameMoneyLine: Decodable {     var open: OpenMoney?     var current: CurrentMoney? } struct OpenMoney: Decodable {     var awayOdds: Int?     var homeOdds: Int? } struct CurrentMoney: Decodable {     var awayOdds: Int?     var homeOdds: Int? } struct GameTotal: Decodable {     var open: OpenTotal?     var current: CurrentTotal? } struct OpenTotal: Decodable {          var total: Int?     var overOdds: Int?     var underOdds: Int? } struct CurrentTotal: Decodable {     var total: Int?     var overOdds: Int?     var underOdds: Int? } struct TeamInfo: Decodable {     var away: AwayTeams?     var home: HomeTeams? } struct AwayTeams: Decodable {     var team: String?     var location: String?     var mascot: String?     var abbreviation: String?     var conference: String?     var division: String? } struct HomeTeams: Decodable {     var team: String?     var location: String?     var mascot: String?     var abbreviation: String?     var conference: String?     var division: String? } ``` if error == nil {                     do {                         let decoder = JSONDecoder()                         let result = try decoder.decode(Games.self, from: data!)                         print(result)                     }                     catch {                         print(error)                     }                 }
3
0
999
Jan ’22