ios – How to put a custom Binding object in #Preview in SwiftUI?


Xcode gives the error message “Ambiguous use of ‘Preview'” for the following code:

import SwiftUI

struct TileDetailView: View {
    @Binding var tile: Tile  // This is a custom object
    @Binding var isShowingTileDetail: Bool
    
    var body: some View {
        Text("This is a tile.")
    }
}

#Preview {
    let bindingVar = Binding.constant(false)
    let aTile = AMClass(name: "A Tile")
    let bindingTile = Binding<Tile>(
        get: { aTile }
    )
    return TileDetailView(aTile: bindingTile, isShowingClassDetail: bindingVar)
}

Please feel free to point out problems with the above code. Thank you.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img