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

262
Visualizações
swift Parameter is implicitly non-escaping

enter image description here

func test(f: () -> ()) {
    let a = f
    let b: () -> () = f // error
    
    a()
    b()
}

The only difference between a and b is whether the type is specified or not.

But what is the reason for the error to be printed only in b?

Please explain the clear difference between a and b.

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

0

The error is shown because 'b' and 'f' do have different signatures.

'b' is an escaping closure 'f' is not.

when doing:

let a = f

you are copying 'f'. The signature stays the same "nonescaping () -> ()".

Declaring a closure in function definition gives you implicit 'nonescaping' in body gives you implicit 'escaping'.

Decorating your closure in the header with @escaping will solve the problem.

func test(f: @escaping () -> ()) {

If you want to know more: https://medium.com/swiftcommmunity/what-do-mean-escaping-and-nonescaping-closures-in-swift-d404d721f39d

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