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

112
Visualizações
Cannot assign value of type (aka 'Array<Dictionary<String, Style>>') to (aka 'Dictionary<String, Style>')

This is my code:

override func style(node: Node) throws -> StyleNode {
    guard let objectNode = try super.style(node: node) as? StyleNode
    else {
      throw UEErrors.unrecoverableError(message: "Could not create Node")
    }

    guard let stylesArray = node.stylesMap else {
      throw UEErrors.unrecoverableError(message: "stylesMap is missing")
    }
    objectNode.stylesMap = stylesArray //error : Cannot assign value of type '[[StyleID : Style]]' (aka 'Array<Dictionary<String, Style>>') to type '[StyleID : Style]' (aka 'Dictionary<String, Style>')
    return objectNode
  }

Note: var stylesMap: [[StyleID: Style]]? How do I create a dictionary of stylesArray? (I think Map in javascript is dictionary in swift)

I'm, trying to port javascript code to swift. Below is javascript code:

static style(
    node: Node,
    baseProps: BaseConstructorProperties,
  ): this {
    const stylesArray = assertNonNull(
      Node?.stylesMap,
      'stylesMap is missing',
    );

    return new this({
      ...baseProps,
      stylesMap: new Map(stylesArray),
    });
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want just the first item, as mentioned in the comments, you can replace the following line:

objectNode.stylesMap = stylesArray

with:

guard let first = stylesArray.first else {
  throw UEErrors.unrecoverableError(message: "No items")
}
objectNode.stylesMap = first
about 4 years ago · Juan Pablo Isaza 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