Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

620
Visualizações
Swift : Generic parameter 'T' could not be inferred

I have a protocol called P, and I want to write a function that would return an instance of any type conforming to that protocol.

I wrote this:

func f<T: P>() -> T? {
    // ... 
}

But then when I try to call it:

var fp = f()

I get this error: Generic parameter 'T' could not be inferred. What am I doing wrong and how to solve this? Thanks for your help.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You're very close. Say you have a struct A that conforms to P. Then you could specify the generic parameter as follows:

var fp: A? = f()

Without that information, the compiler can't know what type fp should be.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda