Este es mi código:
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 } Nota: var stylesMap: [[StyleID: Style]]? ¿Cómo creo un diccionario de stylesArray ? (Creo que Map en javascript es un diccionario en Swift)
Estoy tratando de portar el código JavaScript a Swift. A continuación se muestra el código javascript:
static style( node: Node, baseProps: BaseConstructorProperties, ): this { const stylesArray = assertNonNull( Node?.stylesMap, 'stylesMap is missing', ); return new this({ ...baseProps, stylesMap: new Map(stylesArray), }); }Si desea solo el primer elemento, como se menciona en los comentarios, puede reemplazar la siguiente línea:
objectNode.stylesMap = stylesArraycon:
guard let first = stylesArray.first else { throw UEErrors.unrecoverableError(message: "No items") } objectNode.stylesMap = first