No exact matches in call to instance method 'appendInterpolation' issue

getting the error " No exact matches in call to instance method 'appendInterpolation' "

HStack {
                ForEach(ads, id: \.bcity) { adn in
                    Text("Store")
                    Text("\(adn.bcity)")
                    Text("- 3 miles")
                }
            }

getting the error on the second Text. Please help been trying for awhile to fix

Answered by robnotyou in 40692025

Can you show more code? How do you declare ads?

Accepted Answer

Can you show more code? How do you declare ads?

private var ads: [AdInfo] = AdInfo.allAds

the other part to that is :

struct AdInfo: Codable {
    var aid, bname, bcity: String?
    var bstate: Bstate?
    var distance: String?
    var cangap: String?
    var vip: Int?
    var photo: [String: String]?
    var adsTitle, adsMsg, status: String?
    var urgentAdsHTML: [AdInfo]?

    enum CodingKeys: String, CodingKey {
        case aid, bname, bcity, bstate, distance, cangap, vip, photo
        case adsTitle = "ads_title"
        case adsMsg = "ads_msg"
        case status, urgentAdsHTML
    }
    static let allAds: [AdInfo] = Bundle.main.decode(file: "sanantoniotx.json")
    static let sampleAd: AdInfo = allAds[0]
}

That's because bcity is defined as optional

Replace by

                Text("\(adn.bcity!)")

or better

                Text("\(adn.bcity ?? "no city")")

Note: why have all properties as optionals ?

I think your problem is that bcity is an Optional, so you can't use it in that way.

well when i tried both of the codes to test, It crashed xcode..

In same cases you can try using Text(verbatim: "\(<PLACEHOLDER>)"). This creates a text view without trying to localize it and just expects a simple String.

No exact matches in call to instance method 'appendInterpolation' issue
 
 
Q