No exact matches in call to initializer SwiftUI

Viewed 3382

I have the following code. I added new items to my json file but for some reason I can't display team.Pos even though I added all the models etc. The original data works but not the newly added ones. Any idea why? Additionally I am also trying to display array data as well. But again it also has the same error

import SwiftUI
struct TeamRow: View {
    var team: Team
    var body: some View {
        HStack {
            Image(team.iconName)
            Text(team.code)
            Text(team.Pos) // the error happens here
            Text(clubRanking[10]) // the same error happens
            Spacer()
            
        }
    }
}

struct TeamRow_Previews: PreviewProvider {
    static var previews: some View {
        TeamRow(team: teamData[0])
            .previewLayout(.fixed(width: 350, height: 70))
    }
}

Here is the data model

import SwiftUI
import CoreLocation

struct Team: Hashable, Codable, Identifiable {
    var id: Int
    var name: String
    var nickname: String
    var iconName: String
    var imageName: String
    var stadiumName: String
    var capacity: String
    var city: String
    var website: String
    var code: String
    var Pos: Int
    var PL: Int
    var W: Int
    var D: Int
    var L: Int
    var GD: Int
    var Pts: Int
    
}

And here is the json file

[
    {
        "id":1,
        "name": "Tottenham Hotspur",
        "nickname": "Spurs",
        "iconName": "Spurs",
        "imageName": "Tottenham-Stadium",
        "stadiumName": "Tottenham Hotspur Stadium",
        "capacity": "62303",
        "city": "London",
        "website": "https://www.tottenhamhotspur.com",
        "code":"TOT",
        "Pos":1,
        "PL":0,
        "W":0,
        "D":0,
        "L":0,
        "GD":0,
        "Pts":0
    },
    {
        "id": 2,
        "name": "Liverpool F.C.",
        "nickname": "Liverpool",
        "iconName": "Liverpool",
        "imageName": "Liverpool-Stadium",
        "stadiumName": "Anfield Stadium",
        "capacity": "53394",
        "city": "Liverpool",
        "website": "https://www.liverpoolfc.com",
        "code":"LIV",
        "Pos":1,
        "PL":0,
        "W":0,
        "D":0,
        "L":0,
        "GD":0,
        "Pts":0
    },
]
1 Answers

Try as follows:

Text("\(team.Pos)") // this should work
Text("\(clubRanking[10])") // not clear what is clubRanking, but probably the same
Related