2
respostas

Não consigo adicionar o viagens na List

Ao tentar referenciar a variável viagens a List recebo o erro de Cannot find viagens in scope

List(viagens) { viagem in Text(viagem.titulo) }

Trecho do código com erro apresentado

2 respostas

Oi Rodrigo tudo bem?

Isso é porque você não definiu a variável viagens nesse arquivo.

Me manda seu código como está que posso te auxiliar melhor =) Abraços.

Olá Giovanna, tudo bem? No vídeo ele acessa o array do arquivo de Dados da pasta Model. Segue o meu código.` // // ContentView.swift // alura-viagens-swiftui // // Created by Rodrigo Cerqueira Reis on 17/08/22. //

import SwiftUI

struct ContentView: View { var body: some View {

    GeometryReader { view in

        // MARK: - VSatck Principal

        VStack {

            //MARK: - VStack Header

            VStack{
            Text("alura viagens")
                .foregroundColor(Color.white)
                .font(.custom("Avenir Black", size: 20))
                .padding(.top, 50)
            Text("ESPECIAL")
                .foregroundColor(Color.white)
                .font(.custom("Avenir Book", size: 20))
                .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
                .padding(.leading, 30)
            Text("BRASIL")
                .foregroundColor(Color.white)
                .font(.custom("Avenir Black", size: 23))
                .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
                .padding(.leading, 30)

        }
        .frame(width: view.size.width, height: 180, alignment: .top)
        .background(Color.purple)

            HStack {
                Button(action: {}) {
                    Text("Hotéis")
                        .font(.custom("Avenir Medium", size: 17))
                        .foregroundColor(/*@START_MENU_TOKEN@*/.white/*@END_MENU_TOKEN@*/)
                }
                .frame(width: 100, height: 50)
                .overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.blue, lineWidth: 10))
                .background(Color.blue)
                .offset(x: 50)

                Spacer()

                Button(action: {}) {
                    Text("Pacotes")
                        .font(.custom("Avenir Medium", size: 17))
                        .foregroundColor(.white)
                }
                .frame(width: 100, height: 50)
                .overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.orange, lineWidth: 10))
                .background(Color.orange)
                .offset(x: -50)
            }
            .offset(y: -25)

            List(viages) { viagem in
                Text(viagem.titulo)
            }
        }
    }
    .edgesIgnoringSafeArea(.all)
}

}

struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software