TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Type of expression is ambiguous without more context on a scrollview

Forums > SwiftUI

I'm getting a "Type of expression is ambiguous without more context" on the line ScrollView is being initialized. I've tried following https://stackoverflow.com/questions/40894582/type-of-expression-is-ambiguous-without-more-context-swift but the solution/reason the error is coming up is not clear.

        ScrollView(.horizontal, showsIndicators: false) {
            HStack(alignment: .center, spacing: 10) {

                ForEach(0..<(devicesAndManagers?.count ?? 1), id: \.self ) { device in

                    SpeakerCardView(didPressSoundButton: {
    //                    homePath.append(HomeViewOptions.soundPreset)
                        withAnimation {
                            sheetManager.present(with: .init(systemName: "info",
                                                             title: "something",
                                                             content: "content",
                                                             type: .soundProfileList))
                        }
                    },
                                    didPressSpeaker: {

                        homePath.append(HomeViewOptions.soundSettings)

                    },
                    deviceAndManager: devicesAndManagers[device-1])
                    .frame(minWidth: 325 )
                }

                AddSpeakerCardView(didPressSoundButton: {
                    print("Go to new speaker detection")
                })
                .frame(minWidth: 325 )
            }
        }

when i remove the line ", deviceAndManager" from the initializer for the speaker card view then the error goes away. That is good and all, but i need to use the deviceAndManager object for that view (the SpeakerCardView).

2      

Hi! What type of data you have in devicesAndManagers? If this is array of some type you can just try to put it not as range but like so:

ForEach(devicesAndManagers, id: \.self ) { device in
...
}

2      

it's an array of typealiases of two custom objects

typealias DeviceAndManager = (device: BTDevice, manager: DeviceManager)

and

    @State var devicesAndManagers: [DeviceAndManager] = [DeviceAndManager]()

and when i try using your suggestion i get "Type 'DeviceAndManager' (aka '(device: BTDevice, manager: any DeviceManager)') cannot conform to 'Hashable'"

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.